From 5c37430792f43601f7a3c6b57dff567dc6201ff7 Mon Sep 17 00:00:00 2001 From: wiru Date: Wed, 1 May 2024 02:06:58 -0300 Subject: [PATCH] feat: initial naive implementation of syntax highlighting --- Cargo.lock | 246 ++++++++++-------- Cargo.toml | 3 +- colors/Cargo.toml | 1 + colors/src/colors.rs | 152 ++++------- reqtui/Cargo.toml | 3 + reqtui/src/lib.rs | 1 + reqtui/src/net/request_manager.rs | 55 +++- reqtui/src/syntax/highlighter.rs | 60 ++++- reqtui/src/text_object.rs | 4 + reqtui/src/text_object/text_object.rs | 71 +++++ tui/Cargo.toml | 2 +- .../components/api_explorer/api_explorer.rs | 65 ++--- tui/src/components/api_explorer/res_viewer.rs | 26 +- tui/src/components/api_explorer/sidebar.rs | 10 +- tui/src/components/terminal_too_small.rs | 3 +- 15 files changed, 406 insertions(+), 296 deletions(-) create mode 100644 reqtui/src/text_object.rs create mode 100644 reqtui/src/text_object/text_object.rs diff --git a/Cargo.lock b/Cargo.lock index 0406355..c157dda 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -40,15 +40,15 @@ dependencies = [ [[package]] name = "allocator-api2" -version = "0.2.16" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" +checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" [[package]] name = "anyhow" -version = "1.0.81" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247" +checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519" [[package]] name = "autocfg" @@ -73,9 +73,9 @@ dependencies = [ [[package]] name = "base64" -version = "0.22.0" +version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9475866fec1451be56a3c2400fd081ff546538961565ccb5b7142cbd22bc7a51" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" [[package]] name = "bitflags" @@ -118,9 +118,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.92" +version = "1.0.96" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2678b2e3449475e95b0aa6f9b506a28e61b3dc8996592b983695e8ebb58a8b41" +checksum = "065a29261d53ba54260972629f9ca6bffa69bac13cd1fed61420f7fa68b9f8bd" [[package]] name = "cfg-if" @@ -134,6 +134,7 @@ version = "0.1.0" dependencies = [ "anyhow", "crossterm", + "ratatui", "serde", "toml", "tracing", @@ -239,7 +240,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 2.0.58", + "syn", ] [[package]] @@ -250,7 +251,7 @@ checksum = "a668eda54683121533a393014d8692171709ff57a7d61f187b6e782719f8933f" dependencies = [ "darling_core", "quote", - "syn 2.0.58", + "syn", ] [[package]] @@ -280,7 +281,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.58", + "syn", ] [[package]] @@ -290,7 +291,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "206868b8242f27cecce124c19fd88157fbd0dd334df2587f36417bafbc85097b" dependencies = [ "derive_builder_core", - "syn 2.0.58", + "syn", ] [[package]] @@ -316,9 +317,9 @@ dependencies = [ [[package]] name = "either" -version = "1.10.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" +checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2" [[package]] name = "encoding_rs" @@ -347,9 +348,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "2.0.2" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "658bd65b1cf4c852a3cc96f18a8ce7b5640f6b703f905c7d74532294c2a63984" +checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" [[package]] name = "fnv" @@ -443,7 +444,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn", ] [[package]] @@ -514,9 +515,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.14.3" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" dependencies = [ "ahash", "allocator-api2", @@ -700,9 +701,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.153" +version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" [[package]] name = "libredox" @@ -722,9 +723,9 @@ checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" [[package]] name = "lock_api" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ "autocfg", "scopeguard", @@ -875,7 +876,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn", ] [[package]] @@ -910,9 +911,9 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" [[package]] name = "parking_lot" -version = "0.12.1" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" dependencies = [ "lock_api", "parking_lot_core", @@ -920,15 +921,15 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.9" +version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if", "libc", "redox_syscall", "smallvec", - "windows-targets 0.48.5", + "windows-targets 0.52.5", ] [[package]] @@ -960,7 +961,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn", ] [[package]] @@ -989,27 +990,27 @@ checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" [[package]] name = "proc-macro2" -version = "1.0.79" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" +checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.35" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] [[package]] name = "ratatui" -version = "0.26.1" +version = "0.26.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcb12f8fbf6c62614b0d56eb352af54f6a22410c3b079eb53ee93c7b97dd31d8" +checksum = "a564a852040e82671dc50a37d88f3aa83bbc690dfc6844cfe7a2591620206a80" dependencies = [ "bitflags 2.5.0", "cassowary", @@ -1028,11 +1029,11 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.4.1" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.5.0", ] [[package]] @@ -1082,7 +1083,10 @@ dependencies = [ "anyhow", "cc", "config", + "lazy_static", + "ratatui", "reqwest", + "ropey", "serde", "serde_json", "tokio", @@ -1133,6 +1137,16 @@ dependencies = [ "winreg", ] +[[package]] +name = "ropey" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93411e420bcd1a75ddd1dc3caf18c23155eda2c090631a85af21ba19e97093b5" +dependencies = [ + "smallvec", + "str_indices", +] + [[package]] name = "rustc-demangle" version = "0.1.23" @@ -1141,9 +1155,9 @@ checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" [[package]] name = "rustix" -version = "0.38.32" +version = "0.38.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" dependencies = [ "bitflags 2.5.0", "errno", @@ -1164,9 +1178,9 @@ dependencies = [ [[package]] name = "rustls-pki-types" -version = "1.4.1" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecd36cc4259e3e4514335c4a138c6b43171a8d61d8f5c9348f9fc7529416f247" +checksum = "beb461507cee2c2ff151784c52762cf4d9ff6a61f3e80968600ed24fa837fa54" [[package]] name = "rustversion" @@ -1220,29 +1234,29 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.197" +version = "1.0.199" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +checksum = "0c9f6e76df036c77cd94996771fb40db98187f096dd0b9af39c6c6e452ba966a" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.197" +version = "1.0.199" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +checksum = "11bd257a6541e141e42ca6d24ae26f7714887b47e89aa739099104c7e4d3b7fc" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn", ] [[package]] name = "serde_json" -version = "1.0.115" +version = "1.0.116" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12dc5c46daa8e9fdf4f5e71b6cf9a53f2487da0e86e55808e2d35539666497dd" +checksum = "3e17db7126d17feb94eb3fad46bf1a96b034e8aacbc2e775fe81505f8b0b2813" dependencies = [ "itoa", "ryu", @@ -1302,9 +1316,9 @@ dependencies = [ [[package]] name = "signal-hook-registry" -version = "1.4.1" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" dependencies = [ "libc", ] @@ -1326,9 +1340,9 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "socket2" -version = "0.5.6" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05ffd9c0a93b7543e062e759284fcf5f5e3b098501104bfbdde4d404db792871" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" dependencies = [ "libc", "windows-sys 0.52.0", @@ -1336,12 +1350,12 @@ dependencies = [ [[package]] name = "stability" -version = "0.1.1" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebd1b177894da2a2d9120208c3386066af06a488255caabc5de8ddca22dbc3ce" +checksum = "2ff9eaf853dec4c8802325d8b6d3dffa86cc707fd7a1a4cdbf416e13b061787a" dependencies = [ "quote", - "syn 1.0.109", + "syn", ] [[package]] @@ -1350,6 +1364,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "str_indices" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9557cb6521e8d009c51a8666f09356f4b817ba9ba0981a305bd86aee47bd35c" + [[package]] name = "strsim" version = "0.10.0" @@ -1375,25 +1395,14 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.58", -] - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "syn", ] [[package]] name = "syn" -version = "2.0.58" +version = "2.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687" +checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3" dependencies = [ "proc-macro2", "quote", @@ -1441,22 +1450,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.58" +version = "1.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" +checksum = "f0126ad08bff79f29fc3ae6a55cc72352056dfff61e3ff8bb7129476d44b23aa" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.58" +version = "1.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" +checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn", ] [[package]] @@ -1471,9 +1480,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.34" +version = "0.3.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8248b6521bb14bc45b4067159b9b6ad792e2d6d754d6c41fb50e29fefe38749" +checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" dependencies = [ "deranged", "itoa", @@ -1494,9 +1503,9 @@ checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" -version = "0.2.17" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ba3a3ef41e6672a2f0f001392bb5dcd3ff0a9992d618ca761a11c3121547774" +checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" dependencies = [ "num-conv", "time-core", @@ -1544,7 +1553,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn", ] [[package]] @@ -1594,9 +1603,9 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.22.9" +version = "0.22.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e40bb779c5187258fd7aad0eb68cb8706a0a81fa712fbea808ab43c4b8374c4" +checksum = "d3328d4f68a705b2a4498da1d580585d39a6510f98318a2cec3018a7ec61ddef" dependencies = [ "indexmap", "serde", @@ -1665,7 +1674,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn", ] [[package]] @@ -1792,9 +1801,9 @@ checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" [[package]] name = "unicode-width" -version = "0.1.11" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" +checksum = "68f5e5f3158ecfd4b8ff6fe086db7c8467a2dfdac97fe420f2b7c4aa97af66d6" [[package]] name = "url" @@ -1861,7 +1870,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.58", + "syn", "wasm-bindgen-shared", ] @@ -1895,7 +1904,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -1953,7 +1962,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.4", + "windows-targets 0.52.5", ] [[package]] @@ -1973,17 +1982,18 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" dependencies = [ - "windows_aarch64_gnullvm 0.52.4", - "windows_aarch64_msvc 0.52.4", - "windows_i686_gnu 0.52.4", - "windows_i686_msvc 0.52.4", - "windows_x86_64_gnu 0.52.4", - "windows_x86_64_gnullvm 0.52.4", - "windows_x86_64_msvc 0.52.4", + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", ] [[package]] @@ -1994,9 +2004,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" [[package]] name = "windows_aarch64_msvc" @@ -2006,9 +2016,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" [[package]] name = "windows_i686_gnu" @@ -2018,9 +2028,15 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.52.4" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" [[package]] name = "windows_i686_msvc" @@ -2030,9 +2046,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" [[package]] name = "windows_x86_64_gnu" @@ -2042,9 +2058,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" [[package]] name = "windows_x86_64_gnullvm" @@ -2054,9 +2070,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" [[package]] name = "windows_x86_64_msvc" @@ -2066,15 +2082,15 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" [[package]] name = "winnow" -version = "0.6.6" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0c976aaaa0e1f90dbb21e9587cdaf1d9679a1cde8875c0d6bd83ab96a208352" +checksum = "14b9415ee827af173ebb3f15f9083df5a122eb93572ec28741fb153356ea2578" dependencies = [ "memchr", ] @@ -2106,5 +2122,5 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn", ] diff --git a/Cargo.toml b/Cargo.toml index c367642..457d340 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,4 +14,5 @@ tokio = { version = "1.37.0", features = ["full"] } tracing = "0.1.40" serde = { version = "1.0.197", features = ["derive"] } serde_json = "1.0.115" -reqwest = "0.12" +reqwest = { version = "0.12", features = ["json"] } +ratatui = { version = "0.26.1", features = ["all-widgets", "crossterm"] } diff --git a/colors/Cargo.toml b/colors/Cargo.toml index d994d6c..f646407 100644 --- a/colors/Cargo.toml +++ b/colors/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" tracing.workspace = true anyhow.workspace = true crossterm.workspace = true +ratatui.workspace = true serde.workspace = true toml = { version = "0.8.12" } diff --git a/colors/src/colors.rs b/colors/src/colors.rs index ef6f16c..ee25163 100644 --- a/colors/src/colors.rs +++ b/colors/src/colors.rs @@ -1,10 +1,38 @@ -use crossterm::style::Color; +use std::collections::HashMap; -#[derive(Debug, Default, PartialEq)] +use ratatui::style::{Color, Style}; + +#[derive(Debug, PartialEq)] pub struct Colors { pub primary: PrimaryColors, pub normal: NormalColors, pub bright: BrightColors, + pub tokens: HashMap, +} + +impl Default for Colors { + fn default() -> Self { + Colors { + primary: Default::default(), + normal: Default::default(), + bright: Default::default(), + tokens: token_highlight(), + } + } +} + +fn token_highlight() -> HashMap { + let mut tokens = HashMap::new(); + let colors = NormalColors::default(); + + tokens.insert("conceal".into(), Style::new().fg(colors.red)); + tokens.insert("number".into(), Style::new().fg(colors.blue)); + tokens.insert("property".into(), Style::new().fg(colors.green)); + tokens.insert("punctuation.bracket".into(), Style::new().fg(colors.yellow)); + tokens.insert("punctuation.delimiter".into(), Style::new().fg(colors.cyan)); + tokens.insert("string".into(), Style::new().fg(colors.magenta)); + + tokens } #[derive(Debug, PartialEq)] @@ -42,26 +70,10 @@ pub struct BrightColors { impl Default for PrimaryColors { fn default() -> Self { PrimaryColors { - foreground: Color::Rgb { - r: 0xCE, - g: 0xCE, - b: 0xCE, - }, - background: Color::Rgb { - r: 0x0F, - g: 0x14, - b: 0x19, - }, - accent: Color::Rgb { - r: 0x12, - g: 0x21, - b: 0x32, - }, - hover: Color::Rgb { - r: 0x1A, - g: 0x1F, - b: 0x29, - }, + foreground: Color::Rgb(0xCE, 0xCE, 0xCE), + background: Color::Rgb(0x0F, 0x14, 0x19), + accent: Color::Rgb(0x12, 0x21, 0x32), + hover: Color::Rgb(0x1A, 0x1F, 0x29), } } } @@ -69,46 +81,14 @@ impl Default for PrimaryColors { impl Default for NormalColors { fn default() -> Self { NormalColors { - black: Color::Rgb { - r: 0x03, - g: 0x03, - b: 0x03, - }, - red: Color::Rgb { - r: 0xD9, - g: 0x57, - b: 0x57, - }, - green: Color::Rgb { - r: 0xAA, - g: 0xd9, - b: 0x4C, - }, - yellow: Color::Rgb { - r: 0xE6, - g: 0xB4, - b: 0x50, - }, - blue: Color::Rgb { - r: 0x59, - g: 0xBA, - b: 0xE6, - }, - magenta: Color::Rgb { - r: 0x6C, - g: 0x59, - b: 0x80, - }, - cyan: Color::Rgb { - r: 0x95, - g: 0xE6, - b: 0xCB, - }, - white: Color::Rgb { - r: 0xBF, - g: 0xBD, - b: 0xB6, - }, + black: Color::Rgb(0x03, 0x03, 0x03), + red: Color::Rgb(0xD9, 0x57, 0x57), + green: Color::Rgb(0xAA, 0xd9, 0x4C), + yellow: Color::Rgb(0xE6, 0xB4, 0x50), + blue: Color::Rgb(0x59, 0xBA, 0xE6), + magenta: Color::Rgb(0x6C, 0x59, 0x80), + cyan: Color::Rgb(0x95, 0xE6, 0xCB), + white: Color::Rgb(0xBF, 0xBD, 0xB6), } } } @@ -116,46 +96,14 @@ impl Default for NormalColors { impl Default for BrightColors { fn default() -> Self { BrightColors { - black: Color::Rgb { - r: 0x11, - g: 0x15, - b: 0x1C, - }, - red: Color::Rgb { - r: 0xFB, - g: 0x73, - b: 0x73, - }, - green: Color::Rgb { - r: 0x7F, - g: 0xD9, - b: 0x4C, - }, - yellow: Color::Rgb { - r: 0xE6, - g: 0xB6, - b: 0x73, - }, - blue: Color::Rgb { - r: 0x73, - g: 0xB8, - b: 0xFF, - }, - magenta: Color::Rgb { - r: 0xD2, - g: 0xA6, - b: 0xFF, - }, - cyan: Color::Rgb { - r: 0x95, - g: 0xE6, - b: 0xCB, - }, - white: Color::Rgb { - r: 0xFC, - g: 0xFC, - b: 0xFC, - }, + black: Color::Rgb(0x11, 0x15, 0x1C), + red: Color::Rgb(0xFB, 0x73, 0x73), + green: Color::Rgb(0x7F, 0xD9, 0x4C), + yellow: Color::Rgb(0xE6, 0xB6, 0x73), + blue: Color::Rgb(0x73, 0xB8, 0xFF), + magenta: Color::Rgb(0xD2, 0xA6, 0xFF), + cyan: Color::Rgb(0x95, 0xE6, 0xCB), + white: Color::Rgb(0xFC, 0xFC, 0xFC), } } } diff --git a/reqtui/Cargo.toml b/reqtui/Cargo.toml index 1d0ee7b..267c643 100644 --- a/reqtui/Cargo.toml +++ b/reqtui/Cargo.toml @@ -11,9 +11,12 @@ serde.workspace = true tokio.workspace = true reqwest.workspace = true serde_json.workspace = true +ratatui.workspace = true tree-sitter = "0.22.5" tree-sitter-json = "0.21" +ropey = "1.6.1" +lazy_static = "1.4" [build-dependencies] cc="*" diff --git a/reqtui/src/lib.rs b/reqtui/src/lib.rs index ef03694..c868f00 100644 --- a/reqtui/src/lib.rs +++ b/reqtui/src/lib.rs @@ -3,3 +3,4 @@ pub mod fs; pub mod net; pub mod schema; pub mod syntax; +pub mod text_object; diff --git a/reqtui/src/net/request_manager.rs b/reqtui/src/net/request_manager.rs index 9a99148..38543c4 100644 --- a/reqtui/src/net/request_manager.rs +++ b/reqtui/src/net/request_manager.rs @@ -1,32 +1,67 @@ -use serde::Serialize; +use std::collections::HashMap; + +use ratatui::style::Style; use tokio::sync::mpsc::UnboundedSender; -use crate::schema::types::Request; +use crate::{ + schema::types::Request, + syntax::highlighter::HIGHLIGHTER, + text_object::{Readonly, TextObject}, +}; -#[derive(Debug, Serialize, Clone, PartialEq)] +#[derive(Debug, PartialEq)] pub struct ReqtuiResponse { pub body: String, - pub pretty_body: String, + pub pretty_body: TextObject, } -#[derive(Debug, Serialize, PartialEq)] +#[derive(Debug, PartialEq)] pub enum ReqtuiNetRequest { Request(Request), Response(ReqtuiResponse), + Error(String), } #[tracing::instrument(skip(response_tx))] -pub fn handle_request(request: Request, response_tx: UnboundedSender) { +pub fn handle_request( + request: Request, + response_tx: UnboundedSender, + tokens: HashMap, +) { tracing::debug!("starting to handle user request"); tokio::spawn(async move { - match reqwest::get(request.uri).await { + let client = reqwest::Client::new(); + match client.get(request.uri).send().await { Ok(res) => { tracing::debug!("request handled successfully, sending response"); - let body = res.text().await.expect("failed to decode body"); - let pretty_body = serde_json::to_string_pretty(&body).unwrap(); + let body: serde_json::Value = res + .json() + .await + .map_err(|_| { + response_tx.send(ReqtuiNetRequest::Error( + "failed to decode json response".into(), + )) + }) + .expect("failed to send response through channel"); + + let pretty_body = serde_json::to_string_pretty(&body) + .map_err(|_| { + response_tx.send(ReqtuiNetRequest::Error( + "failed to decode json response".into(), + )) + }) + .expect("failed to send response through channel"); + + let mut highlighter = HIGHLIGHTER.write().unwrap(); + let body = body.to_string(); + + let tree = highlighter.parse(&pretty_body); + let highlight = highlighter.apply(&pretty_body, tree.as_ref(), &tokens); + let pretty_body = TextObject::from(&pretty_body).with_highlight(highlight); + response_tx .send(ReqtuiNetRequest::Response(ReqtuiResponse { - body, + body: body.to_string(), pretty_body, })) .expect("failed to send response through channel"); diff --git a/reqtui/src/syntax/highlighter.rs b/reqtui/src/syntax/highlighter.rs index 812d062..786991a 100644 --- a/reqtui/src/syntax/highlighter.rs +++ b/reqtui/src/syntax/highlighter.rs @@ -1,14 +1,30 @@ -use tree_sitter::{Parser, Query, QueryCursor}; +use lazy_static::lazy_static; +use ratatui::style::Style; + +use std::{collections::HashMap, fmt::Debug, sync::RwLock}; + +use tree_sitter::{Parser, Query, QueryCursor, Tree}; + +lazy_static! { + pub static ref HIGHLIGHTER: RwLock = RwLock::new(Highlighter::default()); +} pub struct Highlighter { parser: Parser, query: Query, } -#[derive(Debug)] +impl Debug for Highlighter { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("Highlighter").finish() + } +} + +#[derive(Debug, PartialEq)] pub struct ColorInfo { pub start: usize, pub end: usize, + pub style: Style, } impl Default for Highlighter { @@ -27,20 +43,36 @@ impl Default for Highlighter { } impl Highlighter { - pub fn apply(&mut self, buffer: &str) -> Vec { - let tree = self.parser.parse(buffer, None).unwrap(); + pub fn parse<'a>(&mut self, buffer: &str) -> Option { + self.parser.parse(buffer, None) + } + pub fn apply( + &self, + buffer: &str, + tree: Option<&Tree>, + tokens: &HashMap, + ) -> Vec { let mut colors = Vec::new(); - let mut cursor = QueryCursor::new(); - let matches = cursor.matches(&self.query, tree.root_node(), buffer.as_bytes()); - - for m in matches { - for cap in m.captures { - let node = cap.node; - let start = node.start_byte(); - let end = node.end_byte(); - let _capture_name = self.query.capture_names()[cap.index as usize]; - colors.push(ColorInfo { start, end }); + + if let Some(tree) = tree { + let mut cursor = QueryCursor::new(); + let matches = cursor.matches(&self.query, tree.root_node(), buffer.as_bytes()); + + for m in matches { + for cap in m.captures { + let node = cap.node; + let start = node.start_byte(); + let end = node.end_byte(); + let capture_name = self.query.capture_names()[cap.index as usize]; + if let Some(style) = tokens.get(capture_name) { + colors.push(ColorInfo { + start, + end, + style: *style, + }); + } + } } } diff --git a/reqtui/src/text_object.rs b/reqtui/src/text_object.rs new file mode 100644 index 0000000..abbd5af --- /dev/null +++ b/reqtui/src/text_object.rs @@ -0,0 +1,4 @@ +#[allow(clippy::module_inception)] +mod text_object; + +pub use text_object::{Readonly, TextObject, Write}; diff --git a/reqtui/src/text_object/text_object.rs b/reqtui/src/text_object/text_object.rs new file mode 100644 index 0000000..4146c78 --- /dev/null +++ b/reqtui/src/text_object/text_object.rs @@ -0,0 +1,71 @@ +use ratatui::{ + style::Styled, + text::{Line, Span}, + widgets::Paragraph, +}; +use ropey::{iter::Chars, Rope}; + +use crate::syntax::highlighter::ColorInfo; + +#[derive(Debug, PartialEq)] +pub struct Readonly; +#[derive(Debug, PartialEq)] +pub struct Write; + +#[derive(Debug, PartialEq)] +pub struct TextObject { + content: Rope, + state: std::marker::PhantomData, + pub display: Paragraph<'static>, +} + +impl TextObject { + pub fn from(content: &str) -> TextObject { + TextObject:: { + display: Paragraph::new(content.to_string()), + content: Rope::from_str(content), + state: std::marker::PhantomData::, + } + } + + pub fn with_write(self) -> TextObject { + TextObject:: { + content: self.content, + state: std::marker::PhantomData, + display: self.display, + } + } +} + +impl TextObject { + pub fn chars(&self) -> Chars<'_> { + self.content.chars() + } + + pub fn with_highlight(self, colors: Vec) -> Self { + let mut lines: Vec = vec![]; + let mut current_line: Vec = vec![]; + for (idx, c) in self.chars().enumerate() { + let style = colors + .iter() + .find(|color| color.start <= idx && color.end >= idx) + .map(|c| c.style) + .unwrap_or_default(); + + current_line.push(c.to_string().set_style(style)); + + if c.eq(&'\n') { + lines.push(current_line.clone().into()); + current_line.clear(); + } + } + + let display = Paragraph::new(lines); + + Self { + content: self.content, + state: std::marker::PhantomData, + display, + } + } +} diff --git a/tui/Cargo.toml b/tui/Cargo.toml index c282ad3..529075a 100644 --- a/tui/Cargo.toml +++ b/tui/Cargo.toml @@ -14,9 +14,9 @@ tokio.workspace = true tracing.workspace = true reqwest.workspace = true serde_json.workspace = true +ratatui.workspace = true futures = "0.3.30" -ratatui = { version = "0.26.1", features = ["all-widgets", "crossterm"] } tui-big-text = { version = "0.4.3" } tracing-subscriber = { version = "0.3.18" } tracing-appender = "0.2.3" diff --git a/tui/src/components/api_explorer/api_explorer.rs b/tui/src/components/api_explorer/api_explorer.rs index f6390a6..4a9d8c2 100644 --- a/tui/src/components/api_explorer/api_explorer.rs +++ b/tui/src/components/api_explorer/api_explorer.rs @@ -7,12 +7,6 @@ use crate::components::{ }, Component, }; -use reqtui::{ - command::Command, - net::request_manager::{ReqtuiNetRequest, ReqtuiResponse}, - schema::types::{Request, RequestKind, Schema}, -}; - use anyhow::Context; use crossterm::event::{KeyCode, KeyEvent}; use ratatui::{ @@ -21,6 +15,11 @@ use ratatui::{ widgets::{Block, Clear, StatefulWidget}, Frame, }; +use reqtui::{ + command::Command, + net::request_manager::{ReqtuiNetRequest, ReqtuiResponse}, + schema::types::{Directory, Request, RequestKind, Schema}, +}; use std::{collections::HashMap, ops::Add}; use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender}; @@ -47,23 +46,20 @@ enum PaneFocus { #[derive(Debug)] pub struct ApiExplorer<'a> { - layout: ExplorerLayout, schema: Schema, - + colors: &'a colors::Colors, + layout: ExplorerLayout, + response_rx: UnboundedReceiver, + request_tx: UnboundedSender, + selected_request: Option, + hovered_request: Option, + dirs_expanded: HashMap, focused_pane: PaneFocus, selected_pane: Option, + preview_tab: ResViewerTabs, raw_preview_scroll: usize, - selected_request: Option, - hovered_request: Option, - - dirs_expanded: HashMap, - colors: &'a colors::Colors, - - response_rx: UnboundedReceiver, - request_tx: UnboundedSender, - responses_map: HashMap, } @@ -114,8 +110,8 @@ impl<'a> ApiExplorer<'a> { KeyCode::Enter => { if let Some(ref req) = self.hovered_request { match req { - RequestKind::Nested(_) => { - let entry = self.dirs_expanded.entry(req.clone()).or_insert(false); + RequestKind::Nested(dir) => { + let entry = self.dirs_expanded.entry(dir.clone()).or_insert(false); *entry = !*entry; } RequestKind::Single(req) => { @@ -160,6 +156,7 @@ impl<'a> ApiExplorer<'a> { reqtui::net::handle_request( self.selected_request.as_ref().unwrap().clone(), self.request_tx.clone(), + self.colors.tokens.clone(), ); Ok(None) } @@ -204,8 +201,8 @@ impl<'a> ApiExplorer<'a> { .as_ref() .map(|sel| sel.eq(&PaneFocus::Preview)) .unwrap_or(false), - current_response.cloned(), - self.preview_tab.clone(), + current_response, + &self.preview_tab, &mut self.raw_preview_scroll, ); @@ -316,7 +313,7 @@ pub fn build_layout(size: Rect) -> ExplorerLayout { fn traverse( found: &mut bool, visit: &VisitNode, - dirs_expanded: &HashMap, + dirs_expanded: &HashMap, current: &RequestKind, needle: &RequestKind, path: &mut Vec, @@ -347,7 +344,7 @@ fn traverse( if let RequestKind::Nested(dir) = current { // if we are on a collapsed directory we should not recurse into its children - if !dirs_expanded.get(current).unwrap() { + if !dirs_expanded.get(dir).unwrap() { return false; } @@ -365,7 +362,7 @@ fn traverse( fn find_next_entry( tree: &[RequestKind], visit: VisitNode, - dirs_expanded: &HashMap, + dirs_expanded: &HashMap, needle: &RequestKind, ) -> Option { let mut found = false; @@ -418,11 +415,15 @@ mod tests { }) } - fn create_nested() -> RequestKind { - RequestKind::Nested(Directory { + fn create_dir() -> Directory { + Directory { name: "Nested1".to_string(), requests: vec![create_child_one(), create_child_two()], - }) + } + } + + fn create_nested() -> RequestKind { + RequestKind::Nested(create_dir()) } fn create_root_two() -> RequestKind { @@ -441,7 +442,7 @@ mod tests { fn test_visit_next_no_expanded() { let tree = create_test_tree(); let mut dirs_expanded = HashMap::new(); - dirs_expanded.insert(create_nested(), false); + dirs_expanded.insert(create_dir(), false); let needle = create_nested(); let expected = Some(create_root_two()); @@ -455,7 +456,7 @@ mod tests { fn test_visit_node_nested_next() { let tree = create_test_tree(); let mut dirs_expanded = HashMap::new(); - dirs_expanded.insert(create_nested(), true); + dirs_expanded.insert(create_dir(), true); let needle = create_nested(); let expected = Some(create_child_one()); @@ -469,7 +470,7 @@ mod tests { fn test_visit_node_no_match() { let tree = create_test_tree(); let mut dirs_expanded = HashMap::new(); - dirs_expanded.insert(create_nested(), true); + dirs_expanded.insert(create_dir(), true); let needle = create_not_used(); let expected = None; @@ -483,7 +484,7 @@ mod tests { fn test_visit_node_nested_prev() { let tree = create_test_tree(); let mut dirs_expanded = HashMap::new(); - dirs_expanded.insert(create_nested(), true); + dirs_expanded.insert(create_dir(), true); let needle = create_child_one(); let expected = Some(create_nested()); @@ -497,7 +498,7 @@ mod tests { fn test_visit_prev_into_nested() { let tree = create_test_tree(); let mut dirs_expanded = HashMap::new(); - dirs_expanded.insert(create_nested(), true); + dirs_expanded.insert(create_dir(), true); let needle = create_root_two(); let expected = Some(create_child_two()); diff --git a/tui/src/components/api_explorer/res_viewer.rs b/tui/src/components/api_explorer/res_viewer.rs index 88b6c01..f89951c 100644 --- a/tui/src/components/api_explorer/res_viewer.rs +++ b/tui/src/components/api_explorer/res_viewer.rs @@ -1,10 +1,10 @@ -use reqtui::{net::request_manager::ReqtuiResponse, syntax::highlighter::Highlighter}; +use reqtui::net::request_manager::ReqtuiResponse; use ratatui::{ buffer::Buffer, layout::{Constraint, Direction, Layout, Rect}, - style::{Style, Stylize}, - text::Line, + style::{Style, Styled, Stylize}, + text::{Line, Span}, widgets::{ Block, Borders, Paragraph, Scrollbar, ScrollbarOrientation, ScrollbarState, StatefulWidget, Tabs, Widget, @@ -18,8 +18,8 @@ use std::{ pub struct ResViewerState<'a> { is_focused: bool, is_selected: bool, - response: Option, - curr_tab: ResViewerTabs, + response: Option<&'a ReqtuiResponse>, + curr_tab: &'a ResViewerTabs, raw_scroll: &'a mut usize, } @@ -62,8 +62,8 @@ impl<'a> ResViewerState<'a> { pub fn new( is_focused: bool, is_selected: bool, - response: Option, - curr_tab: ResViewerTabs, + response: Option<&'a ReqtuiResponse>, + curr_tab: &'a ResViewerTabs, raw_scroll: &'a mut usize, ) -> Self { ResViewerState { @@ -121,7 +121,7 @@ impl<'a> ResViewer<'a> { } fn draw_raw_response(&self, state: &mut ResViewerState, buf: &mut Buffer, size: Rect) { - if let Some(ref response) = state.response { + if let Some(response) = state.response { let lines = response .body .chars() @@ -162,18 +162,16 @@ impl<'a> ResViewer<'a> { let mut scrollbar_state = ScrollbarState::new(total_ines).position(current_scroll); let scrollbar = Scrollbar::new(ScrollbarOrientation::VerticalRight) - .style(Style::default().fg(self.colors.normal.magenta.into())) + .style(Style::default().fg(self.colors.normal.magenta)) .begin_symbol(Some("↑")) .end_symbol(Some("↓")); scrollbar.render(size, buf, &mut scrollbar_state); } - fn draw_preview_response(&self, state: &mut ResViewerState, _buf: &mut Buffer, _size: Rect) { - if let Some(ref response) = state.response { - let mut high = Highlighter::default(); - let res = high.apply(&response.body); - tracing::debug!("{res:?}") + fn draw_preview_response(&self, state: &mut ResViewerState, buf: &mut Buffer, size: Rect) { + if let Some(response) = state.response { + response.pretty_body.display.clone().render(size, buf); } } } diff --git a/tui/src/components/api_explorer/sidebar.rs b/tui/src/components/api_explorer/sidebar.rs index f2650bc..c08ce9d 100644 --- a/tui/src/components/api_explorer/sidebar.rs +++ b/tui/src/components/api_explorer/sidebar.rs @@ -1,4 +1,4 @@ -use reqtui::schema::types::{Request, RequestKind, RequestMethod}; +use reqtui::schema::types::{Directory, Request, RequestKind, RequestMethod}; use ratatui::{ buffer::Buffer, @@ -13,7 +13,7 @@ pub struct SidebarState<'a> { requests: Option<&'a [RequestKind]>, selected_request: Option<&'a Request>, hovered_requet: Option<&'a RequestKind>, - dirs_expanded: &'a mut HashMap, + dirs_expanded: &'a mut HashMap, is_focused: bool, } @@ -22,7 +22,7 @@ impl<'a> SidebarState<'a> { requests: Option<&'a [RequestKind]>, selected_request: Option<&'a Request>, hovered_requet: Option<&'a RequestKind>, - dirs_expanded: &'a mut HashMap, + dirs_expanded: &'a mut HashMap, is_focused: bool, ) -> Self { SidebarState { @@ -98,7 +98,7 @@ fn build_lines( level: usize, selected_request: Option<&Request>, hovered_request: Option<&RequestKind>, - dirs_expanded: &mut HashMap, + dirs_expanded: &mut HashMap, colors: &colors::Colors, ) -> Vec { requests @@ -107,7 +107,7 @@ fn build_lines( .flat_map(|item| match item { RequestKind::Nested(dir) => { let is_hovered = hovered_request.is_some_and(|req| *req == *item); - let is_expanded = dirs_expanded.entry(item.clone()).or_insert(false); + let is_expanded = dirs_expanded.entry(dir.clone()).or_insert(false); let dir_style = match is_hovered { true => Style::default() diff --git a/tui/src/components/terminal_too_small.rs b/tui/src/components/terminal_too_small.rs index ee6fe89..d3a80cb 100644 --- a/tui/src/components/terminal_too_small.rs +++ b/tui/src/components/terminal_too_small.rs @@ -1,3 +1,4 @@ +use crate::components::Component; use ratatui::{ layout::{Alignment, Constraint, Direction, Flex, Layout, Rect}, style::Stylize, @@ -6,8 +7,6 @@ use ratatui::{ Frame, }; -use super::Component; - pub struct TerminalTooSmall<'a> { colors: &'a colors::Colors, }