From eebf8831eb1f8bc58d08a083c78910bb2394f32d Mon Sep 17 00:00:00 2001 From: Araxeus Date: Mon, 13 Mar 2023 00:53:45 +0200 Subject: [PATCH] Make every file/directory a clickable link (#30) --- Cargo.lock | 387 ++++++++++++++++++++++++++------- Cargo.toml | 8 +- src/main.rs | 10 +- src/structs/icons.rs | 12 +- src/structs/mod.rs | 2 +- src/structs/prompt.rs | 64 +++--- src/structs/prompt_renderer.rs | 157 +++---------- src/utils.rs | 12 +- 8 files changed, 399 insertions(+), 253 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d07f539..bef90e7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -46,6 +46,17 @@ dependencies = [ "parking_lot", ] +[[package]] +name = "async-channel" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf46fee83e5ccffc220104713af3292ff9bc7c64c7de289f66dae8e38d826833" +dependencies = [ + "concurrent-queue", + "event-listener", + "futures-core", +] + [[package]] name = "async-executor" version = "1.5.0" @@ -60,6 +71,18 @@ dependencies = [ "slab", ] +[[package]] +name = "async-fs" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "279cf904654eeebfa37ac9bb1598880884924aab82e290aa65c9e77a0e142e06" +dependencies = [ + "async-lock", + "autocfg", + "blocking", + "futures-lite", +] + [[package]] name = "async-io" version = "1.12.0" @@ -77,7 +100,7 @@ dependencies = [ "slab", "socket2", "waker-fn", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -92,9 +115,9 @@ dependencies = [ [[package]] name = "async-recursion" -version = "1.0.0" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cda8f4bcc10624c4e85bc66b3f452cca98cfa5ca002dc83a16aad2367641bea" +checksum = "3b015a331cc64ebd1774ba119538573603427eaace0a1950c423ab971f903796" dependencies = [ "proc-macro2", "quote", @@ -109,15 +132,21 @@ checksum = "7a40729d2133846d9ed0ea60a8b9541bccddab49cd30f0715a1da672fe9a2524" [[package]] name = "async-trait" -version = "0.1.60" +version = "0.1.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d1d8ab452a3936018a687b20e6f7cf5363d713b732b8884001317b0e48aa3" +checksum = "eff18d764974428cf3a9328e23fc5c986f5fbed46e6cd4cdf42544df5d297ec1" dependencies = [ "proc-macro2", "quote", "syn", ] +[[package]] +name = "atomic-waker" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "debc29dde2e69f9e47506b525f639ed42300fc014a3e007832592448fa8e4599" + [[package]] name = "autocfg" version = "1.1.0" @@ -160,6 +189,20 @@ dependencies = [ "generic-array", ] +[[package]] +name = "blocking" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c67b173a56acffd6d2326fb7ab938ba0b00a71480e14902b2591c87bc5741e8" +dependencies = [ + "async-channel", + "async-lock", + "async-task", + "atomic-waker", + "fastrand", + "futures-lite", +] + [[package]] name = "bumpalo" version = "3.12.0" @@ -209,11 +252,28 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "concolor" +version = "0.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7b3e3c41e9488eeda196b6806dbf487742107d61b2e16485bcca6c25ed5755b" +dependencies = [ + "bitflags", + "concolor-query", + "is-terminal", +] + +[[package]] +name = "concolor-query" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82a90734b3d5dcf656e7624cca6bce9c3a90ee11f900e80141a7427ccfb3d317" + [[package]] name = "concurrent-queue" -version = "2.0.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd7bef69dc86e3c610e4e7aed41035e2a7ed12e72dd7530f61327a6579a4390b" +checksum = "c278839b831783b70278b14df4d45e1beb1aad306c07bb796637de9a0e323e8e" dependencies = [ "crossbeam-utils", ] @@ -228,7 +288,7 @@ dependencies = [ "lazy_static", "libc", "unicode-width", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -257,9 +317,9 @@ dependencies = [ [[package]] name = "crossterm" -version = "0.26.0" +version = "0.26.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77f67c7faacd4db07a939f55d66a983a5355358a1f17d32cc9a8d01d1266b9ce" +checksum = "a84cda67535339806297f1b331d6dd6320470d2a0fe65381e79ee9e156dd3d13" dependencies = [ "bitflags", "crossterm_winapi", @@ -292,9 +352,9 @@ dependencies = [ [[package]] name = "cxx" -version = "1.0.91" +version = "1.0.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86d3488e7665a7a483b57e25bdd90d0aeb2bc7608c8d0346acf2ad3f1caf1d62" +checksum = "322296e2f2e5af4270b54df9e85a02ff037e271af20ba3e7fe1575515dc840b8" dependencies = [ "cc", "cxxbridge-flags", @@ -304,9 +364,9 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.91" +version = "1.0.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48fcaf066a053a41a81dfb14d57d99738b767febb8b735c3016e469fac5da690" +checksum = "017a1385b05d631e7875b1f151c9f012d37b53491e2a87f65bff5c262b2111d8" dependencies = [ "cc", "codespan-reporting", @@ -319,15 +379,15 @@ dependencies = [ [[package]] name = "cxxbridge-flags" -version = "1.0.91" +version = "1.0.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2ef98b8b717a829ca5603af80e1f9e2e48013ab227b68ef37872ef84ee479bf" +checksum = "c26bbb078acf09bc1ecda02d4223f03bdd28bd4874edcb0379138efc499ce971" [[package]] name = "cxxbridge-macro" -version = "1.0.91" +version = "1.0.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "086c685979a698443656e5cf7856c95c642295a38599f12fb1ff76fb28d19892" +checksum = "357f40d1f06a24b60ae1fe122542c1fb05d28d32acb2aed064e84bc2ad1e252e" dependencies = [ "proc-macro2", "quote", @@ -432,6 +492,27 @@ dependencies = [ "syn", ] +[[package]] +name = "errno" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" +dependencies = [ + "errno-dragonfly", + "libc", + "winapi", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "event-listener" version = "2.5.3" @@ -493,8 +574,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "197676987abd2f9cadff84926f410af1c183608d36641465df73ae8211dc65d6" dependencies = [ "futures-core", + "futures-io", "futures-sink", "futures-task", + "memchr", "pin-project-lite", "pin-utils", "slab", @@ -532,9 +615,15 @@ dependencies = [ [[package]] name = "gimli" -version = "0.27.0" +version = "0.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dec7af912d60cdbd3677c1af9352ebae6fb8394d165568a2234df0fa00f87793" +checksum = "221996f774192f0f718773def8201c4ae31f02616a54ccfc2d358bb0e5cefdec" + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "heck" @@ -545,6 +634,12 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "hermit-abi" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" + [[package]] name = "hex" version = "0.4.3" @@ -553,12 +648,13 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "human-panic" -version = "1.0.3" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39f357a500abcbd7c5f967c1d45c8838585b36743823b9d43488f24850534e36" +checksum = "86d13dc3bae03e53a5e81a3944773631df2c5a33c060e195c1f7bf3fd0d2a696" dependencies = [ "backtrace", - "os_type", + "concolor", + "os_info", "serde", "serde_derive", "termcolor", @@ -590,6 +686,16 @@ dependencies = [ "cxx-build", ] +[[package]] +name = "indexmap" +version = "1.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" +dependencies = [ + "autocfg", + "hashbrown", +] + [[package]] name = "instant" version = "0.1.12" @@ -599,6 +705,28 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "io-lifetimes" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfa919a82ea574332e2de6e74b4c36e74d41982b335080fa59d4ef31be20fdf3" +dependencies = [ + "libc", + "windows-sys 0.45.0", +] + +[[package]] +name = "is-terminal" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b6b32576413a8e69b90e952e4a026476040d81017b80445deda5f2d3921857" +dependencies = [ + "hermit-abi", + "io-lifetimes", + "rustix", + "windows-sys 0.45.0", +] + [[package]] name = "itoa" version = "1.0.5" @@ -607,9 +735,9 @@ checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440" [[package]] name = "js-sys" -version = "0.3.61" +version = "0.3.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730" +checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" dependencies = [ "wasm-bindgen", ] @@ -635,6 +763,12 @@ dependencies = [ "cc", ] +[[package]] +name = "linux-raw-sys" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" + [[package]] name = "lnk" version = "0.5.1" @@ -713,9 +847,9 @@ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "memoffset" -version = "0.6.5" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" +checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4" dependencies = [ "autocfg", ] @@ -738,21 +872,30 @@ dependencies = [ "libc", "log", "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] name = "nix" -version = "0.25.1" +version = "0.26.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f346ff70e7dbfd675fe90590b92d59ef2de15a8779ae305ebcbfd3f0caf59be4" +checksum = "bfdda3d196821d6af13126e40375cdf7da646a96114af134d5f417a9a1dc8e1a" dependencies = [ - "autocfg", "bitflags", "cfg-if", "libc", "memoffset", "pin-utils", + "static_assertions", +] + +[[package]] +name = "nom8" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae01545c9c7fc4486ab7debaf2aad7003ac19431791868fb2e8066df97fad2f8" +dependencies = [ + "memchr", ] [[package]] @@ -829,9 +972,9 @@ dependencies = [ [[package]] name = "object" -version = "0.30.1" +version = "0.30.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d864c91689fdc196779b98dba0aceac6118594c2df6ee5d943eb6a8df4d107a" +checksum = "ea86265d3d3dcb6a27fc51bd29a4bf387fae9d2986b823079d4986af253eb439" dependencies = [ "memchr", ] @@ -844,12 +987,11 @@ checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" [[package]] name = "open" -version = "3.2.0" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2078c0039e6a54a0c42c28faa984e115fb4c2d5bf2208f77d1961002df8576f8" +checksum = "bd61e3bf9d78956c72ee864bba52431f7f43994b21a17e9e72596a81bd61075b" dependencies = [ "pathdiff", - "windows-sys", ] [[package]] @@ -863,12 +1005,14 @@ dependencies = [ ] [[package]] -name = "os_type" -version = "2.6.0" +name = "os_info" +version = "3.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e24d44c0eea30167516ed8f6daca4b5e3eebcde1bde1e4e6e08b809fb02c7ba5" +checksum = "5c424bc68d15e0778838ac013b5b3449544d8133633d8016319e7e05a820b8c0" dependencies = [ - "regex", + "log", + "serde", + "winapi", ] [[package]] @@ -889,15 +1033,15 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.5" +version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ff9f3fef3968a3ec5945535ed654cb38ff72d7495a25619e2247fb15a2ed9ba" +checksum = "ba1ef8814b5c993410bb3adfad7a5ed269563e4a2f90c41f5d85be7fb47133bf" dependencies = [ "cfg-if", "libc", "redox_syscall", "smallvec", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -929,7 +1073,7 @@ dependencies = [ "libc", "log", "wepoll-ffi", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -940,20 +1084,19 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro-crate" -version = "1.2.1" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eda0fc3b0fb7c975631757e14d9049da17374063edb6ebbcbc54d880d4fe94e9" +checksum = "66618389e4ec1c7afe67d51a9bf34ff9236480f8d51e7489b7d5ab0303c13f34" dependencies = [ "once_cell", - "thiserror", - "toml", + "toml_edit 0.18.1", ] [[package]] name = "proc-macro2" -version = "1.0.49" +version = "1.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57a8eca9f9c4ffde41714334dee777596264c7825420f521abc92b5b5deb63a5" +checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" dependencies = [ "unicode-ident", ] @@ -1028,9 +1171,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.7.0" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a" +checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" dependencies = [ "aho-corasick", "memchr", @@ -1058,6 +1201,20 @@ version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" +[[package]] +name = "rustix" +version = "0.36.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd5c6ff11fecd55b40746d1995a02f2eb375bf8c00d192d521ee09f42bef37bc" +dependencies = [ + "bitflags", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys", + "windows-sys 0.45.0", +] + [[package]] name = "ryu" version = "1.0.12" @@ -1098,9 +1255,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.93" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cad406b69c91885b5107daf2c29572f6c8cdb3c66826821e286c533490c0bc76" +checksum = "1c533a59c9d8a93a09c6ab31f0fd5e5f4dd1b8fc9434804029839884765d04ea" dependencies = [ "itoa", "ryu", @@ -1118,6 +1275,15 @@ dependencies = [ "syn", ] +[[package]] +name = "serde_spanned" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0efd8caf556a6cebd3b285caf480045fcc1ac04f6bd786b09a6f11af30c4fcf4" +dependencies = [ + "serde", +] + [[package]] name = "sha1" version = "0.10.5" @@ -1249,9 +1415,9 @@ dependencies = [ [[package]] name = "termcolor" -version = "1.1.3" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" dependencies = [ "winapi-util", ] @@ -1325,13 +1491,55 @@ dependencies = [ [[package]] name = "toml" -version = "0.5.10" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7afcae9e3f0fe2c370fd4657108972cbb2fa9db1b9f84849cefd80741b01cb6" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime 0.6.1", + "toml_edit 0.19.5", +] + +[[package]] +name = "toml_datetime" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4553f467ac8e3d374bc9a177a26801e5d0f9b211aa1673fb137a403afd1c9cf5" + +[[package]] +name = "toml_datetime" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1333c76748e868a4d9d1017b5ab53171dfd095f70c712fdb4653a406547f598f" +checksum = "3ab8ed2edee10b50132aed5f331333428b011c99402b5a534154ed15746f9622" dependencies = [ "serde", ] +[[package]] +name = "toml_edit" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56c59d8dd7d0dcbc6428bf7aa2f0e823e26e43b3c9aca15bbc9475d23e5fa12b" +dependencies = [ + "indexmap", + "nom8", + "toml_datetime 0.5.1", +] + +[[package]] +name = "toml_edit" +version = "0.19.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7082a95d48029677a28f181e5f6422d0c8339ad8396a39d3f33d62a90c1f6c30" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime 0.6.1", + "winnow", +] + [[package]] name = "tracing" version = "0.1.37" @@ -1400,9 +1608,9 @@ checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" [[package]] name = "uuid" -version = "0.8.2" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" +checksum = "1674845326ee10d37ca60470760d4288a6f80f304007d92e5c53bab78c9cfd79" dependencies = [ "getrandom", ] @@ -1433,9 +1641,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.84" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" +checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -1443,9 +1651,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.84" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9" +checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" dependencies = [ "bumpalo", "log", @@ -1458,9 +1666,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.84" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" +checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1468,9 +1676,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.84" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" +checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" dependencies = [ "proc-macro2", "quote", @@ -1481,9 +1689,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.84" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" +checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" [[package]] name = "wepoll-ffi" @@ -1562,6 +1770,15 @@ dependencies = [ "windows_x86_64_msvc 0.42.1", ] +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-targets" version = "0.42.1" @@ -1649,14 +1866,24 @@ version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" +[[package]] +name = "winnow" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee7b2c67f962bf5042bfd8b6a916178df33a26eec343ae064cb8e069f638fa6f" +dependencies = [ + "memchr", +] + [[package]] name = "zbus" -version = "3.10.0" +version = "3.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f770930448dd412a4a7131dd968a8e6df0064db4d7916fbbd2d6c3f26b566938" +checksum = "20aae5dd5b051971cd2f49f9f3b860e57b2b495ba5ba254eaec42d34ede57e97" dependencies = [ "async-broadcast", "async-executor", + "async-fs", "async-io", "async-lock", "async-recursion", @@ -1689,15 +1916,16 @@ dependencies = [ [[package]] name = "zbus_macros" -version = "3.10.0" +version = "3.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4832059b438689017db7340580ebabba07f114eab91bf990c6e55052408b40d8" +checksum = "9264b3a1bcf5503d4e0348b6e7efe1da58d4f92a913c15ed9e63b52de85faaa1" dependencies = [ "proc-macro-crate", "proc-macro2", "quote", "regex", "syn", + "zvariant_utils", ] [[package]] @@ -1736,3 +1964,14 @@ dependencies = [ "quote", "syn", ] + +[[package]] +name = "zvariant_utils" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53b22993dbc4d128a17a3b6c92f1c63872dd67198537ee728d8b5d7c40640a8b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/Cargo.toml b/Cargo.toml index 0a5d5a5..3155936 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,12 +12,12 @@ keywords = ["ls", "lsi", "cli", "interactive", "explorer", "list", "files", "fol categories = ["command-line-utilities"] [dependencies] -console = "=0.15.5" # ANY LATER VERSION BREAKS SCROLLING (0.15.1 - 0.15.3 tested) -open = "3.2.0" -human-panic = "1.0.3" +console = "0.15.5" +open = "4.0.0" +human-panic = "1.1.1" lnk = "0.5.1" fuzzy-matcher = "0.3.7" -crossterm = "0.26.0" +crossterm = "0.26.1" unicode-segmentation = "1.10.1" tiny_update_notifier = "2.2.0" diff --git a/src/main.rs b/src/main.rs index 9f080a2..8430248 100644 --- a/src/main.rs +++ b/src/main.rs @@ -42,6 +42,11 @@ fn main_loop(initial_path: String) { let entry = choices[index].clone(); + if modifier == KeyModifiers::SHIFT || modifier == KeyModifiers::ALT { + print!("{}", pretty_path(&entry.path)); + break; + } + // exec file if entry.filetype.should_exec() || modifier == KeyModifiers::CONTROL { match open::that(&entry.path) { @@ -55,11 +60,6 @@ fn main_loop(initial_path: String) { } } - if modifier == KeyModifiers::SHIFT || modifier == KeyModifiers::ALT { - print!("{}", pretty_path(&selected_entry.path)); - break; - } - // browse directory by continuing loop with new path selected_entry = entry; diff --git a/src/structs/icons.rs b/src/structs/icons.rs index ca6ac99..c1c2756 100644 --- a/src/structs/icons.rs +++ b/src/structs/icons.rs @@ -2,13 +2,14 @@ use super::Filetype; use std::fmt; +#[derive(PartialEq, Eq)] pub struct Icon(&'static str); -impl Icon { - pub const fn str(&self) -> &'static str { - self.0 - } -} +// impl Icon { +// pub const fn str(&self) -> &'static str { +// self.0 +// } +// } impl fmt::Display for Icon { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { @@ -39,6 +40,7 @@ impl Icons { // Windows Only pub const PC: Icon = Icon("🖥️"); + #[allow(dead_code)] pub const DRIVE: Icon = Icon("💽"); // TODO diff --git a/src/structs/mod.rs b/src/structs/mod.rs index f81f90a..fd557f3 100644 --- a/src/structs/mod.rs +++ b/src/structs/mod.rs @@ -9,5 +9,5 @@ pub use crate::structs::{ filetype::Filetype, icons::{Icon, Icons}, prompt::Prompt, - prompt_renderer::ColorfulTheme, + prompt_renderer::Theme, }; diff --git a/src/structs/prompt.rs b/src/structs/prompt.rs index 23ca64e..2e93165 100644 --- a/src/structs/prompt.rs +++ b/src/structs/prompt.rs @@ -1,7 +1,10 @@ -use super::prompt_renderer::{SimpleTheme, TermRenderer, Theme}; +use super::{ + prompt_renderer::{TermRenderer, Theme}, + Entry, Filetype, +}; use console::Term; use crossterm::{ - event::{read, Event, KeyCode, KeyEvent, KeyModifiers}, + event::{read, Event, KeyCode, KeyEvent, KeyEventKind, KeyModifiers}, terminal, }; @@ -9,40 +12,26 @@ use fuzzy_matcher::FuzzyMatcher; use std::io; use unicode_segmentation::UnicodeSegmentation; -use crate::Icons; /// Renders a selection menu that user can fuzzy match to reduce set. /// /// User can use fuzzy search to limit selectable items. /// Interaction returns index of an item selected in the order they appear in `item` invocation or `items` slice. - pub struct Prompt<'a> { default: usize, - items: Vec, + items: Vec, title: String, report: bool, clear: bool, highlight_matches: bool, - theme: &'a dyn Theme, -} - -impl Default for Prompt<'static> { - fn default() -> Self { - Self::new() - } -} - -impl Prompt<'static> { - /// Creates the prompt with a specific text. - pub fn new() -> Self { - Self::with_theme(&SimpleTheme) - } + theme: &'a Theme, } impl Prompt<'_> { /// Adds multiple items to the fuzzy selector. - pub fn items(&mut self, items: &[T]) -> &mut Self { - for item in items { - self.items.push(item.to_string()); + pub fn items(&mut self, items: &[Entry]) -> &mut Self { + let its = items.to_owned(); + for item in its { + self.items.push(item); } self } @@ -78,9 +67,9 @@ impl Prompt<'_> { let mut sel = self.default; let mut size_vec = Vec::new(); - for items in self.items.iter().as_slice() { - let size = &items.len(); - size_vec.push(*size); + for item in self.items.iter().as_slice() { + let size = &item.name.len() + 2; + size_vec.push(size); } // Fuzzy matcher @@ -107,7 +96,7 @@ impl Prompt<'_> { let mut filtered_list = self .items .iter() - .map(|item| (item, matcher.fuzzy_match(item, &search_term.concat()))) + .map(|item| (item, matcher.fuzzy_match(&item.name, &search_term.concat()))) .filter_map(|(item, score)| score.map(|s| (item, s))) .collect::>(); @@ -133,7 +122,10 @@ impl Prompt<'_> { terminal::enable_raw_mode()?; if let Event::Key(KeyEvent { - code, modifiers, .. + code, + modifiers, + kind: KeyEventKind::Press | KeyEventKind::Repeat, + .. }) = read().unwrap() { match code { @@ -170,7 +162,7 @@ impl Prompt<'_> { if cursor_pos > 0 { cursor_pos -= 1; term.flush()?; - } else if search_term.is_empty() && self.items[0].ends_with("..") { + } else if search_term.is_empty() && self.items[0].name.ends_with("..") { if self.clear { render.clear()?; } @@ -187,18 +179,19 @@ impl Prompt<'_> { cursor_pos += 1; term.flush()?; } else if search_term.is_empty() - && (filtered_list[sel].0.contains(Icons::DIR.str()) + && !filtered_list.is_empty() + && (filtered_list[sel].0.filetype == Filetype::Directory || (cfg!(windows) - && filtered_list[sel].0.contains(Icons::DRIVE.str()))) + && filtered_list[sel].0.filetype == Filetype::DriveView)) { if self.clear { render.clear()?; } - let sel_string = filtered_list[sel].0; + let sel_string_pos_in_items = self .items .iter() - .position(|item| item.eq(sel_string)) + .position(|item| item.name.eq(&filtered_list[sel].0.name)) .unwrap(); terminal::disable_raw_mode()?; @@ -216,15 +209,14 @@ impl Prompt<'_> { if self.report { render.input_prompt_selection( self.title.as_str(), - filtered_list[sel].0, + &filtered_list[sel].0.name, )?; } - let sel_string = filtered_list[sel].0; let sel_string_pos_in_items = self .items .iter() - .position(|item| item.eq(sel_string)) + .position(|item| item.name.eq(&filtered_list[sel].0.name)) .unwrap(); terminal::disable_raw_mode()?; @@ -260,7 +252,7 @@ impl Prompt<'_> { impl<'a> Prompt<'a> { /// Same as `new` but with a specific theme. - pub fn with_theme(theme: &'a dyn Theme) -> Self { + pub const fn with_theme(theme: &'a Theme) -> Self { Self { default: 0, items: vec![], diff --git a/src/structs/prompt_renderer.rs b/src/structs/prompt_renderer.rs index af96673..8c7ef74 100644 --- a/src/structs/prompt_renderer.rs +++ b/src/structs/prompt_renderer.rs @@ -4,93 +4,12 @@ use std::{fmt, io}; use console::{style, Style, StyledObject, Term}; use fuzzy_matcher::{skim::SkimMatcherV2, FuzzyMatcher}; -/// Implements a theme for dialoguer. -pub trait Theme { - /// Formats a prompt. - #[inline] - fn format_prompt(&self, f: &mut dyn fmt::Write, prompt: &str) -> fmt::Result { - write!(f, "{prompt}:") - } - - /// Formats out an error. - #[inline] - fn format_error(&self, f: &mut dyn fmt::Write, err: &str) -> fmt::Result { - write!(f, "error: {err}") - } - - /// Formats an input prompt after selection. - #[inline] - fn format_input_prompt_selection( - &self, - f: &mut dyn fmt::Write, - prompt: &str, - sel: &str, - ) -> fmt::Result { - write!(f, "{prompt}: {sel}") - } - - /// Formats a fuzzy select prompt item. - fn format_fuzzy_select_prompt_item( - &self, - f: &mut dyn fmt::Write, - text: &str, - active: bool, - highlight_matches: bool, - matcher: &SkimMatcherV2, - search_term: &str, - ) -> fmt::Result { - write!(f, "{} ", if active { ">" } else { " " })?; - - if highlight_matches { - if let Some((_score, indices)) = matcher.fuzzy_indices(text, search_term) { - for (idx, c) in text.chars().enumerate() { - if indices.contains(&idx) { - write!(f, "{}", style(c).for_stderr().bold())?; - } else { - write!(f, "{c}")?; - } - } +use crate::utils::{link, link_with_label, pretty_path}; - return Ok(()); - } - } - - write!(f, "{text}") - } - - /// Formats a fuzzy select prompt. - fn format_fuzzy_select_prompt( - &self, - f: &mut dyn fmt::Write, - prompt: &str, - search_term: &[String], - cursor_pos: usize, - ) -> fmt::Result { - if !prompt.is_empty() { - write!(f, "{prompt} ",)?; - } - - if cursor_pos < search_term.len() { - let split = search_term.split_at(cursor_pos); - let head = split.0.concat(); - let cursor = "|".to_string(); - let tail = split.1.concat(); - - write!(f, "{head}{cursor}{tail}") - } else { - let cursor = "|".to_string(); - write!(f, "{}{cursor}", search_term.concat()) - } - } -} - -/// The default theme. -pub struct SimpleTheme; - -impl Theme for SimpleTheme {} +use super::Entry; /// A colorful theme -pub struct ColorfulTheme { +pub struct Theme { /// The style for default values pub defaults_style: Style, /// The style for prompt @@ -135,7 +54,7 @@ pub struct ColorfulTheme { pub inline_selections: bool, } -impl Default for ColorfulTheme { +impl Default for Theme { fn default() -> Self { Self { defaults_style: Style::new().for_stderr().cyan(), @@ -163,21 +82,7 @@ impl Default for ColorfulTheme { } } -impl Theme for ColorfulTheme { - /// Formats a prompt. - fn format_prompt(&self, f: &mut dyn fmt::Write, prompt: &str) -> fmt::Result { - if !prompt.is_empty() { - write!( - f, - "{} {} ", - &self.prompt_prefix, - self.prompt_style.apply_to(prompt) - )?; - } - - write!(f, "{}", &self.prompt_suffix) - } - +impl Theme { /// Formats an error fn format_error(&self, f: &mut dyn fmt::Write, err: &str) -> fmt::Result { write!( @@ -216,7 +121,7 @@ impl Theme for ColorfulTheme { fn format_fuzzy_select_prompt_item( &self, f: &mut dyn fmt::Write, - text: &str, + entry: &Entry, active: bool, highlight_matches: bool, matcher: &SkimMatcherV2, @@ -227,46 +132,46 @@ impl Theme for ColorfulTheme { ('\u{0591}'..='\u{07FF}').contains(&c) // c >= '\u{0591}' && c <= '\u{07FF}' } + let mut output = String::new(); + write!( f, - "{} ", + "{}", if active { - &self.active_item_prefix + format!("{} {} ", &self.active_item_prefix, entry.icon,) } else { - &self.inactive_item_prefix - } + format!("{} {} ", &self.inactive_item_prefix, entry.icon) + }, )?; if highlight_matches { - if let Some((_score, indices)) = matcher.fuzzy_indices(text, search_term) { - for (idx, c) in text.chars().enumerate() { - if text.starts_with('\u{1f5a5}') && c == ' ' && active { - continue; // fix `🖥️ ..` is printed as `🖥️ ..` - }; + if let Some((_score, indices)) = matcher.fuzzy_indices(&entry.name, search_term) { + for (idx, c) in entry.name.chars().enumerate() { + let char; + if indices.contains(&idx) && !is_rtl(c) { if active { - write!( - f, + char = format!( "{}", self.active_item_style .apply_to(self.fuzzy_match_highlight_style.apply_to(c)) - )?; + ); } else { - write!(f, "{}", self.fuzzy_match_highlight_style.apply_to(c))?; + char = format!("{}", self.fuzzy_match_highlight_style.apply_to(c)); } - } else if active && c != '\u{1f5a5}' && c != '\u{fe0f}' { - // Fix `🖥️` is printed as `🖥 ` (because painting those unicode chars breaks the emoji) - write!(f, "{}", self.active_item_style.apply_to(c))?; + } else if active { + char = format!("{}", self.active_item_style.apply_to(c)); } else { - write!(f, "{c}")?; - } + char = format!("{c}"); + }; + output.push_str(&char); } - + write!(f, "{}", link_with_label(pretty_path(&entry.path), &output))?; return Ok(()); } } - write!(f, "{text}") + write!(f, "{}", entry.name) } /// Formats a fuzzy-selectprompt after selection. @@ -282,7 +187,7 @@ impl Theme for ColorfulTheme { f, "{} {} ", &self.prompt_prefix, - self.prompt_style.apply_to(prompt) + self.prompt_style.apply_to(link(prompt)) )?; } @@ -309,14 +214,14 @@ impl Theme for ColorfulTheme { /// Helper struct to conveniently render a theme ot a term. pub struct TermRenderer<'a> { term: &'a Term, - theme: &'a dyn Theme, + theme: &'a Theme, height: usize, prompt_height: usize, prompts_reset_height: bool, } impl<'a> TermRenderer<'a> { - pub fn new(term: &'a Term, theme: &'a dyn Theme) -> TermRenderer<'a> { + pub const fn new(term: &'a Term, theme: &'a Theme) -> TermRenderer<'a> { TermRenderer { term, theme, @@ -372,7 +277,7 @@ impl<'a> TermRenderer<'a> { pub fn fuzzy_select_prompt_item( &mut self, - text: &str, + entry: &Entry, active: bool, highlight: bool, matcher: &SkimMatcherV2, @@ -381,7 +286,7 @@ impl<'a> TermRenderer<'a> { self.write_formatted_line(|this, buf| { this.theme.format_fuzzy_select_prompt_item( buf, - text, + entry, active, highlight, matcher, diff --git a/src/utils.rs b/src/utils.rs index ba49859..df4b33d 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,4 +1,4 @@ -use crate::structs::{ColorfulTheme, Entry, Prompt}; +use crate::structs::{Entry, Prompt, Theme}; use console::style; @@ -38,7 +38,7 @@ pub fn resolve_lnk(path: &String) -> String { // returns the index of the selected choice pub fn display_choices(items: &[Entry], path: &str) -> (usize, KeyModifiers) { - Prompt::with_theme(&ColorfulTheme::default()) + Prompt::with_theme(&Theme::default()) .title(pretty_path(path)) .items(items) .run() @@ -65,6 +65,14 @@ pub fn pretty_path(path: &str) -> &str { } } +pub fn link(path: &str) -> String { + link_with_label(path, path) +} + +pub fn link_with_label(path: &str, label: &str) -> String { + format!("\u{1b}]8;;{path}\u{1b}\\{label}\u{1b}]8;;\u{1b}\\") +} + /**** WINDOWS ONLY ****/ #[cfg(windows)]