From 46a7a87251acea6b1db30682001b30ba9628c79b Mon Sep 17 00:00:00 2001 From: Dian M Fay Date: Mon, 31 May 2021 23:25:01 -0400 Subject: [PATCH 01/31] replace termion with crossterm for portability & configurability load and apply config from ~/.mcfly/mcfly.toml sample config file remove lightmode in favor of color customization interface cleanup and formatting correct example key_scheme supply alternate default colors for MCFLY_LIGHT --- Cargo.lock | 473 ++++++++++++++++++++--------- Cargo.toml | 4 +- README.md | 9 +- mcfly.example.toml | 31 ++ src/interface.rs | 721 +++++++++++++++++++++++++++++---------------- src/settings.rs | 83 ++++-- 6 files changed, 901 insertions(+), 420 deletions(-) create mode 100644 mcfly.example.toml diff --git a/Cargo.lock b/Cargo.lock index 46b316b4..02812ef1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "aho-corasick" -version = "0.7.10" +version = "0.7.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8716408b8bc624ed7f65d223ddb9ac2d044c0547b6fa4b0d554f3a9540496ada" +checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" dependencies = [ "memchr", ] @@ -21,16 +21,13 @@ dependencies = [ ] [[package]] -name = "arrayref" -version = "0.3.6" +name = "atomic" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" - -[[package]] -name = "arrayvec" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8" +checksum = "c3410529e8288c463bedb5930f82833bc0c90e5d2fe639a56582a4d09220b281" +dependencies = [ + "autocfg", +] [[package]] name = "atty" @@ -45,15 +42,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" - -[[package]] -name = "base64" -version = "0.11.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] name = "bitflags" @@ -61,22 +52,11 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" -[[package]] -name = "blake2b_simd" -version = "0.5.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8fb2d74254a3a0b5cac33ac9f8ed0e44aa50378d9dbb2e5d83bd21ed1dc2c8a" -dependencies = [ - "arrayref", - "arrayvec", - "constant_time_eq", -] - [[package]] name = "bstr" -version = "0.2.12" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2889e6d50f394968c8bf4240dc3f2a7eb4680844d27308f798229ac9d4725f41" +checksum = "90682c8d613ad3373e66de8c6411e0ae2ab2571e879d2efbf73558cc66f21279" dependencies = [ "lazy_static", "memchr", @@ -84,17 +64,11 @@ dependencies = [ "serde", ] -[[package]] -name = "byteorder" -version = "1.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" - [[package]] name = "cc" -version = "1.0.52" +version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3d87b23d6a92cd03af510a5ade527033f6aa6fa92161e2d5863a907d4c5e31d" +checksum = "4a72c244c1ff497a746a7e1fb3d14bd08420ecda70c8f25c7112f2781652d787" [[package]] name = "cfg-if" @@ -102,6 +76,12 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + [[package]] name = "chrono" version = "0.4.19" @@ -117,9 +97,9 @@ dependencies = [ [[package]] name = "clap" -version = "2.33.0" +version = "2.33.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" +checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" dependencies = [ "ansi_term", "atty", @@ -131,27 +111,35 @@ dependencies = [ ] [[package]] -name = "constant_time_eq" -version = "0.1.5" +name = "crossterm" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" +checksum = "4e86d73f2a0b407b5768d10a8c720cf5d2df49a9efc10ca09176d201ead4b7fb" +dependencies = [ + "bitflags", + "crossterm_winapi", + "lazy_static", + "libc", + "mio", + "parking_lot", + "signal-hook", + "winapi", +] [[package]] -name = "crossbeam-utils" -version = "0.7.2" +name = "crossterm_winapi" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" +checksum = "c2265c3f8e080075d9b6417aa72293fc71662f34b4af2612d8d1b074d29510db" dependencies = [ - "autocfg", - "cfg-if", - "lazy_static", + "winapi", ] [[package]] name = "csv" -version = "1.1.3" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00affe7f6ab566df61b4be3ce8cf16bc2576bca0963ceb0955e45d514bf9a279" +checksum = "22813a6dc45b335f9bade10bf7271dc477e81113e89eb251a0bc2a8a81c536e1" dependencies = [ "bstr", "csv-core", @@ -175,17 +163,37 @@ version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13aea89a5c93364a98e9b37b2fa237effbb694d5cfe01c5b70941f7eb087d5e3" dependencies = [ - "cfg-if", + "cfg-if 0.1.10", "dirs-sys", ] +[[package]] +name = "dirs-next" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" +dependencies = [ + "cfg-if 1.0.0", + "dirs-sys-next", +] + [[package]] name = "dirs-sys" -version = "0.3.4" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03d86534ed367a67548dc68113a0f5db55432fdfbb6e6f9d77704397d95d5780" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + +[[package]] +name = "dirs-sys-next" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afa0b23de8fd801745c471deffa6e12d248f962c9fd4b4c33787b055599bde7b" +checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" dependencies = [ - "cfg-if", "libc", "redox_users", "winapi", @@ -197,22 +205,46 @@ version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" +[[package]] +name = "figment" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ca029e813a72b7526d28273d25f3e4a2f365d1b7a1018a6f93ec9053a119763" +dependencies = [ + "atomic", + "serde", + "toml", + "uncased", + "version_check", +] + [[package]] name = "getrandom" -version = "0.1.14" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "libc", - "wasi", + "wasi 0.9.0+wasi-snapshot-preview1", +] + +[[package]] +name = "getrandom" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "wasi 0.10.0+wasi-snapshot-preview1", ] [[package]] name = "hermit-abi" -version = "0.1.12" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61565ff7aaace3525556587bd2dc31d4a07071957be715e63ce7b1eccf51a8f4" +checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" dependencies = [ "libc", ] @@ -223,6 +255,15 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" +[[package]] +name = "instant" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec" +dependencies = [ + "cfg-if 1.0.0", +] + [[package]] name = "itertools" version = "0.9.0" @@ -234,9 +275,9 @@ dependencies = [ [[package]] name = "itoa" -version = "0.4.5" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8b7a7c0c47db5545ed3fef7468ee7bb5b74691498139e4b3f6a20685dc6dd8e" +checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" [[package]] name = "lazy_static" @@ -246,9 +287,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.69" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99e85c08494b21a9054e7fe1374a732aeadaff3980b6990b94bfd3a70f690005" +checksum = "789da6d93f1b866ffe175afc5322a4d76c038605a1c3319bb57b06967ca98a36" [[package]] name = "libsqlite3-sys" @@ -263,9 +304,27 @@ dependencies = [ [[package]] name = "linked-hash-map" -version = "0.5.3" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8dd5a6d5999d9907cda8ed67bbd137d3af8085216c2ac62de5be860bd41f304a" +checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3" + +[[package]] +name = "lock_api" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0382880606dff6d15c9476c416d18690b72742aa7b605bb6dd6ec9030fbf07eb" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" +dependencies = [ + "cfg-if 1.0.0", +] [[package]] name = "lru-cache" @@ -282,8 +341,10 @@ version = "0.5.9" dependencies = [ "chrono", "clap", + "crossterm", "csv", "dirs", + "figment", "humantime", "itertools", "libc", @@ -291,16 +352,47 @@ dependencies = [ "regex", "relative-path", "rusqlite", + "serde", "shellexpand", - "termion", "unicode-segmentation", ] [[package]] name = "memchr" -version = "2.3.3" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc" + +[[package]] +name = "mio" +version = "0.7.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf80d3e903b34e0bd7282b218398aec54e082c840d9baf8339e0080a0c542956" +dependencies = [ + "libc", + "log", + "miow", + "ntapi", + "winapi", +] + +[[package]] +name = "miow" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" +checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" +dependencies = [ + "winapi", +] + +[[package]] +name = "ntapi" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" +dependencies = [ + "winapi", +] [[package]] name = "num-integer" @@ -322,22 +414,59 @@ dependencies = [ ] [[package]] -name = "numtoa" -version = "0.1.0" +name = "parking_lot" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" +checksum = "6d7744ac029df22dca6284efe4e898991d28e3085c706c972bcd7da4a27a15eb" +dependencies = [ + "instant", + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa7a782938e745763fe6907fc6ba86946d72f49fe7e21de074e08128a99fb018" +dependencies = [ + "cfg-if 1.0.0", + "instant", + "libc", + "redox_syscall", + "smallvec", + "winapi", +] [[package]] name = "pkg-config" -version = "0.3.17" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677" +checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" [[package]] name = "ppv-lite86" -version = "0.2.6" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" + +[[package]] +name = "proc-macro2" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b" +checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" +dependencies = [ + "proc-macro2", +] [[package]] name = "rand" @@ -345,7 +474,7 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" dependencies = [ - "getrandom", + "getrandom 0.1.16", "libc", "rand_chacha", "rand_core", @@ -368,7 +497,7 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" dependencies = [ - "getrandom", + "getrandom 0.1.16", ] [[package]] @@ -382,62 +511,51 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.1.56" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" - -[[package]] -name = "redox_termios" -version = "0.1.1" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" +checksum = "742739e41cd49414de871ea5e549afb7e2a3ac77b589bcbebe8c82fab37147fc" dependencies = [ - "redox_syscall", + "bitflags", ] [[package]] name = "redox_users" -version = "0.3.4" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09b23093265f8d200fa7b4c2c76297f47e681c655f6f1285a8780d6a022f7431" +checksum = "528532f3d801c87aec9def2add9ca802fe569e44a544afe633765267840abe64" dependencies = [ - "getrandom", + "getrandom 0.2.3", "redox_syscall", - "rust-argon2", ] [[package]] name = "regex" -version = "1.3.7" +version = "1.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6020f034922e3194c711b82a627453881bc4682166cabb07134a10c26ba7692" +checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" dependencies = [ "aho-corasick", "memchr", "regex-syntax", - "thread_local", ] [[package]] name = "regex-automata" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae1ded71d66a4a97f5e961fd0cb25a5f366a42a41570d16a763a69c092c26ae4" -dependencies = [ - "byteorder", -] +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" [[package]] name = "regex-syntax" -version = "0.6.17" +version = "0.6.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fe5bd57d1d7414c6b5ed48563a2c855d995ff777729dcd91c369ec7fea395ae" +checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" [[package]] name = "relative-path" -version = "1.0.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bedde000f40f2921ce439ea165c9c53fd629bfa115140c72e22aceacb4a21954" +checksum = "a479d53d7eed831f3c92ca79c61002d5987e21417d528296832f802bca532380" [[package]] name = "rusqlite" @@ -452,38 +570,72 @@ dependencies = [ ] [[package]] -name = "rust-argon2" -version = "0.7.0" +name = "ryu" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bc8af4bda8e1ff4932523b94d3dd20ee30a87232323eda55903ffd71d2fb017" -dependencies = [ - "base64", - "blake2b_simd", - "constant_time_eq", - "crossbeam-utils", -] +checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" [[package]] -name = "ryu" -version = "1.0.4" +name = "scopeguard" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed3d612bc64430efeb3f7ee6ef26d590dce0c43249217bddc62112540c7941e1" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "serde" -version = "1.0.106" +version = "1.0.126" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec7505abeacaec74ae4778d9d9328fe5a5d04253220a85c4ee022239fc996d03" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.126" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36df6ac6412072f67cf767ebbde4133a5b2e88e76dc6187fa7104cd16f783399" +checksum = "963a7dbc9895aeac7ac90e74f34a5d5261828f79df35cbed41e10189d3804d43" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] [[package]] name = "shellexpand" -version = "2.0.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2b22262a9aaf9464d356f656fea420634f78c881c5eebd5ef5e66d8b9bc603" +checksum = "83bdb7831b2d85ddf4a7b148aa19d0587eddbe8671a436b7bd1182eaad0f2829" dependencies = [ - "dirs", + "dirs-next", +] + +[[package]] +name = "signal-hook" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e31d442c16f047a671b5a71e2161d6e68814012b7f5379d269ebd915fac2729" +dependencies = [ + "libc", + "mio", + "signal-hook-registry", +] + +[[package]] +name = "signal-hook-registry" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0" +dependencies = [ + "libc", ] +[[package]] +name = "smallvec" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" + [[package]] name = "strsim" version = "0.8.0" @@ -491,15 +643,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] -name = "termion" -version = "1.5.5" +name = "syn" +version = "1.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c22cec9d8978d906be5ac94bceb5a010d885c626c4c8855721a4dbd20e3ac905" +checksum = "a1e8cdbefb79a9a5a65e0db8b47b723ee907b7c7f8496c76a1770b5c310bab82" dependencies = [ - "libc", - "numtoa", - "redox_syscall", - "redox_termios", + "proc-macro2", + "quote", + "unicode-xid", ] [[package]] @@ -512,41 +663,57 @@ dependencies = [ ] [[package]] -name = "thread_local" -version = "1.0.1" +name = "time" +version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14" +checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" dependencies = [ - "lazy_static", + "libc", + "wasi 0.10.0+wasi-snapshot-preview1", + "winapi", ] [[package]] -name = "time" -version = "0.1.43" +name = "toml" +version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" +checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" dependencies = [ - "libc", - "winapi", + "serde", +] + +[[package]] +name = "uncased" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5baeed7327e25054889b9bd4f975f32e5f4c5d434042d59ab6cd4142c0a76ed0" +dependencies = [ + "version_check", ] [[package]] name = "unicode-segmentation" -version = "1.6.0" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0" +checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" [[package]] name = "unicode-width" -version = "0.1.7" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479" +checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" + +[[package]] +name = "unicode-xid" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" [[package]] name = "vcpkg" -version = "0.2.8" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fc439f2794e98976c88a2a2dafce96b930fe8010b0a256b3c2199a773933168" +checksum = "025ce40a007e1907e58d5bc1a594def78e5573bb0b1160bc389634e8f12e4faa" [[package]] name = "vec_map" @@ -554,17 +721,29 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" +[[package]] +name = "version_check" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" + [[package]] name = "wasi" version = "0.9.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" +[[package]] +name = "wasi" +version = "0.10.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" + [[package]] name = "winapi" -version = "0.3.8" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" dependencies = [ "winapi-i686-pc-windows-gnu", "winapi-x86_64-pc-windows-gnu", diff --git a/Cargo.toml b/Cargo.toml index eb9252e4..2479e024 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,15 +23,17 @@ debug = true chrono = "0.4.19" clap = "2.33" csv = "1" +crossterm = "0.18" dirs = "2.0" +figment = { version = "0.10", features = ["toml"] } humantime = "2.1.0" itertools = "0.9.0" libc = "0.2" rand = "0.7" regex = "1" relative-path = "1.0" +serde = { version = "1.0", features = ["derive"] } shellexpand = "2.0" -termion = "1.5.5" unicode-segmentation = "1.6" [dependencies.rusqlite] diff --git a/README.md b/README.md index dc8b0189..41d8905b 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ McFly replaces your default `ctrl-r` shell history search with an intelligent search engine that takes into account your working directory and the context of recently executed commands. McFly's suggestions are prioritized in real time with a small neural network. - + TL;DR: an upgraded `ctrl-r` where history results make sense for what you're working on right now. ## Features @@ -193,10 +193,13 @@ To avoid McFly's UI messing up your scrollback history in iTerm2, make sure this iterm2 UI instructions ## Settings -A number of settings can be set via environment variables. To set a setting you should add the following snippets to your `~/.bashrc` / `~/.zshrc` / `~/.config/fish/config.fish`. + +Settings, in particular the interface colors, may be configured in [`~/.mcfly/mcfly.toml`](https://github.com/cantino/mcfly/blob/crossterm-and-colors/mcfly.example.toml). + +A number of settings can also be set via environment variables. To set a setting you should add the following snippets to your `~/.bashrc` / `~/.zshrc` / `~/.config/fish/config.fish`. ### Light Mode -To swap the color scheme for use in a light terminal, set the environment variable `MCFLY_LIGHT`. +To swap the default color scheme for use in a light terminal, set the environment variable `MCFLY_LIGHT`. bash / zsh: ```bash diff --git a/mcfly.example.toml b/mcfly.example.toml new file mode 100644 index 00000000..083bc54f --- /dev/null +++ b/mcfly.example.toml @@ -0,0 +1,31 @@ +# Mcfly sample configuration, to be placed in ~/.mcfly/mcfly.toml + +fuzzy = true +results = 25 +key_scheme = "Vim" # Vim or Emacs (case-sensitive) + +[colors] +# Colors correspond to the ANSI colors defined for your terminal, and are +# named in crossterm style (case-insensitive): +# black dark_grey +# dark_red red +# dark_green green +# dark_yellow yellow +# dark_blue blue +# dark_magenta magenta +# dark_cyan cyan +# grey white + +menu_bg = "dark_red" +menu_fg = "white" +menu_deleting_bg = "cyan" +menu_deleting_fg = "dark_red" + +bg = "black" +fg = "white" +prompt_fg = "white" +highlight = "red" +timing = "magenta" +cursor_bg = "dark_grey" +cursor_fg = "white" +cursor_highlight = "red" diff --git a/src/interface.rs b/src/interface.rs index d11a3c3c..788ec4e0 100644 --- a/src/interface.rs +++ b/src/interface.rs @@ -1,3 +1,4 @@ + use crate::command_input::{CommandInput, Move}; use crate::history::History; @@ -6,15 +7,16 @@ use crate::history::Command; use crate::history_cleaner; use crate::settings::Settings; use crate::settings::{InterfaceView, KeyScheme}; +use crossterm::cursor; +use crossterm::event::{read, Event, KeyCode, KeyEvent, KeyModifiers}; +use crossterm::queue; +use crossterm::style::{Color, Print, ResetColor, SetBackgroundColor, SetForegroundColor}; +use crossterm::terminal; +use crossterm::terminal::{Clear, ClearType, EnterAlternateScreen, LeaveAlternateScreen}; +use std::io::{stdout, Write}; +use std::str::FromStr; use chrono::{Duration, TimeZone, Utc}; use humantime::format_duration; -use std::io::{stdin, stdout, Write}; -use termion::color; -use termion::event::Key; -use termion::input::TermRead; -use termion::raw::IntoRawMode; -use termion::screen::AlternateScreen; -use termion::{clear, cursor, terminal_size}; pub struct Interface<'a> { history: &'a History, @@ -66,17 +68,28 @@ impl MenuMode { } } - fn bg(&self) -> String { + fn bg(&self, interface: &Interface) -> Color { + match *self { + MenuMode::Normal => Color::from_str(&interface.settings.colors.menu_bg).unwrap(), + MenuMode::ConfirmDelete => { + Color::from_str(&interface.settings.colors.menu_deleting_bg).unwrap() + } + } + } + + fn fg(&self, interface: &Interface) -> Color { match *self { - MenuMode::Normal => color::Bg(color::LightBlue).to_string(), - MenuMode::ConfirmDelete => color::Bg(color::Red).to_string(), + MenuMode::Normal => Color::from_str(&interface.settings.colors.menu_fg).unwrap(), + MenuMode::ConfirmDelete => { + Color::from_str(&interface.settings.colors.menu_deleting_fg).unwrap() + } } } } -const PROMPT_LINE_INDEX: u16 = 3; -const INFO_LINE_INDEX: u16 = 1; -const RESULTS_TOP_INDEX: u16 = 5; +const PROMPT_LINE_INDEX: u16 = 2; +const INFO_LINE_INDEX: u16 = 0; +const RESULTS_TOP_INDEX: u16 = 4; impl<'a> Interface<'a> { pub fn new(settings: &'a Settings, history: &'a History) -> Interface<'a> { @@ -133,136 +146,89 @@ impl<'a> Interface<'a> { } fn menubar(&self, screen: &mut W) { - let (width, _height): (u16, u16) = terminal_size().unwrap(); - write!( + let (width, _height): (u16, u16) = terminal::size().unwrap(); + + let _ = queue!(screen, cursor::MoveTo(0, self.info_line_index())); + let _ = queue!(screen, SetBackgroundColor(self.menu_mode.bg(self))); + let _ = queue!(screen, SetForegroundColor(self.menu_mode.fg(self))); + let _ = queue!( screen, - "{hide}{cursor}{clear}{fg}{bg}{text:width$}{reset_bg}", - hide = cursor::Hide, - fg = color::Fg(color::LightWhite).to_string(), - bg = self.menu_mode.bg(), - cursor = cursor::Goto(1, self.info_line_index()), - clear = clear::CurrentLine, - text = self.menu_mode.text(self), - reset_bg = color::Bg(color::Reset).to_string(), - width = width as usize - ) - .unwrap(); + Print(format!( + "{text:width$}", + text = self.menu_mode.text(self), + width = width as usize + )) + ); + let _ = queue!(screen, ResetColor); + screen.flush().unwrap(); } fn prompt(&self, screen: &mut W) { - let prompt_line_index = self.prompt_line_index(); - write!( + let _ = queue!( screen, - "{}{}{}$ {}", - if self.settings.lightmode { - color::Fg(color::Black).to_string() - } else { - color::Fg(color::LightWhite).to_string() - }, - cursor::Goto(1, self.prompt_line_index()), - clear::CurrentLine, - self.input - ) - .unwrap(); - write!( + SetForegroundColor(Color::from_str(&self.settings.colors.prompt_fg).unwrap()) + ); + let _ = queue!(screen, cursor::MoveTo(0, self.prompt_line_index())); + let _ = queue!(screen, Clear(ClearType::CurrentLine)); + let _ = queue!(screen, Print(format!("$ {}", self.input))); + let _ = queue!( screen, - "{}{}", - cursor::Goto(self.input.cursor as u16 + 3, prompt_line_index), - cursor::Show - ) - .unwrap(); - screen.flush().unwrap(); - } + cursor::MoveTo(self.input.cursor as u16 + 2, self.prompt_line_index()) + ); + + if self.in_vim_insert_mode { + let _ = queue!(screen, cursor::EnableBlinking); + } else { + let _ = queue!(screen, cursor::DisableBlinking); + } + + let _ = queue!(screen, cursor::Show); - fn debug_cursor(&self, screen: &mut W) { - let result_top_index = self.result_top_index(); - write!( - screen, - "{}{}", - cursor::Hide, - cursor::Goto(0, result_top_index + self.settings.results + 1) - ) - .unwrap(); screen.flush().unwrap(); } fn results(&mut self, screen: &mut W) { - let result_top_index = self.result_top_index(); - write!( - screen, - "{}{}{}", - cursor::Hide, - cursor::Goto(1, result_top_index), - clear::All - ) - .unwrap(); - let (width, _height): (u16, u16) = terminal_size().unwrap(); + let _ = queue!(screen, cursor::Hide); + let _ = queue!(screen, cursor::MoveTo(0, self.result_top_index())); + let _ = queue!(screen, Clear(ClearType::All)); + + let (width, _height): (u16, u16) = terminal::size().unwrap(); if !self.matches.is_empty() && self.selection > self.matches.len() - 1 { self.selection = self.matches.len() - 1; } for (index, command) in self.matches.iter().enumerate() { - let mut fg = if self.settings.lightmode { - color::Fg(color::Black).to_string() - } else { - color::Fg(color::LightWhite).to_string() - }; - - let mut highlight = if self.settings.lightmode { - color::Fg(color::Blue).to_string() - } else { - color::Fg(color::Green).to_string() - }; - - let mut bg = color::Bg(color::Reset).to_string(); + let mut fg = Color::from_str(&self.settings.colors.fg).unwrap(); + let mut bg = Color::Reset; + let mut highlight = Color::from_str(&self.settings.colors.highlight).unwrap(); + let mut timing_color = Color::from_str(&self.settings.colors.timing).unwrap(); if index == self.selection { - if self.settings.lightmode { - fg = color::Fg(color::LightWhite).to_string(); - bg = color::Bg(color::LightBlack).to_string(); - highlight = color::Fg(color::White).to_string(); - } else { - fg = color::Fg(color::Black).to_string(); - bg = color::Bg(color::LightWhite).to_string(); - highlight = color::Fg(color::Green).to_string(); - } + fg = Color::from_str(&self.settings.colors.cursor_fg).unwrap(); + bg = Color::from_str(&self.settings.colors.cursor_bg).unwrap(); + highlight = Color::from_str(&self.settings.colors.cursor_highlight).unwrap(); + timing_color = Color::from_str(&self.settings.colors.timing).unwrap(); } - write!(screen, "{}{}", fg, bg).unwrap(); - let command_line_index = self.command_line_index(index as i16); - - write!( + let _ = queue!(screen, cursor::MoveTo(0, (command_line_index as i16 + self.result_top_index() as i16) as u16)); + let _ = queue!(screen, SetBackgroundColor(bg)); + let _ = queue!(screen, SetForegroundColor(fg)); + let _ = queue!( screen, - "{}{}", - cursor::Goto( - 1, - (command_line_index as i16 + result_top_index as i16) as u16 - ), - Interface::truncate_for_display( + Print(&format!("{: Interface<'a> { .collect::>() .join(" "); - let highlight = if self.settings.lightmode { - color::Fg(color::Blue).to_string() - } else { - color::Fg(color::LightBlue).to_string() - }; - - write!(screen, "{}", highlight).unwrap(); - write!(screen, "{:>9}", duration).unwrap(); + let _ = queue!(screen, cursor::MoveTo(width - 9, (command_line_index as i16 + self.result_top_index() as i16) as u16)); + let _ = queue!(screen, SetForegroundColor(timing_color)); + let _ = queue!(screen, Print(&format!("{:>9}", duration))); + let _ = queue!(screen, SetForegroundColor(fg)); } - - write!(screen, "{}", color::Bg(color::Reset)).unwrap(); - write!(screen, "{}", color::Fg(color::Reset)).unwrap(); } screen.flush().unwrap(); } #[allow(unused)] fn debug>(&self, screen: &mut W, s: S) { - write!( - screen, - "{}{}{}", - cursor::Goto(1, 2), - clear::CurrentLine, - s.into() - ) - .unwrap(); + let _ = queue!(screen, cursor::MoveTo(0, 0)); + let _ = queue!(screen, Clear(ClearType::CurrentLine)); + let _ = queue!(screen, Print(s.into())); + screen.flush().unwrap(); } @@ -384,42 +339,60 @@ impl<'a> Interface<'a> { } fn select(&mut self) { - let stdin = stdin(); - let mut screen = AlternateScreen::from(stdout().into_raw_mode().unwrap()); - // let mut screen = stdout().into_raw_mode().unwrap(); - write!(screen, "{}", clear::All).unwrap(); + let _ = terminal::enable_raw_mode(); + + let mut screen = stdout(); + + let _ = queue!(screen, EnterAlternateScreen); + let _ = queue!(screen, Clear(ClearType::All)); self.refresh_matches(); self.results(&mut screen); self.menubar(&mut screen); self.prompt(&mut screen); - for c in stdin.keys() { - self.debug_cursor(&mut screen); + loop { + let event = + read().unwrap_or_else(|e| panic!("McFly error: failed to read input {:?}", &e)); if self.menu_mode != MenuMode::Normal { - match c.unwrap() { - Key::Ctrl('c') - | Key::Ctrl('d') - | Key::Ctrl('g') - | Key::Ctrl('z') - | Key::Ctrl('r') => { + match event { + Event::Key(KeyEvent { + modifiers: KeyModifiers::CONTROL, + code: + KeyCode::Char('c') + | KeyCode::Char('d') + | KeyCode::Char('g') + | KeyCode::Char('z') + | KeyCode::Char('r'), + }) => { self.run = false; self.input.clear(); break; } - Key::Char('y') | Key::Char('Y') => { + Event::Key(KeyEvent { + code: KeyCode::Char('y'), + .. + }) => { self.confirm(true); } - Key::Char('n') | Key::Char('N') | Key::Esc => { + Event::Key( + KeyEvent { + code: KeyCode::Char('n'), + .. + } + | KeyEvent { + code: KeyCode::Esc, .. + }, + ) => { self.confirm(false); } _ => {} - } + }; } else { let early_out = match self.settings.key_scheme { - KeyScheme::Emacs => self.select_with_emacs_key_scheme(c.unwrap()), - KeyScheme::Vim => self.select_with_vim_key_scheme(c.unwrap()), + KeyScheme::Emacs => self.select_with_emacs_key_scheme(event), + KeyScheme::Vim => self.select_with_vim_key_scheme(event), }; if early_out { @@ -432,70 +405,144 @@ impl<'a> Interface<'a> { self.prompt(&mut screen); } - write!(screen, "{}{}", clear::All, cursor::Show).unwrap(); + let _ = queue!(screen, Clear(ClearType::All)); + let _ = queue!(screen, cursor::Show); + let _ = queue!(screen, LeaveAlternateScreen); + + let _ = terminal::disable_raw_mode(); } - fn select_with_emacs_key_scheme(&mut self, k: Key) -> bool { - match k { - Key::Char('\n') | Key::Char('\r') | Key::Ctrl('j') => { - self.run = true; - self.accept_selection(); + fn select_with_emacs_key_scheme(&mut self, event: Event) -> bool { + match event { + Event::Key( + KeyEvent { + modifiers: KeyModifiers::CONTROL, + code: + KeyCode::Char('c') + | KeyCode::Char('g') + | KeyCode::Char('z') + | KeyCode::Char('r'), + } + | KeyEvent { + code: KeyCode::Esc, .. + }, + ) => { + self.run = false; + self.input.clear(); return true; } - Key::Char('\t') => { + + Event::Key(KeyEvent { + code: KeyCode::Tab, .. + }) => { self.run = false; self.accept_selection(); return true; } - Key::Ctrl('c') | Key::Ctrl('g') | Key::Ctrl('z') | Key::Esc | Key::Ctrl('r') => { - self.run = false; - self.input.clear(); + + Event::Key( + KeyEvent { + code: KeyCode::Enter, + .. + } + | KeyEvent { + modifiers: KeyModifiers::CONTROL, + code: KeyCode::Char('j'), + }, + ) => { + self.run = true; + self.accept_selection(); return true; } - Key::Ctrl('b') => self.input.move_cursor(Move::Backward), - Key::Ctrl('f') => self.input.move_cursor(Move::Forward), - Key::Ctrl('a') => self.input.move_cursor(Move::BOL), - Key::Ctrl('e') => self.input.move_cursor(Move::EOL), - Key::Ctrl('w') | Key::Alt('\x08') | Key::Alt('\x7f') => { + + Event::Key( + KeyEvent { + modifiers: KeyModifiers::CONTROL, + code: KeyCode::Char('w'), + } + | KeyEvent { + modifiers: KeyModifiers::ALT, + code: KeyCode::Char('\x08') | KeyCode::Char('\x7f'), + }, + ) => { self.input.delete(Move::BackwardWord); self.refresh_matches(); } - Key::Alt('d') => { - self.input.delete(Move::ForwardWord); - self.refresh_matches(); - } - Key::Ctrl('v') => { - self.debug = !self.debug; - } - Key::Alt('b') => self.input.move_cursor(Move::BackwardWord), - Key::Alt('f') => self.input.move_cursor(Move::ForwardWord), - Key::Left => self.input.move_cursor(Move::Backward), - Key::Right => self.input.move_cursor(Move::Forward), - Key::Up | Key::PageUp | Key::Ctrl('p') => self.move_selection(MoveSelection::Up), - Key::Down | Key::PageDown | Key::Ctrl('n') => self.move_selection(MoveSelection::Down), - Key::Ctrl('k') => { - self.input.delete(Move::EOL); - self.refresh_matches(); - } - Key::Ctrl('u') => { - self.input.delete(Move::BOL); - self.refresh_matches(); - } - Key::Backspace | Key::Ctrl('h') => { + + Event::Key(KeyEvent { + code: KeyCode::Left, + .. + }) => self.input.move_cursor(Move::Backward), + Event::Key(KeyEvent { + code: KeyCode::Right, + .. + }) => self.input.move_cursor(Move::Forward), + + Event::Key( + KeyEvent { + code: KeyCode::Up | KeyCode::PageUp, + .. + } + | KeyEvent { + modifiers: KeyModifiers::CONTROL, + code: KeyCode::Char('p'), + }, + ) => self.move_selection(MoveSelection::Up), + + Event::Key( + KeyEvent { + code: KeyCode::Down | KeyCode::PageDown, + .. + } + | KeyEvent { + modifiers: KeyModifiers::CONTROL, + code: KeyCode::Char('n'), + }, + ) => self.move_selection(MoveSelection::Down), + + Event::Key( + KeyEvent { + code: KeyCode::Backspace, + .. + } + | KeyEvent { + modifiers: KeyModifiers::CONTROL, + code: KeyCode::Char('h'), + }, + ) => { self.input.delete(Move::Backward); self.refresh_matches(); } - Key::Delete | Key::Ctrl('d') => { + Event::Key(KeyEvent { + code: KeyCode::Delete, + .. + } + | KeyEvent { + modifiers: KeyModifiers::CONTROL, + code: KeyCode::Char('d') + }) => { self.input.delete(Move::Forward); self.refresh_matches(); } - Key::Home => self.input.move_cursor(Move::BOL), - Key::End => self.input.move_cursor(Move::EOL), - Key::Char(c) => { + + Event::Key(KeyEvent { + code: KeyCode::Home, + .. + }) => self.input.move_cursor(Move::BOL), + Event::Key(KeyEvent { + code: KeyCode::End, .. + }) => self.input.move_cursor(Move::EOL), + Event::Key(KeyEvent { + code: KeyCode::Char(c), + .. + }) => { self.input.insert(c); self.refresh_matches(); } - Key::F(2) => { + Event::Key(KeyEvent { + code: KeyCode::F(2), + .. + }) => { if !self.matches.is_empty() { if self.settings.delete_without_confirm { self.delete_selection(); @@ -504,54 +551,151 @@ impl<'a> Interface<'a> { } } } + + Event::Key(KeyEvent { + modifiers: KeyModifiers::CONTROL, + code, + }) => match code { + KeyCode::Char('v') => self.debug = !self.debug, + KeyCode::Char('b') => self.input.move_cursor(Move::Backward), + KeyCode::Char('f') => self.input.move_cursor(Move::Forward), + KeyCode::Char('a') => self.input.move_cursor(Move::BOL), + KeyCode::Char('e') => self.input.move_cursor(Move::EOL), + KeyCode::Char('k') => { + self.input.delete(Move::EOL); + self.refresh_matches(); + } + KeyCode::Char('u') => { + self.input.delete(Move::BOL); + self.refresh_matches(); + } + _ => {} + }, + + Event::Key(KeyEvent { + modifiers: KeyModifiers::ALT, + code, + }) => match code { + KeyCode::Char('b') => self.input.move_cursor(Move::BackwardWord), + KeyCode::Char('f') => self.input.move_cursor(Move::ForwardWord), + KeyCode::Char('d') => { + self.input.delete(Move::ForwardWord); + self.refresh_matches(); + } + _ => {} + }, + _ => {} } false } - fn select_with_vim_key_scheme(&mut self, k: Key) -> bool { + fn select_with_vim_key_scheme(&mut self, event: Event) -> bool { if self.in_vim_insert_mode { - match k { - Key::Char('\n') | Key::Char('\r') | Key::Ctrl('j') => { - self.run = true; + match event { + Event::Key(KeyEvent { + code: KeyCode::Tab, .. + }) => { + self.run = false; self.accept_selection(); return true; } - Key::Char('\t') => { - self.run = false; + + Event::Key( + KeyEvent { + code: KeyCode::Enter, + .. + } + | KeyEvent { + modifiers: KeyModifiers::CONTROL, + code: KeyCode::Char('j'), + }, + ) => { + self.run = true; self.accept_selection(); return true; } - Key::Ctrl('c') | Key::Ctrl('g') | Key::Ctrl('z') | Key::Ctrl('r') => { + + Event::Key(KeyEvent { + modifiers: KeyModifiers::CONTROL, + code: + KeyCode::Char('c') + | KeyCode::Char('g') + | KeyCode::Char('z') + | KeyCode::Char('r'), + }) => { self.run = false; self.input.clear(); return true; } - Key::Left => self.input.move_cursor(Move::Backward), - Key::Right => self.input.move_cursor(Move::Forward), - Key::Up | Key::PageUp | Key::Ctrl('u') | Key::Ctrl('p') => { - self.move_selection(MoveSelection::Up) - } - Key::Down | Key::PageDown | Key::Ctrl('d') | Key::Ctrl('n') => { - self.move_selection(MoveSelection::Down) - } - Key::Esc => self.in_vim_insert_mode = false, - Key::Backspace => { + + Event::Key(KeyEvent { + code: KeyCode::Left, + .. + }) => self.input.move_cursor(Move::Backward), + Event::Key(KeyEvent { + code: KeyCode::Right, + .. + }) => self.input.move_cursor(Move::Forward), + + Event::Key( + KeyEvent { + code: KeyCode::Up | KeyCode::PageUp, + .. + } + | KeyEvent { + modifiers: KeyModifiers::CONTROL, + code: KeyCode::Char('u') | KeyCode::Char('p'), + }, + ) => self.move_selection(MoveSelection::Up), + + Event::Key( + KeyEvent { + code: KeyCode::Down | KeyCode::PageDown, + .. + } + | KeyEvent { + modifiers: KeyModifiers::CONTROL, + code: KeyCode::Char('d') | KeyCode::Char('n'), + }, + ) => self.move_selection(MoveSelection::Down), + + Event::Key(KeyEvent { + code: KeyCode::Esc, .. + }) => self.in_vim_insert_mode = false, + Event::Key(KeyEvent { + code: KeyCode::Backspace, + .. + }) => { self.input.delete(Move::Backward); self.refresh_matches(); } - Key::Delete => { + Event::Key(KeyEvent { + code: KeyCode::Delete, + .. + }) => { self.input.delete(Move::Forward); self.refresh_matches(); } - Key::Home => self.input.move_cursor(Move::BOL), - Key::End => self.input.move_cursor(Move::EOL), - Key::Char(c) => { + Event::Key(KeyEvent { + code: KeyCode::Home, + .. + }) => self.input.move_cursor(Move::BOL), + Event::Key(KeyEvent { + code: KeyCode::End, .. + }) => self.input.move_cursor(Move::EOL), + Event::Key(KeyEvent { + code: KeyCode::Char(c), + .. + }) => { self.input.insert(c); self.refresh_matches(); } - Key::F(2) => { + Event::Key(KeyEvent { + code: KeyCode::F(2), + .. + }) => { if !self.matches.is_empty() { if self.settings.delete_without_confirm { self.delete_selection(); @@ -563,51 +707,127 @@ impl<'a> Interface<'a> { _ => {} } } else { - match k { - Key::Char('\n') | Key::Char('\r') | Key::Ctrl('j') => { - self.run = true; + match event { + Event::Key(KeyEvent { + code: KeyCode::Tab, .. + }) => { + self.run = false; self.accept_selection(); return true; } - Key::Char('\t') => { - self.run = false; + + Event::Key( + KeyEvent { + code: KeyCode::Enter, + .. + } + | KeyEvent { + modifiers: KeyModifiers::CONTROL, + code: KeyCode::Char('j'), + }, + ) => { + self.run = true; self.accept_selection(); return true; } - Key::Ctrl('c') - | Key::Ctrl('g') - | Key::Ctrl('z') - | Key::Esc - | Key::Char('q') - // TODO add ZZ as shortcut - | Key::Ctrl('r') => { + + Event::Key( + KeyEvent { + modifiers: KeyModifiers::CONTROL, + code: + KeyCode::Char('c') + | KeyCode::Char('g') + | KeyCode::Char('z') + | KeyCode::Char('r'), // TODO add ZZ as shortcut + } + | KeyEvent { + code: KeyCode::Esc, .. + }, + ) => { self.run = false; self.input.clear(); return true; } - Key::Left | Key::Char('h') => self.input.move_cursor(Move::Backward), - Key::Right | Key::Char('l') => self.input.move_cursor(Move::Forward), - Key::Up | Key::PageUp | Key::Char('k') | Key::Ctrl('u') => self.move_selection(MoveSelection::Up), - Key::Down | Key::PageDown | Key::Char('j') | Key::Ctrl('d') => self.move_selection(MoveSelection::Down), - Key::Char('b') | Key::Char('e') => self.input.move_cursor(Move::BackwardWord), - Key::Char('w') => self.input.move_cursor(Move::ForwardWord), - Key::Char('0') | Key::Char('^') => self.input.move_cursor(Move::BOL), - Key::Char('$') => self.input.move_cursor(Move::EOL), - Key::Char('i') | Key::Char('a') => self.in_vim_insert_mode = true, - Key::Backspace => { + + Event::Key(KeyEvent { + code: KeyCode::Left | KeyCode::Char('h'), + .. + }) => self.input.move_cursor(Move::Backward), + Event::Key(KeyEvent { + code: KeyCode::Right | KeyCode::Char('l'), + .. + }) => self.input.move_cursor(Move::Forward), + + Event::Key( + KeyEvent { + code: KeyCode::Up | KeyCode::PageUp | KeyCode::Char('k'), + .. + } + | KeyEvent { + modifiers: KeyModifiers::CONTROL, + code: KeyCode::Char('u'), + }, + ) => self.move_selection(MoveSelection::Up), + + Event::Key( + KeyEvent { + code: KeyCode::Down | KeyCode::PageDown | KeyCode::Char('j'), + .. + } + | KeyEvent { + modifiers: KeyModifiers::CONTROL, + code: KeyCode::Char('d'), + }, + ) => self.move_selection(MoveSelection::Down), + + Event::Key(KeyEvent { + code: KeyCode::Char('b') | KeyCode::Char('e'), + .. + }) => self.input.move_cursor(Move::BackwardWord), + Event::Key(KeyEvent { + code: KeyCode::Char('w'), + .. + }) => self.input.move_cursor(Move::ForwardWord), + Event::Key(KeyEvent { + code: KeyCode::Char('0') | KeyCode::Char('^'), + .. + }) => self.input.move_cursor(Move::BOL), + Event::Key(KeyEvent { + code: KeyCode::Char('$'), + .. + }) => self.input.move_cursor(Move::EOL), + + Event::Key(KeyEvent { + code: KeyCode::Char('i') | KeyCode::Char('a'), + .. + }) => self.in_vim_insert_mode = true, + + Event::Key(KeyEvent { + code: KeyCode::Backspace, + .. + }) => { self.input.delete(Move::Backward); self.refresh_matches(); } - Key::Delete | Key::Char('x') => { + Event::Key(KeyEvent { + code: KeyCode::Delete | KeyCode::Char('x'), + .. + }) => { self.input.delete(Move::Forward); self.refresh_matches(); } - Key::Home => self.input.move_cursor(Move::BOL), - Key::End => self.input.move_cursor(Move::EOL), - Key::Char(_c) => { - - } - Key::F(2) => { + Event::Key(KeyEvent { + code: KeyCode::Home, + .. + }) => self.input.move_cursor(Move::BOL), + Event::Key(KeyEvent { + code: KeyCode::End, .. + }) => self.input.move_cursor(Move::EOL), + + Event::Key(KeyEvent { + code: KeyCode::F(2), + .. + }) => { if !self.matches.is_empty() { if self.settings.delete_without_confirm { self.delete_selection(); @@ -627,8 +847,8 @@ impl<'a> Interface<'a> { command: &Command, search: &str, width: u16, - highlight_color: String, - base_color: String, + highlight_color: Color, + base_color: Color, debug: bool, ) -> String { let mut prev: usize = 0; @@ -646,9 +866,9 @@ impl<'a> Interface<'a> { out.push_grapheme_str(&command.cmd[prev..*start]); } - out.push_str(&highlight_color); + out.push_str(&format!("{}", SetForegroundColor(highlight_color))); out.push_grapheme_str(&command.cmd[*start..*end]); - out.push_str(&base_color); + out.push_str(&format!("{}", SetForegroundColor(base_color))); prev = *end; } } @@ -660,7 +880,7 @@ impl<'a> Interface<'a> { if debug { out.max_grapheme_length += debug_space; out.push_grapheme_str(" "); - out.push_str(&format!("{}", color::Fg(color::LightBlue))); + out.push_str(&format!("{}", SetForegroundColor(Color::Blue))); out.push_grapheme_str(format!("rnk: {:.*} ", 2, command.rank)); out.push_grapheme_str(format!("age: {:.*} ", 2, command.features.age_factor)); out.push_grapheme_str(format!("lng: {:.*} ", 2, command.features.length_factor)); @@ -687,14 +907,15 @@ impl<'a> Interface<'a> { "s_occ: {:.*} ", 2, command.features.selected_occurrences_factor )); - out.push_str(&base_color); + + out.push_str(&format!("{}", SetForegroundColor(base_color))); } out.string } fn result_top_index(&self) -> u16 { - let (_width, height): (u16, u16) = terminal_size().unwrap(); + let (_width, height): (u16, u16) = terminal::size().unwrap(); if self.is_screen_view_bottom() { return height - RESULTS_TOP_INDEX; @@ -703,7 +924,7 @@ impl<'a> Interface<'a> { } fn prompt_line_index(&self) -> u16 { - let (_width, height): (u16, u16) = terminal_size().unwrap(); + let (_width, height): (u16, u16) = terminal::size().unwrap(); if self.is_screen_view_bottom() { return height - PROMPT_LINE_INDEX; } @@ -711,7 +932,7 @@ impl<'a> Interface<'a> { } fn info_line_index(&self) -> u16 { - let (_width, height): (u16, u16) = terminal_size().unwrap(); + let (_width, height): (u16, u16) = terminal::size().unwrap(); if self.is_screen_view_bottom() { return height; } @@ -744,3 +965,5 @@ impl<'a> Interface<'a> { // Ctrl('q') | Ctrl('v') => quoted insert // Ctrl('y') => yank // Ctrl('_') => undo + + diff --git a/src/settings.rs b/src/settings.rs index 51b38011..dadb258d 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -1,15 +1,21 @@ + use crate::shell_history; use clap::AppSettings; use clap::{crate_authors, crate_version, value_t}; use clap::{App, Arg, SubCommand}; use dirs::home_dir; +use figment::{ + providers::{Format, Serialized, Toml}, + Figment, +}; +use serde::{Deserialize, Serialize}; use std::env; use std::path::PathBuf; use std::str::FromStr; use std::time::SystemTime; use std::time::UNIX_EPOCH; -#[derive(Debug)] +#[derive(Debug, Serialize, Deserialize)] pub enum Mode { Add, Search, @@ -18,32 +24,32 @@ pub enum Mode { Init, } -#[derive(Debug)] +#[derive(Debug, Serialize, Deserialize)] pub enum KeyScheme { Emacs, Vim, } -#[derive(Debug)] +#[derive(Debug, Serialize, Deserialize)] pub enum InitMode { Bash, Zsh, Fish, } -#[derive(Debug, PartialEq)] +#[derive(Debug, Serialize, Deserialize, PartialEq)] pub enum InterfaceView { Top, Bottom, } -#[derive(Debug)] +#[derive(Debug, Serialize, Deserialize)] pub enum ResultSort { Rank, LastRun, } -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, Serialize, Deserialize)] pub enum HistoryFormat { /// bash format - commands in plain text, one per line, with multi-line commands joined. /// HISTTIMEFORMAT is assumed to be empty. @@ -61,7 +67,23 @@ pub enum HistoryFormat { Fish, } -#[derive(Debug)] +#[derive(Debug, Serialize, Deserialize)] +pub struct Colors { + pub menu_bg: String, + pub menu_fg: String, + pub menu_deleting_bg: String, + pub menu_deleting_fg: String, + pub bg: String, + pub fg: String, + pub prompt_fg: String, + pub highlight: String, + pub timing: String, + pub cursor_bg: String, + pub cursor_fg: String, + pub cursor_highlight: String, +} + +#[derive(Debug, Serialize, Deserialize)] pub struct Settings { pub mode: Mode, pub debug: bool, @@ -77,7 +99,6 @@ pub struct Settings { pub old_dir: Option, pub append_to_histfile: bool, pub refresh_training_cache: bool, - pub lightmode: bool, pub key_scheme: KeyScheme, pub history_format: HistoryFormat, pub limit: Option, @@ -86,6 +107,7 @@ pub struct Settings { pub delete_without_confirm: bool, pub interface_view: InterfaceView, pub result_sort: ResultSort, + pub colors: Colors, } impl Default for Settings { @@ -105,7 +127,6 @@ impl Default for Settings { append_to_histfile: false, debug: false, fuzzy: false, - lightmode: false, key_scheme: KeyScheme::Emacs, history_format: HistoryFormat::Bash, limit: None, @@ -114,6 +135,20 @@ impl Default for Settings { delete_without_confirm: false, interface_view: InterfaceView::Top, result_sort: ResultSort::Rank, + colors: Colors { + menu_bg: "Blue".to_string(), + menu_fg: "White".to_string(), + menu_deleting_bg: "Red".to_string(), + menu_deleting_fg: "Cyan".to_string(), + bg: "Black".to_string(), + fg: "White".to_string(), + prompt_fg: "White".to_string(), + highlight: "Green".to_string(), + timing: "Blue".to_string(), + cursor_bg: "Grey".to_string(), + cursor_fg: "Black".to_string(), + cursor_highlight: "Green".to_string(), + }, } } } @@ -247,7 +282,11 @@ impl Settings { ) .get_matches(); - let mut settings = Settings::default(); + let mut settings: Settings = Figment::from(Serialized::defaults(Settings::default())) + .merge(Toml::file(Settings::mcfly_config_path())) + .extract() + .unwrap(); + if matches.is_present("init") { settings.skip_environment_check = true; } @@ -404,8 +443,9 @@ impl Settings { settings.results = results; } - settings.fuzzy = - search_matches.is_present("fuzzy") || env::var("MCFLY_FUZZY").is_ok(); + settings.fuzzy = settings.fuzzy + || env::var("MCFLY_FUZZY").is_ok() + || search_matches.is_present("fuzzy"); settings.delete_without_confirm = search_matches .is_present("delete_without_confirm") @@ -472,14 +512,12 @@ impl Settings { _ => unreachable!(), // If all subcommands are defined above, anything else is unreachable!() } - settings.lightmode = match env::var_os("MCFLY_LIGHT") { - Some(_val) => true, - None => false, - }; - settings.key_scheme = match env::var("MCFLY_KEY_SCHEME").as_ref().map(String::as_ref) { - Ok("vim") => KeyScheme::Vim, - _ => KeyScheme::Emacs, - }; + if env::var("MCFLY_KEY_SCHEME").is_ok() { + settings.key_scheme = match env::var("MCFLY_KEY_SCHEME").as_ref().map(String::as_ref) { + Ok("vim") => KeyScheme::Vim, + _ => KeyScheme::Emacs, + }; + } settings } @@ -494,7 +532,12 @@ impl Settings { .join(PathBuf::from(".mcfly")) } + pub fn mcfly_config_path() -> PathBuf { + Settings::storage_dir_path().join(PathBuf::from("mcfly.toml")) + } + pub fn mcfly_db_path() -> PathBuf { Settings::storage_dir_path().join(PathBuf::from("history.db")) } } + From 60490b979e354a1f6d5d1dfb0edfbf11420d2c93 Mon Sep 17 00:00:00 2001 From: Dian M Fay Date: Sat, 5 Jun 2021 18:19:10 -0400 Subject: [PATCH 02/31] supply alternate default colors for MCFLY_LIGHT --- src/settings.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/settings.rs b/src/settings.rs index dadb258d..ca21bb24 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -282,7 +282,26 @@ impl Settings { ) .get_matches(); - let mut settings: Settings = Figment::from(Serialized::defaults(Settings::default())) + let mut default_settings = Settings::default(); + + if env::var("MCFLY_LIGHT").is_ok() { + default_settings.colors = Colors { + menu_bg: "Blue".to_string(), + menu_fg: "White".to_string(), + menu_deleting_bg: "Red".to_string(), + menu_deleting_fg: "Cyan".to_string(), + bg: "White".to_string(), + fg: "Black".to_string(), + prompt_fg: "Black".to_string(), + highlight: "Blue".to_string(), + timing: "Blue".to_string(), + cursor_bg: "Dark_Grey".to_string(), + cursor_fg: "White".to_string(), + cursor_highlight: "White".to_string(), + }; + } + + let mut settings: Settings = Figment::from(Serialized::defaults(default_settings)) .merge(Toml::file(Settings::mcfly_config_path())) .extract() .unwrap(); From 6b89f605be2b043dd9fe9770c4467b96f9406ab4 Mon Sep 17 00:00:00 2001 From: Dian M Fay Date: Mon, 21 Jun 2021 18:57:24 -0400 Subject: [PATCH 03/31] cargo update --- Cargo.lock | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 02812ef1..a3f5f0e8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -287,9 +287,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.95" +version = "0.2.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "789da6d93f1b866ffe175afc5322a4d76c038605a1c3319bb57b06967ca98a36" +checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6" [[package]] name = "libsqlite3-sys" @@ -365,9 +365,9 @@ checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc" [[package]] name = "mio" -version = "0.7.11" +version = "0.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf80d3e903b34e0bd7282b218398aec54e082c840d9baf8339e0080a0c542956" +checksum = "8c2bdb6314ec10835cd3293dd268473a835c02b7b352e788be788b3c6ca6bb16" dependencies = [ "libc", "log", @@ -511,9 +511,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.2.8" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "742739e41cd49414de871ea5e549afb7e2a3ac77b589bcbebe8c82fab37147fc" +checksum = "5ab49abadf3f9e1c4bc499e8845e152ad87d2ad2d30371841171169e9d75feee" dependencies = [ "bitflags", ] @@ -644,9 +644,9 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "syn" -version = "1.0.72" +version = "1.0.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1e8cdbefb79a9a5a65e0db8b47b723ee907b7c7f8496c76a1770b5c310bab82" +checksum = "f71489ff30030d2ae598524f61326b902466f72a0fb1a8564c001cc63425bcc7" dependencies = [ "proc-macro2", "quote", @@ -711,9 +711,9 @@ checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" [[package]] name = "vcpkg" -version = "0.2.13" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "025ce40a007e1907e58d5bc1a594def78e5573bb0b1160bc389634e8f12e4faa" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" [[package]] name = "vec_map" From 14dff307202aed7919dfda85ee201cbfccf6763d Mon Sep 17 00:00:00 2001 From: Jackson Schuster Date: Wed, 24 Aug 2022 18:13:04 -0500 Subject: [PATCH 04/31] wip --- .vscode/launch.json | 69 ++++++++ Cargo.lock | 407 +++++++++++++++++++++++++++++++++++++++++++- Cargo.toml | 1 + mcfly.ps1 | 66 +++++++ src/fake_typer.rs | 5 + src/interface.rs | 123 ++++++------- src/settings.rs | 4 +- 7 files changed, 608 insertions(+), 67 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 mcfly.ps1 diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..f12e6ff9 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,69 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "lldb", + "request": "launch", + "name": "Debug unit tests in library 'mcfly'", + "cargo": { + "args": [ + "test", + "--no-run", + "--lib", + "--package=mcfly" + ], + "filter": { + "name": "mcfly", + "kind": "lib" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug executable 'mcfly'", + "cargo": { + "args": [ + "build", + "--bin=mcfly", + "--package=mcfly" + ], + "filter": { + "name": "mcfly", + "kind": "bin" + } + }, + "args": ["--history_format", "zsh", "search"], + "env": { + "MCFLY_SESSION_ID" : "asdfasdfasdfasdf", + "HISTFILE" : "C:\\Users\\jschuster\\AppData\\Roaming\\Microsoft\\Windows\\PowerShell\\PSReadLine\\ConsoleHost_history.txt", + "MCFLY_HISTORY" : "C:\\Users\\jschuster\\AppData\\Roaming\\Microsoft\\Windows\\PowerShell\\PSReadLine\\ConsoleHost_history.txt" + }, + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug unit tests in executable 'mcfly'", + "cargo": { + "args": [ + "test", + "--no-run", + "--bin=mcfly", + "--package=mcfly" + ], + "filter": { + "name": "mcfly", + "kind": "bin" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + } + ] +} \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index a3f5f0e8..f537be95 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,12 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "adler32" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234" + [[package]] name = "aho-corasick" version = "0.7.18" @@ -46,12 +52,36 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" +[[package]] +name = "autopilot" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a2fd0359d0cd30b15419bcce7e6641a3cbe2046c612b3900216dc64bc989558" +dependencies = [ + "cocoa", + "core-foundation", + "core-graphics", + "image", + "libc", + "pkg-config", + "rand", + "scopeguard", + "winapi", + "x11", +] + [[package]] name = "bitflags" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +[[package]] +name = "block" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" + [[package]] name = "bstr" version = "0.2.16" @@ -64,6 +94,12 @@ dependencies = [ "serde", ] +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + [[package]] name = "cc" version = "1.0.68" @@ -110,6 +146,109 @@ dependencies = [ "vec_map", ] +[[package]] +name = "cocoa" +version = "0.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c49e86fc36d5704151f5996b7b3795385f50ce09e3be0f47a0cfde869681cf8" +dependencies = [ + "bitflags", + "block", + "core-foundation", + "core-graphics", + "foreign-types", + "libc", + "objc", +] + +[[package]] +name = "color_quant" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" + +[[package]] +name = "core-foundation" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57d24c7a13c43e870e37c1556b74555437870a04514f7685f5b354e090567171" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" + +[[package]] +name = "core-graphics" +version = "0.19.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3889374e6ea6ab25dba90bb5d96202f61108058361f6dc72e8b03e6f8bbe923" +dependencies = [ + "bitflags", + "core-foundation", + "foreign-types", + "libc", +] + +[[package]] +name = "crc32fast" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" +dependencies = [ + "cfg-if 1.0.0", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521" +dependencies = [ + "cfg-if 1.0.0", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "715e8152b692bba2d374b53d4875445368fdf21a94751410af607a5ac677d1fc" +dependencies = [ + "cfg-if 1.0.0", + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "045ebe27666471bb549370b4b0b3e51b07f56325befa4284db65fc89c02511b1" +dependencies = [ + "autocfg", + "cfg-if 1.0.0", + "crossbeam-utils", + "memoffset", + "once_cell", + "scopeguard", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51887d4adc7b564537b15adcfb307936f8075dfcd5f00dde9a9f1d29383682bc" +dependencies = [ + "cfg-if 1.0.0", + "once_cell", +] + [[package]] name = "crossterm" version = "0.18.2" @@ -157,6 +296,16 @@ dependencies = [ "memchr", ] +[[package]] +name = "deflate" +version = "0.7.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "707b6a7b384888a70c8d2e8650b3e60170dfc6a67bb4aa67b6dfca57af4bedb4" +dependencies = [ + "adler32", + "byteorder", +] + [[package]] name = "dirs" version = "2.0.2" @@ -218,6 +367,21 @@ dependencies = [ "version_check", ] +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + [[package]] name = "getrandom" version = "0.1.16" @@ -240,6 +404,16 @@ dependencies = [ "wasi 0.10.0+wasi-snapshot-preview1", ] +[[package]] +name = "gif" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "471d90201b3b223f3451cd4ad53e34295f16a1df17b1edf3736d47761c3981af" +dependencies = [ + "color_quant", + "lzw", +] + [[package]] name = "hermit-abi" version = "0.1.18" @@ -255,6 +429,32 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" +[[package]] +name = "image" +version = "0.22.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08ed2ada878397b045454ac7cfb011d73132c59f31a955d230bd1f1c2e68eb4a" +dependencies = [ + "byteorder", + "gif", + "jpeg-decoder", + "num-iter", + "num-rational", + "num-traits", + "png", + "scoped_threadpool", + "tiff", +] + +[[package]] +name = "inflate" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cdb29978cc5797bd8dcc8e5bf7de604891df2a8dc576973d71a281e916db2ff" +dependencies = [ + "adler32", +] + [[package]] name = "instant" version = "0.1.9" @@ -279,6 +479,15 @@ version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" +[[package]] +name = "jpeg-decoder" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "229d53d58899083193af11e15917b5640cd40b29ff475a1fe4ef725deb02d0f2" +dependencies = [ + "rayon", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -335,10 +544,26 @@ dependencies = [ "linked-hash-map", ] +[[package]] +name = "lzw" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d947cbb889ed21c2a84be6ffbaebf5b4e0f4340638cba0444907e38b56be084" + +[[package]] +name = "malloc_buf" +version = "0.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb" +dependencies = [ + "libc", +] + [[package]] name = "mcfly" version = "0.5.9" dependencies = [ + "autopilot", "chrono", "clap", "crossterm", @@ -363,6 +588,15 @@ version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc" +[[package]] +name = "memoffset" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" +dependencies = [ + "autocfg", +] + [[package]] name = "mio" version = "0.7.13" @@ -394,6 +628,17 @@ dependencies = [ "winapi", ] +[[package]] +name = "num-derive" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eafd0b45c5537c3ba526f79d3e75120036502bebacbb3f3220914067ce39dbf2" +dependencies = [ + "proc-macro2 0.4.30", + "quote 0.6.13", + "syn 0.15.44", +] + [[package]] name = "num-integer" version = "0.1.44" @@ -404,6 +649,28 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-iter" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c000134b5dbf44adc5cb772486d335293351644b801551abe8f75c84cfa4aef" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.14" @@ -413,6 +680,31 @@ dependencies = [ "autocfg", ] +[[package]] +name = "num_cpus" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "objc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1" +dependencies = [ + "malloc_buf", +] + +[[package]] +name = "once_cell" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" + [[package]] name = "parking_lot" version = "0.11.1" @@ -444,19 +736,49 @@ version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" +[[package]] +name = "png" +version = "0.15.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef859a23054bbfee7811284275ae522f0434a3c8e7f4b74bd4a35ae7e1c4a283" +dependencies = [ + "bitflags", + "crc32fast", + "deflate", + "inflate", +] + [[package]] name = "ppv-lite86" version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" +[[package]] +name = "proc-macro2" +version = "0.4.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" +dependencies = [ + "unicode-xid 0.1.0", +] + [[package]] name = "proc-macro2" version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038" dependencies = [ - "unicode-xid", + "unicode-xid 0.2.2", +] + +[[package]] +name = "quote" +version = "0.6.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" +dependencies = [ + "proc-macro2 0.4.30", ] [[package]] @@ -465,7 +787,7 @@ version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" dependencies = [ - "proc-macro2", + "proc-macro2 1.0.27", ] [[package]] @@ -509,6 +831,30 @@ dependencies = [ "rand_core", ] +[[package]] +name = "rayon" +version = "1.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd99e5772ead8baa5215278c9b15bf92087709e9c1b2d1f97cdb5a183c933a7d" +dependencies = [ + "autocfg", + "crossbeam-deque", + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "258bcdb5ac6dad48491bb2992db6b7cf74878b0384908af124823d118c99683f" +dependencies = [ + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-utils", + "num_cpus", +] + [[package]] name = "redox_syscall" version = "0.2.9" @@ -575,6 +921,12 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" +[[package]] +name = "scoped_threadpool" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d51f5df5af43ab3f1360b429fa5e0152ac5ce8c0bd6485cae490332e96846a8" + [[package]] name = "scopeguard" version = "1.1.0" @@ -596,9 +948,9 @@ version = "1.0.126" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "963a7dbc9895aeac7ac90e74f34a5d5261828f79df35cbed41e10189d3804d43" dependencies = [ - "proc-macro2", - "quote", - "syn", + "proc-macro2 1.0.27", + "quote 1.0.9", + "syn 1.0.73", ] [[package]] @@ -642,15 +994,26 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" +[[package]] +name = "syn" +version = "0.15.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5" +dependencies = [ + "proc-macro2 0.4.30", + "quote 0.6.13", + "unicode-xid 0.1.0", +] + [[package]] name = "syn" version = "1.0.73" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f71489ff30030d2ae598524f61326b902466f72a0fb1a8564c001cc63425bcc7" dependencies = [ - "proc-macro2", - "quote", - "unicode-xid", + "proc-macro2 1.0.27", + "quote 1.0.9", + "unicode-xid 0.2.2", ] [[package]] @@ -662,6 +1025,18 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "tiff" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7b7c2cfc4742bd8a32f2e614339dd8ce30dbcf676bb262bd63a2327bc5df57d" +dependencies = [ + "byteorder", + "lzw", + "num-derive", + "num-traits", +] + [[package]] name = "time" version = "0.1.44" @@ -703,6 +1078,12 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" +[[package]] +name = "unicode-xid" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" + [[package]] name = "unicode-xid" version = "0.2.2" @@ -760,3 +1141,13 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "x11" +version = "2.19.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dd0565fa8bfba8c5efe02725b14dff114c866724eff2cfd44d76cea74bcd87a" +dependencies = [ + "libc", + "pkg-config", +] diff --git a/Cargo.toml b/Cargo.toml index 2479e024..bd2b35c4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,6 +35,7 @@ relative-path = "1.0" serde = { version = "1.0", features = ["derive"] } shellexpand = "2.0" unicode-segmentation = "1.6" +autopilot = "0.4.0" [dependencies.rusqlite] version = "0.15.0" diff --git a/mcfly.ps1 b/mcfly.ps1 new file mode 100644 index 00000000..5edf75cf --- /dev/null +++ b/mcfly.ps1 @@ -0,0 +1,66 @@ + +# Ensure stdin is a tty +# Can't + +if ($env:__MCFLY_LOADED == "loaded") { + return 0; +} +$env:__MCFLY_LOADED = "loaded"; + +$env:HISTFILE = $null -eq $env:HISTFILE ? "$env:APPDATA\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt" : $HISTFILE; + +$fileExists = Test-Path -path $env:HISTFILE +if (-not $fileExists) { + Write-Output "McFly: ${env:HISTFILE} does not exist or is not readable. Please fix this or set HISTFILE to something else before using McFly."; + return 1; +} + +# MCFLY_SESSION_ID is used by McFly internally to keep track of the commands from a particular terminal session. + +$MCFLY_SESSION_ID = new-guid +$env:MCFLY_SESSION_ID = $MCFLY_SESSION_ID + +(Get-Command "mcfly.exe" -ErrorAction SilentlyContinue) | Select-Object -ExpandProperty Path | Set-Variable -Name MCFLY_PATH +if ($null -eq $MCFLY_PATH) +{ + Write-output "Cannot find the mcfly binary, please make sure that mcfly is in your path before sourcing mcfly.bash."; + return 1; +} + +if ($null -eq (Get-Module -Name PSReadLine)){ + Write-Output "Installing PSReadLine for keybindings" + Install-Module PSReadLine +} + +if ($MCFLY_HISTORY -eq 1) { + $env:MCFLY_HISTORY = New-TemporaryFile + Get-Content $env:HISTFILE | Select-Object -Last 100 | Set-Content $env:MCFLY_HISTORY +} + +function Add-LastCommandToMcFly { + $lastCommand = Get-History -Count 1; + $lastCommandStart = Get-Date -Date $lastCommand.StartExecutionTime -UFormat %s + $MCFLY_PATH add --when $lastCommandStart +} +function global:Invoke-McFly { + $startInfo = New-Object System.Diagnostics.ProcessStartInfo -ArgumentList $MCFLY_PATH -Property @{ + StandardOutputEncoding = [System.Text.Encoding]::UTF8; + RedirectStandardOutput = $true; + RedirectStandardError = $true; + CreateNoWindow = $true; + UseShellExecute = $false; + }; + if ($startInfo.ArgumentList.Add) { + # PowerShell 6+ uses .NET 5+ and supports the ArgumentList property + # which bypasses the need for manually escaping the argument list into + # a command string. + $startInfo.ArgumentList.Add($search); + } + $process = [System.Diagnostics.Process]::Start($startInfo) +} + +function global:prompt { + Add-LastCommandToMcFly +} + +Set-PSReadLineKeyHandler -Chord "Ctrl+r" -Function Invoke-McFly \ No newline at end of file diff --git a/src/fake_typer.rs b/src/fake_typer.rs index 5962da38..664f336b 100644 --- a/src/fake_typer.rs +++ b/src/fake_typer.rs @@ -3,6 +3,7 @@ extern "C" { pub fn ioctl(fd: i8, request: u32, arg: *const u8) -> i8; } +#[cfg(not(windows))] pub fn use_tiocsti(string: &str) { for byte in string.as_bytes() { let a: *const u8 = byte; @@ -11,3 +12,7 @@ pub fn use_tiocsti(string: &str) { } } } +#[cfg(windows)] +pub fn use_tiocsti(string: &str) { + autopilot::key::type_string(string, &[], 0.0, 0.0) +} diff --git a/src/interface.rs b/src/interface.rs index 788ec4e0..d63f5c55 100644 --- a/src/interface.rs +++ b/src/interface.rs @@ -18,6 +18,9 @@ use std::str::FromStr; use chrono::{Duration, TimeZone, Utc}; use humantime::format_duration; + + + pub struct Interface<'a> { history: &'a History, settings: &'a Settings, @@ -216,17 +219,20 @@ impl<'a> Interface<'a> { let _ = queue!(screen, cursor::MoveTo(0, (command_line_index as i16 + self.result_top_index() as i16) as u16)); let _ = queue!(screen, SetBackgroundColor(bg)); let _ = queue!(screen, SetForegroundColor(fg)); - let _ = queue!( - screen, - Print(&format!("{: Interface<'a> { let _ = queue!(screen, cursor::MoveTo(width - 9, (command_line_index as i16 + self.result_top_index() as i16) as u16)); let _ = queue!(screen, SetForegroundColor(timing_color)); - let _ = queue!(screen, Print(&format!("{:>9}", duration))); + let tmp_str = format!("{:>9}", duration); + let _ = queue!(screen, Print(&tmp_str)); let _ = queue!(screen, SetForegroundColor(fg)); } } @@ -844,74 +851,76 @@ impl<'a> Interface<'a> { } fn truncate_for_display( + screen: &mut Write, command: &Command, search: &str, width: u16, - highlight_color: Color, - base_color: Color, + highlighted_text_color: Color, + text_color: Color, debug: bool, ) -> String { let mut prev: usize = 0; let debug_space = if debug { 90 } else { 0 }; - let max_grapheme_length = if width > debug_space { - width - debug_space - 9 - } else { - 11 - }; - let mut out = FixedLengthGraphemeString::empty(max_grapheme_length); + // let max_grapheme_length = if width > debug_space { + // width - debug_space - 9 + // } else { + // 11 + // }; + // let mut out = FixedLengthGraphemeString::empty(max_grapheme_length); if !search.is_empty() { for (start, end) in &command.match_bounds { if prev != *start { - out.push_grapheme_str(&command.cmd[prev..*start]); + let _ = queue!(screen, Print(&command.cmd[prev..*start])); } - out.push_str(&format!("{}", SetForegroundColor(highlight_color))); - out.push_grapheme_str(&command.cmd[*start..*end]); - out.push_str(&format!("{}", SetForegroundColor(base_color))); + let _ = queue!(screen, SetForegroundColor(highlighted_text_color)); + let _ = queue!(screen, Print(&command.cmd[*start..*end])); + let _ = queue!(screen, SetForegroundColor(text_color)); prev = *end; } } if prev != command.cmd.len() { - out.push_grapheme_str(&command.cmd[prev..]); + let _ = queue!(screen, Print(&command.cmd[prev..])); } if debug { - out.max_grapheme_length += debug_space; - out.push_grapheme_str(" "); - out.push_str(&format!("{}", SetForegroundColor(Color::Blue))); - out.push_grapheme_str(format!("rnk: {:.*} ", 2, command.rank)); - out.push_grapheme_str(format!("age: {:.*} ", 2, command.features.age_factor)); - out.push_grapheme_str(format!("lng: {:.*} ", 2, command.features.length_factor)); - out.push_grapheme_str(format!("ext: {:.*} ", 0, command.features.exit_factor)); - out.push_grapheme_str(format!( + // out.max_grapheme_length += debug_space; + let _ = queue!(screen, Print(" ")); + let _ = queue!(screen, SetForegroundColor(Color::Blue)); + let _ = queue!(screen, Print(format!("rnk: {:.*} ", 2, command.rank))); + let _ = queue!(screen, Print(format!("age: {:.*} ", 2, command.features.age_factor))); + let _ = queue!(screen, Print(format!("lng: {:.*} ", 2, command.features.length_factor))); + let _ = queue!(screen, Print(format!("ext: {:.*} ", 0, command.features.exit_factor))); + let _ = queue!(screen, Print(format!( "r_ext: {:.*} ", 0, command.features.recent_failure_factor - )); - out.push_grapheme_str(format!("dir: {:.*} ", 3, command.features.dir_factor)); - out.push_grapheme_str(format!( - "s_dir: {:.*} ", - 3, command.features.selected_dir_factor - )); - out.push_grapheme_str(format!("ovlp: {:.*} ", 3, command.features.overlap_factor)); - out.push_grapheme_str(format!( - "i_ovlp: {:.*} ", - 3, command.features.immediate_overlap_factor - )); - out.push_grapheme_str(format!( - "occ: {:.*}", - 2, command.features.occurrences_factor - )); - out.push_grapheme_str(format!( - "s_occ: {:.*} ", - 2, command.features.selected_occurrences_factor - )); - - out.push_str(&format!("{}", SetForegroundColor(base_color))); + ))); + // out.push_grapheme_str(format!("dir: {:.*} ", 3, command.features.dir_factor)); + // out.push_grapheme_str(format!( + // "s_dir: {:.*} ", + // 3, command.features.selected_dir_factor + // )); + // out.push_grapheme_str(format!("ovlp: {:.*} ", 3, command.features.overlap_factor)); + // out.push_grapheme_str(format!( + // "i_ovlp: {:.*} ", + // 3, command.features.immediate_overlap_factor + // )); + // out.push_grapheme_str(format!( + // "occ: {:.*}", + // 2, command.features.occurrences_factor + // )); + // out.push_grapheme_str(format!( + // "s_occ: {:.*} ", + // 2, command.features.selected_occurrences_factor + // )); + + // out.push_str(&format!("{}", SetForegroundColor(text_color))); } - out.string + // out.string + "".to_string() } fn result_top_index(&self) -> u16 { @@ -963,7 +972,7 @@ impl<'a> Interface<'a> { // Ctrl('s') => forward history search // Ctrl('t') => transpose characters // Ctrl('q') | Ctrl('v') => quoted insert -// Ctrl('y') => yank -// Ctrl('_') => undo + + diff --git a/src/settings.rs b/src/settings.rs index ca21bb24..2ec09a4e 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -445,12 +445,12 @@ impl Settings { if let Some(dir) = search_matches.value_of("directory") { settings.dir = dir.to_string(); } else { - settings.dir = env::var("PWD").unwrap_or_else(|err| { + settings.dir = env::current_dir().unwrap_or_else(|err| { panic!( "McFly error: Unable to determine current directory ({})", err ) - }); + }).to_str().unwrap().to_string(); } if let Ok(results) = env::var("MCFLY_RESULTS") { From 394396e3bc9e77776b1271148ae892627ea26b7d Mon Sep 17 00:00:00 2001 From: Jackson Schuster <36744439+jtschuster@users.noreply.github.com> Date: Thu, 25 Aug 2022 23:21:05 -0500 Subject: [PATCH 05/31] Somewhat working on windows???? --- .vscode/launch.json | 6 ++ mcfly.ps1 | 91 ++++++++--------- src/init.rs | 9 ++ src/interface.rs | 234 +++++++++++++++++++++++++------------------- src/settings.rs | 43 ++++---- 5 files changed, 218 insertions(+), 165 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index f12e6ff9..9425f2e1 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,6 +4,12 @@ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ + { + "type": "lldb", + "request": "attach", + "name": "Attach", + "pid": "${command:pickMyProcess}" // use ${command:pickProcess} to pick other users' processes + }, { "type": "lldb", "request": "launch", diff --git a/mcfly.ps1 b/mcfly.ps1 index 5edf75cf..22a3ee89 100644 --- a/mcfly.ps1 +++ b/mcfly.ps1 @@ -1,66 +1,59 @@ +#!/usr/bin/env pwsh # Ensure stdin is a tty # Can't -if ($env:__MCFLY_LOADED == "loaded") { - return 0; -} -$env:__MCFLY_LOADED = "loaded"; + if ($env:__MCFLY_LOADED -eq "loadd") { + return ; + } + $env:__MCFLY_LOADED = "loaded"; -$env:HISTFILE = $null -eq $env:HISTFILE ? "$env:APPDATA\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt" : $HISTFILE; + $env:HISTFILE = $null -eq $env:HISTFILE ? "$env:APPDATA\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt" : $env:HISTFILE; -$fileExists = Test-Path -path $env:HISTFILE -if (-not $fileExists) { - Write-Output "McFly: ${env:HISTFILE} does not exist or is not readable. Please fix this or set HISTFILE to something else before using McFly."; - return 1; -} + $fileExists = Test-Path -path $env:HISTFILE + if (-not $fileExists) { + Write-Output "McFly: ${env:HISTFILE} does not exist or is not readable. Please fix this or set HISTFILE to something else before using McFly."; + return 1; + } -# MCFLY_SESSION_ID is used by McFly internally to keep track of the commands from a particular terminal session. + # MCFLY_SESSION_ID is used by McFly internally to keep track of the commands from a particular terminal session. -$MCFLY_SESSION_ID = new-guid -$env:MCFLY_SESSION_ID = $MCFLY_SESSION_ID + $MCFLY_SESSION_ID = new-guid + $env:MCFLY_SESSION_ID = $MCFLY_SESSION_ID -(Get-Command "mcfly.exe" -ErrorAction SilentlyContinue) | Select-Object -ExpandProperty Path | Set-Variable -Name MCFLY_PATH -if ($null -eq $MCFLY_PATH) -{ - Write-output "Cannot find the mcfly binary, please make sure that mcfly is in your path before sourcing mcfly.bash."; - return 1; -} + $MCFLY_PATH = '::MCFLY::' + if (!(Test-Path $MCFLY_PATH)) { + Write-output "Cannot find the mcfly binary, please make sure that mcfly is in your path before sourcing mcfly.ps1."; + return 1; + } -if ($null -eq (Get-Module -Name PSReadLine)){ - Write-Output "Installing PSReadLine for keybindings" - Install-Module PSReadLine -} + if ($null -eq (Get-Module -Name PSReadLine)) { + Write-Output "Installing PSReadLine for keybindings" + Install-Module PSReadLine + } -if ($MCFLY_HISTORY -eq 1) { $env:MCFLY_HISTORY = New-TemporaryFile Get-Content $env:HISTFILE | Select-Object -Last 100 | Set-Content $env:MCFLY_HISTORY -} -function Add-LastCommandToMcFly { - $lastCommand = Get-History -Count 1; - $lastCommandStart = Get-Date -Date $lastCommand.StartExecutionTime -UFormat %s - $MCFLY_PATH add --when $lastCommandStart -} -function global:Invoke-McFly { - $startInfo = New-Object System.Diagnostics.ProcessStartInfo -ArgumentList $MCFLY_PATH -Property @{ - StandardOutputEncoding = [System.Text.Encoding]::UTF8; - RedirectStandardOutput = $true; - RedirectStandardError = $true; - CreateNoWindow = $true; - UseShellExecute = $false; - }; - if ($startInfo.ArgumentList.Add) { - # PowerShell 6+ uses .NET 5+ and supports the ArgumentList property - # which bypasses the need for manually escaping the argument list into - # a command string. - $startInfo.ArgumentList.Add($search); + function Invoke-McFly { + invoke-expression "&$MCFLY_PATH search" | Out-Host + } + function Add-CommandToMcFly { + Param([string]$command) + $lastExit = $LASTEXITCODE + Invoke-Expression "&$MCFLY_PATH add '$line' --exit $LASTEXITCODE" | Out-Host + $LASTEXITCODE = $lastExit } - $process = [System.Diagnostics.Process]::Start($startInfo) -} -function global:prompt { - Add-LastCommandToMcFly -} + Set-PSReadLineOption -AddToHistoryHandler { + Param([string]$line) + Add-CommandToMcFly($line); + return $true + } -Set-PSReadLineKeyHandler -Chord "Ctrl+r" -Function Invoke-McFly \ No newline at end of file + Set-PSReadLineKeyHandler -Chord "Ctrl+r" -ScriptBlock { + $line = $null + $cursor = $null + [Microsoft.PowerShell.PSConsoleReadline]::GetBufferState([ref]$line, [ref]$cursor) + Invoke-Expression "$MCFLY_PATH search $line" | Out-Host + } \ No newline at end of file diff --git a/src/init.rs b/src/init.rs index c554ed5d..de413ad3 100644 --- a/src/init.rs +++ b/src/init.rs @@ -1,3 +1,5 @@ +use std::env; + use super::settings::InitMode; pub struct Init {} @@ -14,6 +16,9 @@ impl Init { InitMode::Fish => { Init::init_fish(); } + InitMode::Powershell => { + Init::init_pwsh(); + } } Self {} } @@ -29,4 +34,8 @@ impl Init { let script = include_str!("../mcfly.fish"); print!("{}", script); } + pub fn init_pwsh() { + let script = include_str!("../mcfly.ps1").replace("::MCFLY::", env::current_exe().unwrap().to_str().unwrap()); + print!("{}", script); + } } diff --git a/src/interface.rs b/src/interface.rs index d63f5c55..c5bfd4ef 100644 --- a/src/interface.rs +++ b/src/interface.rs @@ -1,25 +1,20 @@ - use crate::command_input::{CommandInput, Move}; use crate::history::History; -use crate::fixed_length_grapheme_string::FixedLengthGraphemeString; use crate::history::Command; use crate::history_cleaner; use crate::settings::Settings; use crate::settings::{InterfaceView, KeyScheme}; -use crossterm::cursor; -use crossterm::event::{read, Event, KeyCode, KeyEvent, KeyModifiers}; +use chrono::{Duration, TimeZone, Utc}; +use crossterm::event::{poll, read, Event, KeyCode, KeyEvent, KeyModifiers}; use crossterm::queue; use crossterm::style::{Color, Print, ResetColor, SetBackgroundColor, SetForegroundColor}; use crossterm::terminal; use crossterm::terminal::{Clear, ClearType, EnterAlternateScreen, LeaveAlternateScreen}; +use crossterm::{cursor, execute}; +use humantime::format_duration; use std::io::{stdout, Write}; use std::str::FromStr; -use chrono::{Duration, TimeZone, Utc}; -use humantime::format_duration; - - - pub struct Interface<'a> { history: &'a History, @@ -164,7 +159,7 @@ impl<'a> Interface<'a> { ); let _ = queue!(screen, ResetColor); - screen.flush().unwrap(); + // screen.flush().unwrap(); } fn prompt(&self, screen: &mut W) { @@ -188,13 +183,12 @@ impl<'a> Interface<'a> { let _ = queue!(screen, cursor::Show); - screen.flush().unwrap(); + // screen.flush().unwrap(); } fn results(&mut self, screen: &mut W) { let _ = queue!(screen, cursor::Hide); let _ = queue!(screen, cursor::MoveTo(0, self.result_top_index())); - let _ = queue!(screen, Clear(ClearType::All)); let (width, _height): (u16, u16) = terminal::size().unwrap(); @@ -216,10 +210,25 @@ impl<'a> Interface<'a> { } let command_line_index = self.command_line_index(index as i16); - let _ = queue!(screen, cursor::MoveTo(0, (command_line_index as i16 + self.result_top_index() as i16) as u16)); + let _ = queue!( + screen, + cursor::MoveTo( + 0, + (command_line_index as i16 + self.result_top_index() as i16) as u16 + ) + ); let _ = queue!(screen, SetBackgroundColor(bg)); let _ = queue!(screen, SetForegroundColor(fg)); - Interface::truncate_for_display(screen, command, &self.input.command, width, highlight, fg, self.debug); + let _ = queue!(screen, Clear(ClearType::CurrentLine)); + Interface::truncate_for_display( + screen, + command, + &self.input.command, + width, + highlight, + fg, + self.debug, + ); // let _ = queue!(screen, Print(command)); // let tmp_str = format!("{:width$}", Interface::truncate_for_display( // command, @@ -263,14 +272,20 @@ impl<'a> Interface<'a> { .collect::>() .join(" "); - let _ = queue!(screen, cursor::MoveTo(width - 9, (command_line_index as i16 + self.result_top_index() as i16) as u16)); + let _ = queue!( + screen, + cursor::MoveTo( + width - 9, + (command_line_index as i16 + self.result_top_index() as i16) as u16 + ) + ); let _ = queue!(screen, SetForegroundColor(timing_color)); let tmp_str = format!("{:>9}", duration); let _ = queue!(screen, Print(&tmp_str)); let _ = queue!(screen, SetForegroundColor(fg)); } } - screen.flush().unwrap(); + // screen.flush().unwrap(); } #[allow(unused)] @@ -331,85 +346,96 @@ impl<'a> Interface<'a> { self.delete_requests.push(command.cmd.clone()); } self.build_cache_table(); - self.refresh_matches(); + self.refresh_matches(0); } } - fn refresh_matches(&mut self) { - self.selection = 0; - self.matches = self.history.find_matches( + fn refresh_matches(&mut self, selection: usize) { + self.selection = selection; + for new_match in self.history.find_matches( &self.input.command, self.settings.results as i16, self.settings.fuzzy, &self.settings.result_sort, - ); + ) { + self.matches.insert(0, new_match) + } + self.matches.truncate(self.settings.results.into()); } fn select(&mut self) { - let _ = terminal::enable_raw_mode(); + // let _ = terminal::enable_raw_mode(); let mut screen = stdout(); let _ = queue!(screen, EnterAlternateScreen); let _ = queue!(screen, Clear(ClearType::All)); - self.refresh_matches(); + self.refresh_matches(0); self.results(&mut screen); self.menubar(&mut screen); self.prompt(&mut screen); + screen.flush().unwrap(); + // Synchronizing issue when typing fast - just run the loop a few times without a keystroke to synchronize the input + let mut i = 0; loop { - let event = - read().unwrap_or_else(|e| panic!("McFly error: failed to read input {:?}", &e)); - - if self.menu_mode != MenuMode::Normal { - match event { - Event::Key(KeyEvent { - modifiers: KeyModifiers::CONTROL, - code: - KeyCode::Char('c') - | KeyCode::Char('d') - | KeyCode::Char('g') - | KeyCode::Char('z') - | KeyCode::Char('r'), - }) => { - self.run = false; - self.input.clear(); - break; - } - Event::Key(KeyEvent { - code: KeyCode::Char('y'), - .. - }) => { - self.confirm(true); - } - Event::Key( - KeyEvent { - code: KeyCode::Char('n'), + if poll(std::time::Duration::ZERO).unwrap_or(false) || i > 3 { + let event = + read().unwrap_or_else(|e| panic!("McFly error: failed to read input {:?}", &e)); + + if self.menu_mode != MenuMode::Normal { + match event { + Event::Key(KeyEvent { + modifiers: KeyModifiers::CONTROL, + code: + KeyCode::Char('c') + | KeyCode::Char('d') + | KeyCode::Char('g') + | KeyCode::Char('z') + | KeyCode::Char('r'), + }) => { + self.run = false; + self.input.clear(); + break; + } + Event::Key(KeyEvent { + code: KeyCode::Char('y'), .. + }) => { + self.confirm(true); } - | KeyEvent { - code: KeyCode::Esc, .. - }, - ) => { - self.confirm(false); + Event::Key( + KeyEvent { + code: KeyCode::Char('n'), + .. + } + | KeyEvent { + code: KeyCode::Esc, .. + }, + ) => { + self.confirm(false); + } + _ => {} + }; + } else { + let early_out = match self.settings.key_scheme { + KeyScheme::Emacs => self.select_with_emacs_key_scheme(event), + KeyScheme::Vim => self.select_with_vim_key_scheme(event), + }; + + if early_out { + break; } - _ => {} - }; - } else { - let early_out = match self.settings.key_scheme { - KeyScheme::Emacs => self.select_with_emacs_key_scheme(event), - KeyScheme::Vim => self.select_with_vim_key_scheme(event), - }; - - if early_out { - break; } } + self.refresh_matches(self.selection); self.results(&mut screen); self.menubar(&mut screen); self.prompt(&mut screen); + screen.flush().unwrap(); + i += 1; } let _ = queue!(screen, Clear(ClearType::All)); @@ -473,7 +499,7 @@ impl<'a> Interface<'a> { }, ) => { self.input.delete(Move::BackwardWord); - self.refresh_matches(); + self.refresh_matches(0); } Event::Key(KeyEvent { @@ -518,18 +544,20 @@ impl<'a> Interface<'a> { }, ) => { self.input.delete(Move::Backward); - self.refresh_matches(); - } - Event::Key(KeyEvent { - code: KeyCode::Delete, - .. + self.refresh_matches(0); } - | KeyEvent { - modifiers: KeyModifiers::CONTROL, - code: KeyCode::Char('d') - }) => { + Event::Key( + KeyEvent { + code: KeyCode::Delete, + .. + } + | KeyEvent { + modifiers: KeyModifiers::CONTROL, + code: KeyCode::Char('d'), + }, + ) => { self.input.delete(Move::Forward); - self.refresh_matches(); + self.refresh_matches(0); } Event::Key(KeyEvent { @@ -544,7 +572,7 @@ impl<'a> Interface<'a> { .. }) => { self.input.insert(c); - self.refresh_matches(); + self.refresh_matches(0); } Event::Key(KeyEvent { code: KeyCode::F(2), @@ -570,11 +598,11 @@ impl<'a> Interface<'a> { KeyCode::Char('e') => self.input.move_cursor(Move::EOL), KeyCode::Char('k') => { self.input.delete(Move::EOL); - self.refresh_matches(); + self.refresh_matches(0); } KeyCode::Char('u') => { self.input.delete(Move::BOL); - self.refresh_matches(); + self.refresh_matches(0); } _ => {} }, @@ -587,7 +615,7 @@ impl<'a> Interface<'a> { KeyCode::Char('f') => self.input.move_cursor(Move::ForwardWord), KeyCode::Char('d') => { self.input.delete(Move::ForwardWord); - self.refresh_matches(); + self.refresh_matches(0); } _ => {} }, @@ -676,14 +704,14 @@ impl<'a> Interface<'a> { .. }) => { self.input.delete(Move::Backward); - self.refresh_matches(); + self.refresh_matches(0); } Event::Key(KeyEvent { code: KeyCode::Delete, .. }) => { self.input.delete(Move::Forward); - self.refresh_matches(); + self.refresh_matches(0); } Event::Key(KeyEvent { code: KeyCode::Home, @@ -697,7 +725,7 @@ impl<'a> Interface<'a> { .. }) => { self.input.insert(c); - self.refresh_matches(); + self.refresh_matches(0); } Event::Key(KeyEvent { code: KeyCode::F(2), @@ -814,14 +842,14 @@ impl<'a> Interface<'a> { .. }) => { self.input.delete(Move::Backward); - self.refresh_matches(); + self.refresh_matches(0); } Event::Key(KeyEvent { code: KeyCode::Delete | KeyCode::Char('x'), .. }) => { self.input.delete(Move::Forward); - self.refresh_matches(); + self.refresh_matches(0); } Event::Key(KeyEvent { code: KeyCode::Home, @@ -838,7 +866,7 @@ impl<'a> Interface<'a> { if !self.matches.is_empty() { if self.settings.delete_without_confirm { self.delete_selection(); - }else{ + } else { self.menu_mode = MenuMode::ConfirmDelete; } } @@ -854,13 +882,13 @@ impl<'a> Interface<'a> { screen: &mut Write, command: &Command, search: &str, - width: u16, + _width: u16, highlighted_text_color: Color, text_color: Color, debug: bool, ) -> String { let mut prev: usize = 0; - let debug_space = if debug { 90 } else { 0 }; + let _debug_space = if debug { 90 } else { 0 }; // let max_grapheme_length = if width > debug_space { // width - debug_space - 9 // } else { @@ -890,13 +918,25 @@ impl<'a> Interface<'a> { let _ = queue!(screen, Print(" ")); let _ = queue!(screen, SetForegroundColor(Color::Blue)); let _ = queue!(screen, Print(format!("rnk: {:.*} ", 2, command.rank))); - let _ = queue!(screen, Print(format!("age: {:.*} ", 2, command.features.age_factor))); - let _ = queue!(screen, Print(format!("lng: {:.*} ", 2, command.features.length_factor))); - let _ = queue!(screen, Print(format!("ext: {:.*} ", 0, command.features.exit_factor))); - let _ = queue!(screen, Print(format!( - "r_ext: {:.*} ", - 0, command.features.recent_failure_factor - ))); + let _ = queue!( + screen, + Print(format!("age: {:.*} ", 2, command.features.age_factor)) + ); + let _ = queue!( + screen, + Print(format!("lng: {:.*} ", 2, command.features.length_factor)) + ); + let _ = queue!( + screen, + Print(format!("ext: {:.*} ", 0, command.features.exit_factor)) + ); + let _ = queue!( + screen, + Print(format!( + "r_ext: {:.*} ", + 0, command.features.recent_failure_factor + )) + ); // out.push_grapheme_str(format!("dir: {:.*} ", 3, command.features.dir_factor)); // out.push_grapheme_str(format!( // "s_dir: {:.*} ", @@ -972,7 +1012,3 @@ impl<'a> Interface<'a> { // Ctrl('s') => forward history search // Ctrl('t') => transpose characters // Ctrl('q') | Ctrl('v') => quoted insert - - - - diff --git a/src/settings.rs b/src/settings.rs index 2ec09a4e..bc0f4ac7 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -35,6 +35,7 @@ pub enum InitMode { Bash, Zsh, Fish, + Powershell, } #[derive(Debug, Serialize, Deserialize, PartialEq)] @@ -276,8 +277,8 @@ impl Settings { .subcommand(SubCommand::with_name("init") .about("Prints the shell code used to execute mcfly") .arg(Arg::with_name("shell") - .help("Shell to init — one of bash, zsh, or fish") - .possible_values(&["bash", "zsh", "fish"]) + .help("Shell to init — one of bash, zsh, fish, or powershell") + .possible_values(&["bash", "zsh", "fish", "powershell"]) .required(true)) ) .get_matches(); @@ -407,12 +408,16 @@ impl Settings { if let Some(dir) = add_matches.value_of("directory") { settings.dir = dir.to_string(); } else { - settings.dir = env::var("PWD").unwrap_or_else(|err| { + settings.dir = env::current_dir().unwrap_or_else(|err| { panic!( "McFly error: Unable to determine current directory ({})", err ) - }); + }).to_str().to_owned().unwrap_or_else(|| { + panic!( + "McFly error: Unable to determine current directory" + ) + }).to_string(); } if let Some(old_dir) = add_matches.value_of("old_directory") { @@ -476,19 +481,20 @@ impl Settings { if let Some(values) = search_matches.values_of("command") { settings.command = values.collect::>().join(" "); } else { - settings.command = shell_history::last_history_line( - &settings.mcfly_history, - settings.history_format, - ) - .unwrap_or_else(String::new) - .trim_start_matches("#mcfly: ") - .trim_start_matches("#mcfly:") - .to_string(); - shell_history::delete_last_history_entry_if_search( - &settings.mcfly_history, - settings.history_format, - settings.debug, - ); + settings.command = "".to_string(); + // shell_history::last_history_line( + // &settings.mcfly_history, + // settings.history_format, + // ) + // .unwrap_or_else(String::new) + // .trim_start_matches("#mcfly: ") + // .trim_start_matches("#mcfly:") + // .to_string(); + // shell_history::delete_last_history_entry_if_search( + // &settings.mcfly_history, + // settings.history_format, + // settings.debug, + // ); } } @@ -523,6 +529,9 @@ impl Settings { "fish" => { settings.init_mode = InitMode::Fish; } + "powershell" => { + settings.init_mode = InitMode::Powershell; + } _ => unreachable!(), } } From e61b21c3f715caa2f56826875e82ca71c43ad8c7 Mon Sep 17 00:00:00 2001 From: Jackson Schuster <36744439+jtschuster@users.noreply.github.com> Date: Sun, 28 Aug 2022 00:07:46 -0500 Subject: [PATCH 06/31] Working on windows reliably --- Cargo.lock | 19 ++++++++ Cargo.toml | 1 + mcfly.ps1 | 89 ++++++++++++++++++++++++++-------- src/fake_typer.rs | 10 +++- src/interface.rs | 99 ++++++++++++++++++-------------------- src/main.rs | 3 +- src/path_update_helpers.rs | 63 ++---------------------- 7 files changed, 150 insertions(+), 134 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f537be95..91890dd8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -573,6 +573,7 @@ dependencies = [ "humantime", "itertools", "libc", + "path-absolutize", "rand", "regex", "relative-path", @@ -730,6 +731,24 @@ dependencies = [ "winapi", ] +[[package]] +name = "path-absolutize" +version = "3.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3de4b40bd9736640f14c438304c09538159802388febb02c8abaae0846c1f13" +dependencies = [ + "path-dedot", +] + +[[package]] +name = "path-dedot" +version = "3.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d611d5291372b3738a34ebf0d1f849e58b1dcc1101032f76a346eaa1f8ddbb5b" +dependencies = [ + "once_cell", +] + [[package]] name = "pkg-config" version = "0.3.19" diff --git a/Cargo.toml b/Cargo.toml index bd2b35c4..3c211d18 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,6 +36,7 @@ serde = { version = "1.0", features = ["derive"] } shellexpand = "2.0" unicode-segmentation = "1.6" autopilot = "0.4.0" +path-absolutize = "3.0.13" [dependencies.rusqlite] version = "0.15.0" diff --git a/mcfly.ps1 b/mcfly.ps1 index 22a3ee89..39da939b 100644 --- a/mcfly.ps1 +++ b/mcfly.ps1 @@ -3,12 +3,24 @@ # Ensure stdin is a tty # Can't - if ($env:__MCFLY_LOADED -eq "loadd") { +$null = New-Module starship { + if ($env:__MCFLY_LOADED -eq "loaded") { return ; } $env:__MCFLY_LOADED = "loaded"; - $env:HISTFILE = $null -eq $env:HISTFILE ? "$env:APPDATA\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt" : $env:HISTFILE; + # We need PSReadLine for a number of capabilities + if ($null -eq (Get-Module -Name PSReadLine)) { + Write-Output "Installing PSReadLine for keybindings" + Install-Module PSReadLine + } + + # Get history file and make a dummy file for psreadline (hopefully after it has loaded the real history file to its in memory history) + $env:HISTFILE = $null -eq $env:HISTFILE ? (Get-PSReadLineOption).HistorySavePath : $env:HISTFILE; + $_PSREADLINEHISTORY = (Get-PSReadLineOption).HistorySavePath + $psreadline_dummy = New-TemporaryFile + Set-PSReadLineOption -HistorySavePath $psreadline_dummy.FullName + $fileExists = Test-Path -path $env:HISTFILE if (-not $fileExists) { @@ -21,33 +33,63 @@ $MCFLY_SESSION_ID = new-guid $env:MCFLY_SESSION_ID = $MCFLY_SESSION_ID - $MCFLY_PATH = '::MCFLY::' - if (!(Test-Path $MCFLY_PATH)) { - Write-output "Cannot find the mcfly binary, please make sure that mcfly is in your path before sourcing mcfly.ps1."; - return 1; - } - - if ($null -eq (Get-Module -Name PSReadLine)) { - Write-Output "Installing PSReadLine for keybindings" - Install-Module PSReadLine - } - $env:MCFLY_HISTORY = New-TemporaryFile Get-Content $env:HISTFILE | Select-Object -Last 100 | Set-Content $env:MCFLY_HISTORY + <# +.SYNOPSIS +Cmdlet to run McFly + +.PARAMETER CommandToComplete +The command to complete + +.EXAMPLE +Invoke-McFly -CommandToComplete "cargo bu" +#> function Invoke-McFly { - invoke-expression "&$MCFLY_PATH search" | Out-Host + Param([string]$CommandToComplete) + $lastExitTmp = $LASTEXITCODE + Start-Process -FilePath '::MCFLY::' -ArgumentList "search", "$CommandToComplete" -NoNewWindow -Wait + $LASTEXITCODE = $lastExitTmp } + + <# +.SYNOPSIS +Add a command to McFly's history. + +.PARAMETER Command +The string of the command to add to McFly's history + +.PARAMETER ExitCode +The exit code of the command to add + +.EXAMPLE +Add-CommandToMcFly -Command "cargo build" +#> function Add-CommandToMcFly { - Param([string]$command) - $lastExit = $LASTEXITCODE - Invoke-Expression "&$MCFLY_PATH add '$line' --exit $LASTEXITCODE" | Out-Host - $LASTEXITCODE = $lastExit + Param([string]$Command) + Param([int]$ExitCode) + $ExitCode = $ExitCode ?? 0; + Write-Host "Adding Command: $command" + Start-Process -FilePath '::MCFLY::' -ArgumentList add, $command, --exit, $ExitCode -NoNewWindow | Out-Host } + # We need to make sure we call out AddToHistoryHandler right after each command is called + Set-PSReadLineOption -HistorySaveStyle SaveIncrementally + + Set-PSReadLineOption -PredictionSource HistoryAndPlugin + Set-PSReadLineOption -AddToHistoryHandler { Param([string]$line) - Add-CommandToMcFly($line); + # save the exit code to restore in case the program depends on it + $lastExitTmp = $LASTEXITCODE + $line = $line.Trim(); + # PSReadLine executes this before the command even runs, so we don't know its exit code - assume 0 + Add-CommandToMcFly -Command $line -ExitCode 0 + # Add the command to PSReadLine's real history file + Out-File -FilePath $_PSREADLINEHISTORY -Append -InputObject $line + $LASTEXITCODE = $lastExitTmp + # Tell PSReadLine to save the command to their in-memory history (and also the dummy file) return $true } @@ -55,5 +97,10 @@ $line = $null $cursor = $null [Microsoft.PowerShell.PSConsoleReadline]::GetBufferState([ref]$line, [ref]$cursor) - Invoke-Expression "$MCFLY_PATH search $line" | Out-Host - } \ No newline at end of file + Invoke-McFly -CommandToComplete $line + } + Export-ModuleMember -Function @( + "Invoke-McFly" + "Add-LastCommandToMcFly" + ) +} \ No newline at end of file diff --git a/src/fake_typer.rs b/src/fake_typer.rs index 664f336b..689ee514 100644 --- a/src/fake_typer.rs +++ b/src/fake_typer.rs @@ -12,7 +12,15 @@ pub fn use_tiocsti(string: &str) { } } } + #[cfg(windows)] pub fn use_tiocsti(string: &str) { - autopilot::key::type_string(string, &[], 0.0, 0.0) + autopilot::key::type_string(string, &[], 0.0, 0.0); +} + +pub fn delete_chars(n : usize) +{ + for _ in 0..n { + autopilot::key::tap(&autopilot::key::Code(autopilot::key::KeyCode::Backspace), &[], 0, 0); + } } diff --git a/src/interface.rs b/src/interface.rs index c5bfd4ef..8c5aa377 100644 --- a/src/interface.rs +++ b/src/interface.rs @@ -180,10 +180,11 @@ impl<'a> Interface<'a> { } else { let _ = queue!(screen, cursor::DisableBlinking); } + let _ = queue!(screen, cursor::EnableBlinking); let _ = queue!(screen, cursor::Show); - // screen.flush().unwrap(); + screen.flush().unwrap(); } fn results(&mut self, screen: &mut W) { @@ -352,19 +353,16 @@ impl<'a> Interface<'a> { fn refresh_matches(&mut self, selection: usize) { self.selection = selection; - for new_match in self.history.find_matches( + self.matches = self.history.find_matches( &self.input.command, self.settings.results as i16, self.settings.fuzzy, &self.settings.result_sort, - ) { - self.matches.insert(0, new_match) - } - self.matches.truncate(self.settings.results.into()); + ); } fn select(&mut self) { - // let _ = terminal::enable_raw_mode(); + let _ = terminal::enable_raw_mode(); let mut screen = stdout(); @@ -380,53 +378,51 @@ impl<'a> Interface<'a> { // Synchronizing issue when typing fast - just run the loop a few times without a keystroke to synchronize the input let mut i = 0; loop { - if poll(std::time::Duration::ZERO).unwrap_or(false) || i > 3 { - let event = - read().unwrap_or_else(|e| panic!("McFly error: failed to read input {:?}", &e)); - - if self.menu_mode != MenuMode::Normal { - match event { - Event::Key(KeyEvent { - modifiers: KeyModifiers::CONTROL, - code: - KeyCode::Char('c') - | KeyCode::Char('d') - | KeyCode::Char('g') - | KeyCode::Char('z') - | KeyCode::Char('r'), - }) => { - self.run = false; - self.input.clear(); - break; - } - Event::Key(KeyEvent { - code: KeyCode::Char('y'), + let event = + read().unwrap_or_else(|e| panic!("McFly error: failed to read input {:?}", &e)); + + if self.menu_mode != MenuMode::Normal { + match event { + Event::Key(KeyEvent { + modifiers: KeyModifiers::CONTROL, + code: + KeyCode::Char('c') + | KeyCode::Char('d') + | KeyCode::Char('g') + | KeyCode::Char('z') + | KeyCode::Char('r'), + }) => { + self.run = false; + self.input.clear(); + break; + } + Event::Key(KeyEvent { + code: KeyCode::Char('y'), + .. + }) => { + self.confirm(true); + } + Event::Key( + KeyEvent { + code: KeyCode::Char('n'), .. - }) => { - self.confirm(true); - } - Event::Key( - KeyEvent { - code: KeyCode::Char('n'), - .. - } - | KeyEvent { - code: KeyCode::Esc, .. - }, - ) => { - self.confirm(false); } - _ => {} - }; - } else { - let early_out = match self.settings.key_scheme { - KeyScheme::Emacs => self.select_with_emacs_key_scheme(event), - KeyScheme::Vim => self.select_with_vim_key_scheme(event), - }; - - if early_out { - break; + | KeyEvent { + code: KeyCode::Esc, .. + }, + ) => { + self.confirm(false); } + _ => {} + }; + } else { + let early_out = match self.settings.key_scheme { + KeyScheme::Emacs => self.select_with_emacs_key_scheme(event), + KeyScheme::Vim => self.select_with_vim_key_scheme(event), + }; + + if early_out { + break; } } @@ -435,6 +431,7 @@ impl<'a> Interface<'a> { self.menubar(&mut screen); self.prompt(&mut screen); screen.flush().unwrap(); + screen.flush().unwrap(); i += 1; } diff --git a/src/main.rs b/src/main.rs index 3c9c7978..7625407b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -73,10 +73,11 @@ fn handle_search(settings: &Settings) { fs::write(path, &out) .unwrap_or_else(|err| panic!("McFly error: unable to write to {}: {}", path, err)); } else { + fake_typer::delete_chars(settings.command.chars().count()); fake_typer::use_tiocsti(&cmd); if result.run { - fake_typer::use_tiocsti(&"\n".to_string()); + fake_typer::use_tiocsti( &"\n".to_string()); } } } diff --git a/src/path_update_helpers.rs b/src/path_update_helpers.rs index 8e441b7c..fe9305f1 100644 --- a/src/path_update_helpers.rs +++ b/src/path_update_helpers.rs @@ -1,34 +1,9 @@ -use relative_path::RelativePath; -use std::env; use std::path::Path; use unicode_segmentation::UnicodeSegmentation; +use path_absolutize::*; pub fn normalize_path(incoming_path: &str) -> String { - let expanded_path = shellexpand::tilde(incoming_path); - - let current_dir = env::var("PWD").unwrap_or_else(|err| { - panic!( - "McFly error: Unable to determine current directory ({})", - err - ) - }); - let current_dir_path = Path::new(¤t_dir); - - let path_buf = if expanded_path.starts_with('/') { - RelativePath::new(&expanded_path.into_owned()) - .normalize() - .to_path("/") - } else { - let to_current_dir = RelativePath::new(&expanded_path).to_path(current_dir_path); - RelativePath::new(to_current_dir.to_str().unwrap()) - .normalize() - .to_path("/") - }; - - path_buf - .to_str() - .unwrap_or_else(|| panic!("McFly error: Path must be a valid UTF8 string")) - .to_string() + return Path::new(incoming_path).absolutize_from(std::env::current_dir().unwrap().as_path()).unwrap().to_str().unwrap().to_string(); } pub fn parse_mv_command(command: &str) -> Vec { @@ -108,39 +83,7 @@ mod tests { use super::{normalize_path, parse_mv_command}; use std::env; use std::path::PathBuf; - - #[test] - fn normalize_path_works_absolute_paths() { - assert_eq!(normalize_path("/foo/bar/baz"), String::from("/foo/bar/baz")); - assert_eq!(normalize_path("/"), String::from("/")); - assert_eq!(normalize_path("////"), String::from("/")); - } - - #[test] - fn normalize_path_works_with_tilda() { - assert_eq!(normalize_path("~/"), env::var("HOME").unwrap()); - assert_eq!( - normalize_path("~/foo"), - PathBuf::from(env::var("HOME").unwrap()) - .join("foo") - .to_string_lossy() - ); - } - - #[test] - fn normalize_path_works_with_double_dots() { - assert_eq!(normalize_path("/foo/bar/../baz"), String::from("/foo/baz")); - assert_eq!(normalize_path("/foo/bar/../../baz"), String::from("/baz")); - assert_eq!(normalize_path("/foo/bar/../../"), String::from("/")); - assert_eq!(normalize_path("/foo/bar/../.."), String::from("/")); - assert_eq!( - normalize_path("~/foo/bar/../baz"), - PathBuf::from(env::var("HOME").unwrap()) - .join("foo/baz") - .to_string_lossy() - ); - assert_eq!(normalize_path("~/foo/bar/../.."), env::var("HOME").unwrap()); - } + use std::path::Path; #[test] fn parse_mv_command_works_in_the_basic_case() { From 74ac425b37df2dd68b174fca2e784a0700b756a1 Mon Sep 17 00:00:00 2001 From: Jackson Schuster <36744439+jtschuster@users.noreply.github.com> Date: Thu, 1 Sep 2022 17:40:10 -0500 Subject: [PATCH 07/31] wip --- mcfly.ps1 | 68 ++++++++++++++++++++++++++++++----------------------- src/main.rs | 2 +- 2 files changed, 40 insertions(+), 30 deletions(-) diff --git a/mcfly.ps1 b/mcfly.ps1 index 39da939b..f36c0ee7 100644 --- a/mcfly.ps1 +++ b/mcfly.ps1 @@ -3,7 +3,7 @@ # Ensure stdin is a tty # Can't -$null = New-Module starship { +$null = New-Module mcfly { if ($env:__MCFLY_LOADED -eq "loaded") { return ; } @@ -11,7 +11,7 @@ $null = New-Module starship { # We need PSReadLine for a number of capabilities if ($null -eq (Get-Module -Name PSReadLine)) { - Write-Output "Installing PSReadLine for keybindings" + Write-Output "Installing PSReadLine as McFly dependency" Install-Module PSReadLine } @@ -37,15 +37,15 @@ $null = New-Module starship { Get-Content $env:HISTFILE | Select-Object -Last 100 | Set-Content $env:MCFLY_HISTORY <# -.SYNOPSIS -Cmdlet to run McFly + .SYNOPSIS + Cmdlet to run McFly -.PARAMETER CommandToComplete -The command to complete + .PARAMETER CommandToComplete + The command to complete -.EXAMPLE -Invoke-McFly -CommandToComplete "cargo bu" -#> + .EXAMPLE + Invoke-McFly -CommandToComplete "cargo bu" + #> function Invoke-McFly { Param([string]$CommandToComplete) $lastExitTmp = $LASTEXITCODE @@ -54,24 +54,27 @@ Invoke-McFly -CommandToComplete "cargo bu" } <# -.SYNOPSIS -Add a command to McFly's history. + .SYNOPSIS + Add a command to McFly's history. -.PARAMETER Command -The string of the command to add to McFly's history + .PARAMETER Command + The string of the command to add to McFly's history -.PARAMETER ExitCode -The exit code of the command to add + .PARAMETER ExitCode + The exit code of the command to add -.EXAMPLE -Add-CommandToMcFly -Command "cargo build" -#> + .EXAMPLE + Add-CommandToMcFly -Command "cargo build" + #> function Add-CommandToMcFly { - Param([string]$Command) - Param([int]$ExitCode) + Param ( + [string] $Command, + [int] $ExitCode + ) $ExitCode = $ExitCode ?? 0; - Write-Host "Adding Command: $command" - Start-Process -FilePath '::MCFLY::' -ArgumentList add, $command, --exit, $ExitCode -NoNewWindow | Out-Host + $Command | Out-File -FilePath $env:MCFLY_HISTORY -Append + write-host "Adding Command" + Start-Process -FilePath '::MCFLY::' -ArgumentList add, --exit, $ExitCode, --append-to-histfile -NoNewWindow | Write-Host } # We need to make sure we call out AddToHistoryHandler right after each command is called @@ -79,15 +82,22 @@ Add-CommandToMcFly -Command "cargo build" Set-PSReadLineOption -PredictionSource HistoryAndPlugin + $historyHandler = { + Param([string]$Command) + $lastExitTmp = $LASTEXITCODE + $Command = $Command.Trim(); + # PSReadLine executes this before the command even runs, so we don't know its exit code - assume 0 + Add-CommandToMcFly -Command $Command -ExitCode 0 + $LASTEXITCODE = $lastExitTmp + # Tell PSReadLine to save the command to their in-memory history (and also the dummy file) + return $true + } Set-PSReadLineOption -AddToHistoryHandler { - Param([string]$line) - # save the exit code to restore in case the program depends on it + Param([string]$Command) $lastExitTmp = $LASTEXITCODE - $line = $line.Trim(); + $Command = $Command.Trim(); # PSReadLine executes this before the command even runs, so we don't know its exit code - assume 0 - Add-CommandToMcFly -Command $line -ExitCode 0 - # Add the command to PSReadLine's real history file - Out-File -FilePath $_PSREADLINEHISTORY -Append -InputObject $line + Add-CommandToMcFly -Command $Command -ExitCode 0 $LASTEXITCODE = $lastExitTmp # Tell PSReadLine to save the command to their in-memory history (and also the dummy file) return $true @@ -101,6 +111,6 @@ Add-CommandToMcFly -Command "cargo build" } Export-ModuleMember -Function @( "Invoke-McFly" - "Add-LastCommandToMcFly" + "Add-CommandToMcFly" ) } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 7625407b..66b3352d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -77,7 +77,7 @@ fn handle_search(settings: &Settings) { fake_typer::use_tiocsti(&cmd); if result.run { - fake_typer::use_tiocsti( &"\n".to_string()); + // fake_typer::use_tiocsti( &"\n".to_string()); } } } From 5dc17fe4fef4ee8159abcc1f0a0c1afbb3a81375 Mon Sep 17 00:00:00 2001 From: Jackson Schuster <36744439+jtschuster@users.noreply.github.com> Date: Thu, 1 Sep 2022 18:19:48 -0500 Subject: [PATCH 08/31] wip --- Cargo.toml | 1 - mcfly.ps1 | 1 + src/fake_typer.rs | 1 - src/interface.rs | 45 ++++++++++++++++++-------------------- src/path_update_helpers.rs | 6 ----- src/settings.rs | 8 +++---- 6 files changed, 26 insertions(+), 36 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index eab60a18..88f89c77 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,7 +34,6 @@ libc = "0.2" rand = "0.8" regex = "1" serde = { version = "1.0", features = ["derive"] } -unicode-segmentation = "1.6" autopilot = "0.4.0" path-absolutize = "3.0.13" relative-path = "1.7" diff --git a/mcfly.ps1 b/mcfly.ps1 index f36c0ee7..08a497a3 100644 --- a/mcfly.ps1 +++ b/mcfly.ps1 @@ -107,6 +107,7 @@ $null = New-Module mcfly { $line = $null $cursor = $null [Microsoft.PowerShell.PSConsoleReadline]::GetBufferState([ref]$line, [ref]$cursor) + [Microsoft.PowerShell.PSConsoleReadLine]::DeleteLine Invoke-McFly -CommandToComplete $line } Export-ModuleMember -Function @( diff --git a/src/fake_typer.rs b/src/fake_typer.rs index 61a92613..eae0b3ff 100644 --- a/src/fake_typer.rs +++ b/src/fake_typer.rs @@ -1,5 +1,4 @@ use libc; -use std::convert::TryInto; // Should we be using https://docs.rs/libc/0.2.44/libc/fn.ioctl.html instead? extern "C" { diff --git a/src/interface.rs b/src/interface.rs index 268acb39..91d7c613 100644 --- a/src/interface.rs +++ b/src/interface.rs @@ -6,12 +6,12 @@ use crate::history_cleaner; use crate::settings::{InterfaceView, KeyScheme}; use crate::settings::{ResultSort, Settings}; use chrono::{Duration, TimeZone, Utc}; -use crossterm::event::{poll, read, Event, KeyCode, KeyEvent, KeyModifiers}; +use crossterm::event::{read, Event, KeyCode, KeyEvent, KeyModifiers}; use crossterm::queue; use crossterm::style::{Color, Print, ResetColor, SetBackgroundColor, SetForegroundColor}; use crossterm::terminal; use crossterm::terminal::{Clear, ClearType, EnterAlternateScreen, LeaveAlternateScreen}; -use crossterm::{cursor, execute}; +use crossterm::{cursor}; use humantime::format_duration; use std::io::{stdout, Write}; use std::str::FromStr; @@ -161,7 +161,7 @@ impl<'a> Interface<'a> { fn menubar(&self, screen: &mut W) { let (width, _height): (u16, u16) = terminal::size().unwrap(); - let _ = queue!(screen, cursor::Hide()); + let _ = queue!(screen, cursor::Hide); let _ = queue!(screen, cursor::MoveTo(1, self.info_line_index())); let _ = queue!(screen, cursor::MoveTo(1, self.info_line_index())); let _ = queue!(screen, SetBackgroundColor(self.menu_mode.bg(self))); @@ -363,12 +363,11 @@ impl<'a> Interface<'a> { self.delete_requests.push(command.cmd.clone()); } self.build_cache_table(); - self.refresh_matches(0); + self.refresh_matches(); } } - fn refresh_matches(&mut self, selection: usize) { - self.selection = selection; + fn refresh_matches(&mut self) { self.matches = self.history.find_matches( &self.input.command, self.settings.results as i16, @@ -392,14 +391,13 @@ impl<'a> Interface<'a> { let _ = queue!(screen, EnterAlternateScreen); let _ = queue!(screen, Clear(ClearType::All)); - self.refresh_matches(0); + self.refresh_matches(); self.results(&mut screen); self.menubar(&mut screen); self.prompt(&mut screen); screen.flush().unwrap(); // Synchronizing issue when typing fast - just run the loop a few times without a keystroke to synchronize the input - let mut i = 0; loop { let event = read().unwrap_or_else(|e| panic!("McFly error: failed to read input {:?}", &e)); @@ -449,13 +447,12 @@ impl<'a> Interface<'a> { } } - self.refresh_matches(self.selection); + self.refresh_matches(); self.results(&mut screen); self.menubar(&mut screen); self.prompt(&mut screen); screen.flush().unwrap(); screen.flush().unwrap(); - i += 1; } let _ = queue!(screen, Clear(ClearType::All)); @@ -519,7 +516,7 @@ impl<'a> Interface<'a> { }, ) => { self.input.delete(Move::BackwardWord); - self.refresh_matches(0); + self.refresh_matches(); } Event::Key(KeyEvent { @@ -564,7 +561,7 @@ impl<'a> Interface<'a> { }, ) => { self.input.delete(Move::Backward); - self.refresh_matches(0); + self.refresh_matches(); } Event::Key( KeyEvent { @@ -577,7 +574,7 @@ impl<'a> Interface<'a> { }, ) => { self.input.delete(Move::Forward); - self.refresh_matches(0); + self.refresh_matches(); } Event::Key(KeyEvent { @@ -592,7 +589,7 @@ impl<'a> Interface<'a> { .. }) => { self.input.insert(c); - self.refresh_matches(0); + self.refresh_matches(); } Event::Key(KeyEvent { code: KeyCode::F(1), @@ -625,11 +622,11 @@ impl<'a> Interface<'a> { KeyCode::Char('e') => self.input.move_cursor(Move::EOL), KeyCode::Char('k') => { self.input.delete(Move::EOL); - self.refresh_matches(0); + self.refresh_matches(); } KeyCode::Char('u') => { self.input.delete(Move::BOL); - self.refresh_matches(0); + self.refresh_matches(); } _ => {} }, @@ -642,7 +639,7 @@ impl<'a> Interface<'a> { KeyCode::Char('f') => self.input.move_cursor(Move::ForwardWord), KeyCode::Char('d') => { self.input.delete(Move::ForwardWord); - self.refresh_matches(0); + self.refresh_matches(); } _ => {} }, @@ -731,14 +728,14 @@ impl<'a> Interface<'a> { .. }) => { self.input.delete(Move::Backward); - self.refresh_matches(0); + self.refresh_matches(); } Event::Key(KeyEvent { code: KeyCode::Delete, .. }) => { self.input.delete(Move::Forward); - self.refresh_matches(0); + self.refresh_matches(); } Event::Key(KeyEvent { code: KeyCode::Home, @@ -752,7 +749,7 @@ impl<'a> Interface<'a> { .. }) => { self.input.insert(c); - self.refresh_matches(0); + self.refresh_matches(); } Event::Key(KeyEvent { code: KeyCode::F(1), @@ -876,14 +873,14 @@ impl<'a> Interface<'a> { .. }) => { self.input.delete(Move::Backward); - self.refresh_matches(0); + self.refresh_matches(); } Event::Key(KeyEvent { code: KeyCode::Delete | KeyCode::Char('x'), .. }) => { self.input.delete(Move::Forward); - self.refresh_matches(0); + self.refresh_matches(); } Event::Key(KeyEvent { code: KeyCode::Home, @@ -919,8 +916,8 @@ impl<'a> Interface<'a> { false } - fn truncate_for_display( - screen: &mut Write, + fn truncate_for_display( + screen: &mut T, command: &Command, search: &str, _width: u16, diff --git a/src/path_update_helpers.rs b/src/path_update_helpers.rs index 614c733f..4eeda074 100644 --- a/src/path_update_helpers.rs +++ b/src/path_update_helpers.rs @@ -1,7 +1,4 @@ use std::path::Path; -use relative_path::RelativePath; -use std::env; -use std::path::{Path, PathBuf}; use unicode_segmentation::UnicodeSegmentation; use path_absolutize::*; @@ -84,9 +81,6 @@ pub fn parse_mv_command(command: &str) -> Vec { #[cfg(test)] mod tests { use super::{normalize_path, parse_mv_command}; - use std::env; - use std::path::PathBuf; - use std::path::Path; #[test] fn parse_mv_command_works_in_the_basic_case() { diff --git a/src/settings.rs b/src/settings.rs index c3d746b3..1ceb9401 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -3,7 +3,6 @@ use crate::shell_history; use clap::AppSettings; use clap::{crate_authors, crate_version, value_t}; use clap::{App, Arg, SubCommand}; -use dirs::home_dir; use figment::{ providers::{Format, Serialized, Toml}, Figment, @@ -39,13 +38,13 @@ pub enum InitMode { Powershell, } -#[derive(Debug, PartialEq, Eq)] +#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)] pub enum InterfaceView { Top, Bottom, } -#[derive(Debug, Clone)] +#[derive(Debug, Serialize, Deserialize, Clone)] pub enum ResultSort { Rank, LastRun, @@ -102,6 +101,7 @@ pub struct Settings { pub append_to_histfile: bool, pub refresh_training_cache: bool, pub key_scheme: KeyScheme, + pub lightmode: bool, pub history_format: HistoryFormat, pub limit: Option, pub skip_environment_check: bool, @@ -579,7 +579,7 @@ impl Settings { } pub fn mcfly_config_path() -> PathBuf { - Settings::storage_dir_path().join(PathBuf::from("mcfly.toml")) + Settings::mcfly_dir_in_home().unwrap().join(PathBuf::from("mcfly.toml")) } // Use ~/.mcfly only if it already exists, otherwise create 'mcfly' folder in XDG_DATA_DIR From 9a6afbad4b2ad7ff8910564f7e3b5f47824d169a Mon Sep 17 00:00:00 2001 From: Jackson Schuster <36744439+jtschuster@users.noreply.github.com> Date: Fri, 2 Sep 2022 11:05:29 -0500 Subject: [PATCH 09/31] Add windows path test and update path normalizer --- mcfly.ps1 | 11 - src/fixed_length_grapheme_string.rs | 17 +- src/interface.rs | 863 ++++++++++++++-------------- src/main.rs | 2 +- src/path_update_helpers.rs | 107 +++- 5 files changed, 567 insertions(+), 433 deletions(-) diff --git a/mcfly.ps1 b/mcfly.ps1 index 08a497a3..d25c6244 100644 --- a/mcfly.ps1 +++ b/mcfly.ps1 @@ -73,7 +73,6 @@ $null = New-Module mcfly { ) $ExitCode = $ExitCode ?? 0; $Command | Out-File -FilePath $env:MCFLY_HISTORY -Append - write-host "Adding Command" Start-Process -FilePath '::MCFLY::' -ArgumentList add, --exit, $ExitCode, --append-to-histfile -NoNewWindow | Write-Host } @@ -82,16 +81,6 @@ $null = New-Module mcfly { Set-PSReadLineOption -PredictionSource HistoryAndPlugin - $historyHandler = { - Param([string]$Command) - $lastExitTmp = $LASTEXITCODE - $Command = $Command.Trim(); - # PSReadLine executes this before the command even runs, so we don't know its exit code - assume 0 - Add-CommandToMcFly -Command $Command -ExitCode 0 - $LASTEXITCODE = $lastExitTmp - # Tell PSReadLine to save the command to their in-memory history (and also the dummy file) - return $true - } Set-PSReadLineOption -AddToHistoryHandler { Param([string]$Command) $lastExitTmp = $LASTEXITCODE diff --git a/src/fixed_length_grapheme_string.rs b/src/fixed_length_grapheme_string.rs index 7ee515b3..951d0d3e 100644 --- a/src/fixed_length_grapheme_string.rs +++ b/src/fixed_length_grapheme_string.rs @@ -1,3 +1,5 @@ +use std::{io::{Write}}; + use unicode_segmentation::UnicodeSegmentation; #[derive(Debug)] @@ -7,12 +9,25 @@ pub struct FixedLengthGraphemeString { pub max_grapheme_length: u16, } +impl Write for FixedLengthGraphemeString +{ + fn write(&mut self, buf: &[u8]) -> std::io::Result { + let s = String::from_utf8(buf.to_vec()).unwrap(); + self.push_str(&s); + Ok(s.len()) + } + + fn flush(&mut self) -> std::io::Result<()> { + Ok(()) + } +} + impl FixedLengthGraphemeString { pub fn empty(max_grapheme_length: u16) -> FixedLengthGraphemeString { FixedLengthGraphemeString { string: String::new(), grapheme_length: 0, - max_grapheme_length, + max_grapheme_length: max_grapheme_length, } } diff --git a/src/interface.rs b/src/interface.rs index 91d7c613..42e8e664 100644 --- a/src/interface.rs +++ b/src/interface.rs @@ -1,20 +1,22 @@ use crate::command_input::{CommandInput, Move}; use crate::history::History; +use crate::fixed_length_grapheme_string::FixedLengthGraphemeString; use crate::history::Command; use crate::history_cleaner; use crate::settings::{InterfaceView, KeyScheme}; use crate::settings::{ResultSort, Settings}; use chrono::{Duration, TimeZone, Utc}; +use crossterm::event::KeyCode::Char; use crossterm::event::{read, Event, KeyCode, KeyEvent, KeyModifiers}; -use crossterm::queue; -use crossterm::style::{Color, Print, ResetColor, SetBackgroundColor, SetForegroundColor}; -use crossterm::terminal; -use crossterm::terminal::{Clear, ClearType, EnterAlternateScreen, LeaveAlternateScreen}; -use crossterm::{cursor}; +use crossterm::style::{Color, Print, SetBackgroundColor, SetForegroundColor}; +use crossterm::terminal::{self, LeaveAlternateScreen}; +use crossterm::terminal::{Clear, ClearType, EnterAlternateScreen}; +use crossterm::{cursor, execute, queue}; use humantime::format_duration; use std::io::{stdout, Write}; use std::str::FromStr; +use std::string::String; pub struct Interface<'a> { history: &'a History, @@ -88,15 +90,6 @@ impl MenuMode { } } } - - fn fg(&self, interface: &Interface) -> Color { - match *self { - MenuMode::Normal => Color::from_str(&interface.settings.colors.menu_fg).unwrap(), - MenuMode::ConfirmDelete => { - Color::from_str(&interface.settings.colors.menu_deleting_fg).unwrap() - } - } - } } const PROMPT_LINE_INDEX: u16 = 2; @@ -161,51 +154,61 @@ impl<'a> Interface<'a> { fn menubar(&self, screen: &mut W) { let (width, _height): (u16, u16) = terminal::size().unwrap(); - let _ = queue!(screen, cursor::Hide); - let _ = queue!(screen, cursor::MoveTo(1, self.info_line_index())); - let _ = queue!(screen, cursor::MoveTo(1, self.info_line_index())); - let _ = queue!(screen, SetBackgroundColor(self.menu_mode.bg(self))); - let _ = queue!(screen, SetForegroundColor(self.menu_mode.fg(self))); - let _ = queue!( + queue!( screen, + cursor::Hide, + cursor::MoveTo(0, self.info_line_index()), + Clear(ClearType::CurrentLine), + SetBackgroundColor(self.menu_mode.bg(self)), + SetForegroundColor(Color::White), + cursor::MoveTo(1, self.info_line_index()), Print(format!( "{text:width$}", text = self.menu_mode.text(self), - width = width as usize - )) - ); - let _ = queue!(screen, ResetColor); - + width = width as usize - 1 + )), + SetBackgroundColor(Color::Reset) + ) + .unwrap(); } fn prompt(&self, screen: &mut W) { - let _ = queue!( - screen, - SetForegroundColor(Color::from_str(&self.settings.colors.prompt_fg).unwrap()) - ); - let _ = queue!(screen, cursor::MoveTo(0, self.prompt_line_index())); - let _ = queue!(screen, Clear(ClearType::CurrentLine)); - let _ = queue!(screen, Print(format!("$ {}", self.input))); - let _ = queue!( - screen, - cursor::MoveTo(self.input.cursor as u16 + 2, self.prompt_line_index()) - ); - - if self.in_vim_insert_mode { - let _ = queue!(screen, cursor::EnableBlinking); + let fg = if self.settings.lightmode { + Color::Black } else { - let _ = queue!(screen, cursor::DisableBlinking); - } - let _ = queue!(screen, cursor::EnableBlinking); - - let _ = queue!(screen, cursor::Show); + Color::White + }; + queue!( + screen, + cursor::MoveTo(1, self.prompt_line_index()), + SetForegroundColor(fg), + Clear(ClearType::CurrentLine), + Print(format!("$ {}", self.input)), + cursor::MoveTo(self.input.cursor as u16 + 3, self.prompt_line_index()), + cursor::Show + ) + .unwrap(); + } - screen.flush().unwrap(); + fn debug_cursor(&self, screen: &mut W) { + let result_top_index = self.result_top_index(); + queue!( + screen, + cursor::Hide, + cursor::MoveTo(0, result_top_index + self.settings.results + 1) + ) + .unwrap(); + // screen.flush().unwrap(); } fn results(&mut self, screen: &mut W) { - let _ = queue!(screen, cursor::Hide); - let _ = queue!(screen, cursor::MoveTo(0, self.result_top_index())); + queue!( + screen, + cursor::Hide, + cursor::MoveTo(1, self.result_top_index()), + Clear(ClearType::All) + ) + .unwrap(); let (width, _height): (u16, u16) = terminal::size().unwrap(); @@ -214,51 +217,51 @@ impl<'a> Interface<'a> { } for (index, command) in self.matches.iter().enumerate() { - let mut fg = Color::from_str(&self.settings.colors.fg).unwrap(); + let mut fg = if self.settings.lightmode { + Color::Black + } else { + Color::White + }; + + let mut fg_highlight = if self.settings.lightmode { + Color::Blue + } else { + Color::Green + }; + let mut bg = Color::Reset; - let mut highlight = Color::from_str(&self.settings.colors.highlight).unwrap(); - let mut timing_color = Color::from_str(&self.settings.colors.timing).unwrap(); if index == self.selection { - fg = Color::from_str(&self.settings.colors.cursor_fg).unwrap(); - bg = Color::from_str(&self.settings.colors.cursor_bg).unwrap(); - highlight = Color::from_str(&self.settings.colors.cursor_highlight).unwrap(); - timing_color = Color::from_str(&self.settings.colors.timing).unwrap(); + if self.settings.lightmode { + fg = Color::White; + bg = Color::DarkGrey; + fg_highlight = Color::White; + } else { + fg = Color::Black; + bg = Color::White; + fg_highlight = Color::Green; + } } let command_line_index = self.command_line_index(index as i16); - let _ = queue!( + queue!( screen, cursor::MoveTo( - 0, + 1, (command_line_index as i16 + self.result_top_index() as i16) as u16 - ) - ); - let _ = queue!(screen, SetBackgroundColor(bg)); - let _ = queue!(screen, SetForegroundColor(fg)); - let _ = queue!(screen, Clear(ClearType::CurrentLine)); - Interface::truncate_for_display( - screen, - command, - &self.input.command, - width, - highlight, - fg, - self.debug, - ); - // let _ = queue!(screen, Print(command)); - // let tmp_str = format!("{:width$}", Interface::truncate_for_display( - // command, - // &self.input.command, - // width, - // highlight, - // fg, - // self.debug - // ), width=(width + 10) as usize); - // let _ = queue!( - // screen, - // Print(&tmp_str), - // ); + ), + SetBackgroundColor(bg), + SetForegroundColor(fg), + Print(Interface::truncate_for_display( + command, + &self.input.command, + width, + fg_highlight, + fg, + self.debug + )) + ) + .unwrap(); if command.last_run.is_some() { let duration = &format_duration( @@ -289,27 +292,35 @@ impl<'a> Interface<'a> { .collect::>() .join(" "); - let _ = queue!( + let timing_color = if self.settings.lightmode { + Color::DarkBlue + } else { + Color::Blue + }; + queue!( screen, cursor::MoveTo( width - 9, (command_line_index as i16 + self.result_top_index() as i16) as u16 - ) - ); - let _ = queue!(screen, SetForegroundColor(timing_color)); - let tmp_str = format!("{:>9}", duration); - let _ = queue!(screen, Print(&tmp_str)); - let _ = queue!(screen, SetForegroundColor(fg)); + ), + SetForegroundColor(timing_color), + Print(format!("{:>9}", duration)), + SetForegroundColor(Color::Reset), + SetBackgroundColor(Color::Reset) + ) + .unwrap(); } } - // screen.flush().unwrap(); } #[allow(unused)] fn debug>(&self, screen: &mut W, s: S) { - let _ = queue!(screen, cursor::MoveTo(0, 0)); - let _ = queue!(screen, Clear(ClearType::CurrentLine)); - let _ = queue!(screen, Print(s.into())); + let _ = queue!( + screen, + cursor::MoveTo(0, 0), + Clear(ClearType::CurrentLine), + Print(s.into()) + ); screen.flush().unwrap(); } @@ -368,6 +379,7 @@ impl<'a> Interface<'a> { } fn refresh_matches(&mut self) { + self.selection = 0; self.matches = self.history.find_matches( &self.input.command, self.settings.results as i16, @@ -384,12 +396,9 @@ impl<'a> Interface<'a> { } fn select(&mut self) { - let _ = terminal::enable_raw_mode(); - let mut screen = stdout(); - - let _ = queue!(screen, EnterAlternateScreen); - let _ = queue!(screen, Clear(ClearType::All)); + terminal::enable_raw_mode().unwrap(); + queue!(screen, EnterAlternateScreen, Clear(ClearType::All)).unwrap(); self.refresh_matches(); self.results(&mut screen); @@ -397,211 +406,219 @@ impl<'a> Interface<'a> { self.prompt(&mut screen); screen.flush().unwrap(); - // Synchronizing issue when typing fast - just run the loop a few times without a keystroke to synchronize the input + loop { let event = read().unwrap_or_else(|e| panic!("McFly error: failed to read input {:?}", &e)); + self.debug_cursor(&mut screen); - if self.menu_mode != MenuMode::Normal { - match event { - Event::Key(KeyEvent { - modifiers: KeyModifiers::CONTROL, - code: - KeyCode::Char('c') - | KeyCode::Char('d') - | KeyCode::Char('g') - | KeyCode::Char('z') - | KeyCode::Char('r'), - }) => { - self.run = false; - self.input.clear(); - break; - } - Event::Key(KeyEvent { - code: KeyCode::Char('y'), - .. - }) => { - self.confirm(true); - } - Event::Key( + if let Event::Key(key_event) = event { + if self.menu_mode != MenuMode::Normal { + match key_event { + KeyEvent { + modifiers: KeyModifiers::CONTROL, + code: Char('c') | Char('d') | Char('g') | Char('z') | Char('r'), + } => { + self.run = false; + self.input.clear(); + break; + } KeyEvent { - code: KeyCode::Char('n'), + code: Char('y') | Char('Y'), + .. + } => { + self.confirm(true); + } + KeyEvent { + code: Char('n') | Char('N'), .. } | KeyEvent { code: KeyCode::Esc, .. - }, - ) => { - self.confirm(false); + } => { + self.confirm(false); + } + _ => {} + }; + } else { + let early_out = match self.settings.key_scheme { + KeyScheme::Emacs => self.select_with_emacs_key_scheme(key_event), + KeyScheme::Vim => self.select_with_vim_key_scheme(key_event), + }; + + if early_out { + break; } - _ => {} - }; - } else { - let early_out = match self.settings.key_scheme { - KeyScheme::Emacs => self.select_with_emacs_key_scheme(event), - KeyScheme::Vim => self.select_with_vim_key_scheme(event), - }; - - if early_out { - break; } } - self.refresh_matches(); self.results(&mut screen); self.menubar(&mut screen); self.prompt(&mut screen); screen.flush().unwrap(); - screen.flush().unwrap(); } - let _ = queue!(screen, Clear(ClearType::All)); - let _ = queue!(screen, cursor::Show); - let _ = queue!(screen, LeaveAlternateScreen); - - let _ = terminal::disable_raw_mode(); + queue!( + screen, + Clear(ClearType::All), + cursor::Show, + LeaveAlternateScreen + ) + .unwrap(); } - fn select_with_emacs_key_scheme(&mut self, event: Event) -> bool { + fn select_with_emacs_key_scheme(&mut self, event: KeyEvent) -> bool { match event { - Event::Key( - KeyEvent { - modifiers: KeyModifiers::CONTROL, - code: - KeyCode::Char('c') - | KeyCode::Char('g') - | KeyCode::Char('z') - | KeyCode::Char('r'), - } - | KeyEvent { - code: KeyCode::Esc, .. - }, - ) => { - self.run = false; - self.input.clear(); + KeyEvent { + code: KeyCode::Enter, + .. + } + | KeyEvent { + modifiers: KeyModifiers::CONTROL, + code: Char('j'), + } => { + self.run = true; + self.accept_selection(); return true; } - Event::Key(KeyEvent { + KeyEvent { code: KeyCode::Tab, .. - }) => { + } => { self.run = false; self.accept_selection(); return true; } - Event::Key( - KeyEvent { - code: KeyCode::Enter, - .. - } - | KeyEvent { - modifiers: KeyModifiers::CONTROL, - code: KeyCode::Char('j'), - }, - ) => { - self.run = true; - self.accept_selection(); + KeyEvent { + modifiers: KeyModifiers::CONTROL, + code: Char('c') | Char('g') | Char('z') | Char('r'), + } + | KeyEvent { + code: KeyCode::Esc, .. + } => { + self.run = false; + self.input.clear(); return true; } - Event::Key( - KeyEvent { - modifiers: KeyModifiers::CONTROL, - code: KeyCode::Char('w'), + KeyEvent { + modifiers: KeyModifiers::CONTROL, + code, + } => match code { + Char('b') => self.input.move_cursor(Move::Backward), + Char('f') => self.input.move_cursor(Move::Forward), + Char('a') => self.input.move_cursor(Move::BOL), + Char('e') => self.input.move_cursor(Move::EOL), + Char('v') => self.debug = !self.debug, + Char('k') => { + self.input.delete(Move::EOL); + self.refresh_matches(); } - | KeyEvent { - modifiers: KeyModifiers::ALT, - code: KeyCode::Char('\x08') | KeyCode::Char('\x7f'), - }, - ) => { + Char('u') => { + self.input.delete(Move::BOL); + self.refresh_matches(); + } + Char('w') => { + self.input.delete(Move::BackwardWord); + self.refresh_matches(); + } + Char('p') => self.move_selection(MoveSelection::Up), + Char('n') => self.move_selection(MoveSelection::Down), + Char('h') => { + self.input.delete(Move::Backward); + self.refresh_matches(); + } + Char('d') => { + self.input.delete(Move::Forward); + self.refresh_matches(); + } + _ => {} + }, + + KeyEvent { + modifiers: KeyModifiers::ALT, + code: Char('\x08') | Char('\x7f'), + } => { self.input.delete(Move::BackwardWord); self.refresh_matches(); } - Event::Key(KeyEvent { + KeyEvent { + modifiers: KeyModifiers::ALT, + code, + } => match code { + Char('b') => self.input.move_cursor(Move::BackwardWord), + Char('f') => self.input.move_cursor(Move::ForwardWord), + Char('d') => { + self.input.delete(Move::ForwardWord); + self.refresh_matches(); + } + _ => {} + }, + + KeyEvent { code: KeyCode::Left, .. - }) => self.input.move_cursor(Move::Backward), - Event::Key(KeyEvent { + } => self.input.move_cursor(Move::Backward), + + KeyEvent { code: KeyCode::Right, .. - }) => self.input.move_cursor(Move::Forward), + } => self.input.move_cursor(Move::Forward), - Event::Key( - KeyEvent { - code: KeyCode::Up | KeyCode::PageUp, - .. - } - | KeyEvent { - modifiers: KeyModifiers::CONTROL, - code: KeyCode::Char('p'), - }, - ) => self.move_selection(MoveSelection::Up), + KeyEvent { + code: KeyCode::Up | KeyCode::PageUp, + .. + } => self.move_selection(MoveSelection::Up), - Event::Key( - KeyEvent { - code: KeyCode::Down | KeyCode::PageDown, - .. - } - | KeyEvent { - modifiers: KeyModifiers::CONTROL, - code: KeyCode::Char('n'), - }, - ) => self.move_selection(MoveSelection::Down), + KeyEvent { + code: KeyCode::Down | KeyCode::PageDown, + .. + } => self.move_selection(MoveSelection::Down), - Event::Key( - KeyEvent { - code: KeyCode::Backspace, - .. - } - | KeyEvent { - modifiers: KeyModifiers::CONTROL, - code: KeyCode::Char('h'), - }, - ) => { + KeyEvent { + code: KeyCode::Backspace, + .. + } => { self.input.delete(Move::Backward); self.refresh_matches(); } - Event::Key( - KeyEvent { - code: KeyCode::Delete, - .. - } - | KeyEvent { - modifiers: KeyModifiers::CONTROL, - code: KeyCode::Char('d'), - }, - ) => { + + KeyEvent { + code: KeyCode::Delete, + .. + } => { self.input.delete(Move::Forward); self.refresh_matches(); } - Event::Key(KeyEvent { + KeyEvent { code: KeyCode::Home, .. - }) => self.input.move_cursor(Move::BOL), - Event::Key(KeyEvent { + } => self.input.move_cursor(Move::BOL), + + KeyEvent { code: KeyCode::End, .. - }) => self.input.move_cursor(Move::EOL), - Event::Key(KeyEvent { - code: KeyCode::Char(c), - .. - }) => { + } => self.input.move_cursor(Move::EOL), + + KeyEvent { code: Char(c), .. } => { self.input.insert(c); self.refresh_matches(); } - Event::Key(KeyEvent { + + KeyEvent { code: KeyCode::F(1), .. - }) => { + } => { self.switch_result_sort(); self.refresh_matches(); } - Event::Key(KeyEvent { + + KeyEvent { code: KeyCode::F(2), .. - }) => { + } => { if !self.matches.is_empty() { if self.settings.delete_without_confirm { self.delete_selection(); @@ -611,157 +628,111 @@ impl<'a> Interface<'a> { } } - Event::Key(KeyEvent { - modifiers: KeyModifiers::CONTROL, - code, - }) => match code { - KeyCode::Char('v') => self.debug = !self.debug, - KeyCode::Char('b') => self.input.move_cursor(Move::Backward), - KeyCode::Char('f') => self.input.move_cursor(Move::Forward), - KeyCode::Char('a') => self.input.move_cursor(Move::BOL), - KeyCode::Char('e') => self.input.move_cursor(Move::EOL), - KeyCode::Char('k') => { - self.input.delete(Move::EOL); - self.refresh_matches(); - } - KeyCode::Char('u') => { - self.input.delete(Move::BOL); - self.refresh_matches(); - } - _ => {} - }, - - Event::Key(KeyEvent { - modifiers: KeyModifiers::ALT, - code, - }) => match code { - KeyCode::Char('b') => self.input.move_cursor(Move::BackwardWord), - KeyCode::Char('f') => self.input.move_cursor(Move::ForwardWord), - KeyCode::Char('d') => { - self.input.delete(Move::ForwardWord); - self.refresh_matches(); - } - _ => {} - }, - _ => {} } false } - fn select_with_vim_key_scheme(&mut self, event: Event) -> bool { + fn select_with_vim_key_scheme(&mut self, event: KeyEvent) -> bool { if self.in_vim_insert_mode { match event { - Event::Key(KeyEvent { + KeyEvent { code: KeyCode::Tab, .. - }) => { + } => { self.run = false; self.accept_selection(); return true; } - Event::Key( - KeyEvent { - code: KeyCode::Enter, - .. - } - | KeyEvent { - modifiers: KeyModifiers::CONTROL, - code: KeyCode::Char('j'), - }, - ) => { + KeyEvent { + code: KeyCode::Enter, + .. + } + | KeyEvent { + modifiers: KeyModifiers::CONTROL, + code: Char('j'), + } => { self.run = true; self.accept_selection(); return true; } - Event::Key(KeyEvent { + KeyEvent { modifiers: KeyModifiers::CONTROL, - code: - KeyCode::Char('c') - | KeyCode::Char('g') - | KeyCode::Char('z') - | KeyCode::Char('r'), - }) => { + code: Char('c') | Char('g') | Char('z') | Char('r'), + } => { self.run = false; self.input.clear(); return true; } - Event::Key(KeyEvent { + KeyEvent { code: KeyCode::Left, .. - }) => self.input.move_cursor(Move::Backward), - Event::Key(KeyEvent { + } => self.input.move_cursor(Move::Backward), + KeyEvent { code: KeyCode::Right, .. - }) => self.input.move_cursor(Move::Forward), + } => self.input.move_cursor(Move::Forward), - Event::Key( - KeyEvent { - code: KeyCode::Up | KeyCode::PageUp, - .. - } - | KeyEvent { - modifiers: KeyModifiers::CONTROL, - code: KeyCode::Char('u') | KeyCode::Char('p'), - }, - ) => self.move_selection(MoveSelection::Up), - - Event::Key( - KeyEvent { - code: KeyCode::Down | KeyCode::PageDown, - .. - } - | KeyEvent { - modifiers: KeyModifiers::CONTROL, - code: KeyCode::Char('d') | KeyCode::Char('n'), - }, - ) => self.move_selection(MoveSelection::Down), + KeyEvent { + code: KeyCode::Up | KeyCode::PageUp, + .. + } + | KeyEvent { + modifiers: KeyModifiers::CONTROL, + code: Char('u') | Char('p'), + } => self.move_selection(MoveSelection::Up), - Event::Key(KeyEvent { + KeyEvent { + code: KeyCode::Down | KeyCode::PageDown, + .. + } + | KeyEvent { + modifiers: KeyModifiers::CONTROL, + code: Char('d') | Char('n'), + } => self.move_selection(MoveSelection::Down), + + KeyEvent { code: KeyCode::Esc, .. - }) => self.in_vim_insert_mode = false, - Event::Key(KeyEvent { + } => self.in_vim_insert_mode = false, + KeyEvent { code: KeyCode::Backspace, .. - }) => { + } => { self.input.delete(Move::Backward); self.refresh_matches(); } - Event::Key(KeyEvent { + KeyEvent { code: KeyCode::Delete, .. - }) => { + } => { self.input.delete(Move::Forward); self.refresh_matches(); } - Event::Key(KeyEvent { + KeyEvent { code: KeyCode::Home, .. - }) => self.input.move_cursor(Move::BOL), - Event::Key(KeyEvent { + } => self.input.move_cursor(Move::BOL), + KeyEvent { code: KeyCode::End, .. - }) => self.input.move_cursor(Move::EOL), - Event::Key(KeyEvent { - code: KeyCode::Char(c), - .. - }) => { + } => self.input.move_cursor(Move::EOL), + KeyEvent { code: Char(c), .. } => { self.input.insert(c); self.refresh_matches(); } - Event::Key(KeyEvent { + KeyEvent { code: KeyCode::F(1), .. - }) => { + } => { self.switch_result_sort(); self.refresh_matches(); } - Event::Key(KeyEvent { + KeyEvent { code: KeyCode::F(2), .. - }) => { + } => { if !self.matches.is_empty() { if self.settings.delete_without_confirm { self.delete_selection(); @@ -774,133 +745,119 @@ impl<'a> Interface<'a> { } } else { match event { - Event::Key(KeyEvent { + KeyEvent { code: KeyCode::Tab, .. - }) => { + } => { self.run = false; self.accept_selection(); return true; } - Event::Key( - KeyEvent { - code: KeyCode::Enter, - .. - } - | KeyEvent { - modifiers: KeyModifiers::CONTROL, - code: KeyCode::Char('j'), - }, - ) => { + KeyEvent { + code: KeyCode::Enter, + .. + } + | KeyEvent { + modifiers: KeyModifiers::CONTROL, + code: Char('j'), + } => { self.run = true; self.accept_selection(); return true; } - Event::Key( - KeyEvent { - modifiers: KeyModifiers::CONTROL, - code: - KeyCode::Char('c') - | KeyCode::Char('g') - | KeyCode::Char('z') - | KeyCode::Char('r'), // TODO add ZZ as shortcut - } - | KeyEvent { - code: KeyCode::Esc, .. - }, - ) => { + KeyEvent { + modifiers: KeyModifiers::CONTROL, + code: Char('c') | Char('g') | Char('z') | Char('r'), // TODO add ZZ as shortcut + } + | KeyEvent { + code: KeyCode::Esc, .. + } => { self.run = false; self.input.clear(); return true; } - Event::Key(KeyEvent { - code: KeyCode::Left | KeyCode::Char('h'), + KeyEvent { + code: KeyCode::Left | Char('h'), .. - }) => self.input.move_cursor(Move::Backward), - Event::Key(KeyEvent { - code: KeyCode::Right | KeyCode::Char('l'), + } => self.input.move_cursor(Move::Backward), + KeyEvent { + code: KeyCode::Right | Char('l'), .. - }) => self.input.move_cursor(Move::Forward), + } => self.input.move_cursor(Move::Forward), - Event::Key( - KeyEvent { - code: KeyCode::Up | KeyCode::PageUp | KeyCode::Char('k'), - .. - } - | KeyEvent { - modifiers: KeyModifiers::CONTROL, - code: KeyCode::Char('u'), - }, - ) => self.move_selection(MoveSelection::Up), - - Event::Key( - KeyEvent { - code: KeyCode::Down | KeyCode::PageDown | KeyCode::Char('j'), - .. - } - | KeyEvent { - modifiers: KeyModifiers::CONTROL, - code: KeyCode::Char('d'), - }, - ) => self.move_selection(MoveSelection::Down), - - Event::Key(KeyEvent { - code: KeyCode::Char('b') | KeyCode::Char('e'), + KeyEvent { + code: KeyCode::Up | KeyCode::PageUp | Char('k'), .. - }) => self.input.move_cursor(Move::BackwardWord), - Event::Key(KeyEvent { - code: KeyCode::Char('w'), + } + | KeyEvent { + modifiers: KeyModifiers::CONTROL, + code: Char('u'), + } => self.move_selection(MoveSelection::Up), + + KeyEvent { + code: KeyCode::Down | KeyCode::PageDown | Char('j'), .. - }) => self.input.move_cursor(Move::ForwardWord), - Event::Key(KeyEvent { - code: KeyCode::Char('0') | KeyCode::Char('^'), + } + | KeyEvent { + modifiers: KeyModifiers::CONTROL, + code: Char('d'), + } => self.move_selection(MoveSelection::Down), + + KeyEvent { + code: Char('b') | Char('e'), .. - }) => self.input.move_cursor(Move::BOL), - Event::Key(KeyEvent { - code: KeyCode::Char('$'), + } => self.input.move_cursor(Move::BackwardWord), + KeyEvent { + code: Char('w'), .. + } => self.input.move_cursor(Move::ForwardWord), + KeyEvent { + code: Char('0') | Char('^'), .. - }) => self.input.move_cursor(Move::EOL), + } => self.input.move_cursor(Move::BOL), + KeyEvent { + code: Char('$'), .. + } => self.input.move_cursor(Move::EOL), - Event::Key(KeyEvent { - code: KeyCode::Char('i') | KeyCode::Char('a'), + KeyEvent { + code: Char('i') | Char('a'), .. - }) => self.in_vim_insert_mode = true, + } => self.in_vim_insert_mode = true, - Event::Key(KeyEvent { + KeyEvent { code: KeyCode::Backspace, .. - }) => { + } => { self.input.delete(Move::Backward); self.refresh_matches(); } - Event::Key(KeyEvent { - code: KeyCode::Delete | KeyCode::Char('x'), + KeyEvent { + code: KeyCode::Delete | Char('x'), .. - }) => { + } => { self.input.delete(Move::Forward); self.refresh_matches(); } - Event::Key(KeyEvent { + KeyEvent { code: KeyCode::Home, .. - }) => self.input.move_cursor(Move::BOL), - Event::Key(KeyEvent { + } => self.input.move_cursor(Move::BOL), + KeyEvent { code: KeyCode::End, .. - }) => self.input.move_cursor(Move::EOL), + } => self.input.move_cursor(Move::EOL), - Event::Key(KeyEvent { + KeyEvent { code: KeyCode::F(1), .. - }) => { + } => { self.switch_result_sort(); self.refresh_matches(); - }, - Event::Key(KeyEvent { + } + KeyEvent { code: KeyCode::F(2), .. - }) => { + } => { if !self.matches.is_empty() { if self.settings.delete_without_confirm { self.delete_selection(); @@ -916,7 +873,77 @@ impl<'a> Interface<'a> { false } - fn truncate_for_display( + fn truncate_for_display( + command: &Command, + search: &str, + width: u16, + highlight_color: Color, + base_color: Color, + debug: bool, + ) -> String { + let mut prev: usize = 0; + let debug_space = if debug { 90 } else { 0 }; + let max_grapheme_length = if width > debug_space { + width - debug_space - 9 + } else { + width + }; + let mut out = FixedLengthGraphemeString::empty(max_grapheme_length); + + if !search.is_empty() { + for (start, end) in &command.match_bounds { + if prev != *start { + out.push_grapheme_str(&command.cmd[prev..*start]); + } + + execute!(out, SetForegroundColor(highlight_color)).unwrap(); + out.push_grapheme_str(&command.cmd[*start..*end]); + execute!(out, SetForegroundColor(base_color)).unwrap(); + prev = *end; + } + } + + if prev != command.cmd.len() { + out.push_grapheme_str(&command.cmd[prev..]); + } + + if debug { + out.max_grapheme_length += debug_space; + out.push_grapheme_str(" "); + execute!(out, SetForegroundColor(Color::Blue)).unwrap(); + out.push_grapheme_str(format!("rnk: {:.*} ", 2, command.rank)); + out.push_grapheme_str(format!("age: {:.*} ", 2, command.features.age_factor)); + out.push_grapheme_str(format!("lng: {:.*} ", 2, command.features.length_factor)); + out.push_grapheme_str(format!("ext: {:.*} ", 0, command.features.exit_factor)); + out.push_grapheme_str(format!( + "r_ext: {:.*} ", + 0, command.features.recent_failure_factor + )); + out.push_grapheme_str(format!("dir: {:.*} ", 3, command.features.dir_factor)); + out.push_grapheme_str(format!( + "s_dir: {:.*} ", + 3, command.features.selected_dir_factor + )); + out.push_grapheme_str(format!("ovlp: {:.*} ", 3, command.features.overlap_factor)); + out.push_grapheme_str(format!( + "i_ovlp: {:.*} ", + 3, command.features.immediate_overlap_factor + )); + out.push_grapheme_str(format!( + "occ: {:.*}", + 2, command.features.occurrences_factor + )); + out.push_grapheme_str(format!( + "s_occ: {:.*} ", + 2, command.features.selected_occurrences_factor + )); + execute!(out, SetForegroundColor(base_color)).unwrap(); + } + + out.string + } + + fn _truncate_for_display( screen: &mut T, command: &Command, search: &str, @@ -1050,3 +1077,5 @@ impl<'a> Interface<'a> { // Ctrl('s') => forward history search // Ctrl('t') => transpose characters // Ctrl('q') | Ctrl('v') => quoted insert +// Ctrl('y') => yank +// Ctrl('_') => undo diff --git a/src/main.rs b/src/main.rs index 1ca29bc9..10c1ae24 100644 --- a/src/main.rs +++ b/src/main.rs @@ -84,7 +84,7 @@ fn handle_search(settings: &Settings) { fake_typer::use_tiocsti(&cmd); if result.run { - // fake_typer::use_tiocsti( &"\n".to_string()); + fake_typer::use_tiocsti( &"\n".to_string()); } } } diff --git a/src/path_update_helpers.rs b/src/path_update_helpers.rs index 4eeda074..8e4e5aa7 100644 --- a/src/path_update_helpers.rs +++ b/src/path_update_helpers.rs @@ -1,9 +1,16 @@ -use std::path::Path; -use unicode_segmentation::UnicodeSegmentation; use path_absolutize::*; +use std::path::{Path, PathBuf}; +use unicode_segmentation::UnicodeSegmentation; pub fn normalize_path(incoming_path: &str) -> String { - return Path::new(incoming_path).absolutize_from(std::env::current_dir().unwrap().as_path()).unwrap().to_str().unwrap().to_string(); + let expanded_path = shellexpand::tilde(incoming_path).to_string(); + println!("{}", expanded_path); + return Path::new(&expanded_path) + .absolutize_from(std::env::current_dir().unwrap().as_path()) + .unwrap() + .to_str() + .unwrap() + .to_string(); } pub fn parse_mv_command(command: &str) -> Vec { @@ -81,6 +88,100 @@ pub fn parse_mv_command(command: &str) -> Vec { #[cfg(test)] mod tests { use super::{normalize_path, parse_mv_command}; + use std::env; + use std::path::PathBuf; + + #[test] + #[cfg(not(windows))] + fn normalize_path_works_absolute_paths() { + assert_eq!(normalize_path("/foo/bar/baz"), String::from("/foo/bar/baz")); + assert_eq!(normalize_path("/"), String::from("/")); + assert_eq!(normalize_path("////"), String::from("/")); + } + + #[test] + #[cfg(not(windows))] + fn normalize_path_works_with_tilda() { + assert_eq!(normalize_path("~/"), env::var("HOME").unwrap()); + assert_eq!( + normalize_path("~/foo"), + PathBuf::from(env::var("HOME").unwrap()) + .join("foo") + .to_string_lossy() + ); + } + + #[test] + #[cfg(not(windows))] + fn normalize_path_works_with_double_dots() { + assert_eq!(normalize_path("/foo/bar/../baz"), String::from("/foo/baz")); + assert_eq!(normalize_path("/foo/bar/../../baz"), String::from("/baz")); + assert_eq!(normalize_path("/foo/bar/../../"), String::from("/")); + assert_eq!(normalize_path("/foo/bar/../.."), String::from("/")); + assert_eq!( + normalize_path("~/foo/bar/../baz"), + PathBuf::from(env::var("HOME").unwrap()) + .join("foo/baz") + .to_string_lossy() + ); + assert_eq!(normalize_path("~/foo/bar/../.."), env::var("HOME").unwrap()); + } + + fn windows_home_path() -> String { + PathBuf::from(env::var("HOMEDRIVE").unwrap()) + .join(env::var("HOMEPATH").unwrap()) + .to_str() + .unwrap() + .to_string() + } + + #[test] + #[cfg(windows)] + fn normalize_path_works_absolute_paths() { + assert_eq!( + normalize_path("C:\\foo\\bar\\baz"), + String::from("C:\\foo\\bar\\baz") + ); + assert_eq!(normalize_path("C:\\"), String::from("C:\\")); + assert_eq!(normalize_path("C:\\\\\\\\"), String::from("C:\\")); + } + + #[test] + #[cfg(windows)] + fn normalize_path_works_with_tilda() { + assert_eq!(normalize_path("~\\"), windows_home_path()); + assert_eq!( + normalize_path("~\\foo"), + PathBuf::from(windows_home_path()) + .join("foo") + .to_string_lossy() + ); + } + + #[test] + #[cfg(windows)] + fn normalize_path_works_with_double_dots() { + assert_eq!( + normalize_path("C:\\foo\\bar\\..\\baz"), + String::from("C:\\foo\\baz") + ); + assert_eq!( + normalize_path("C:\\foo\\bar\\..\\..\\baz"), + String::from("C:\\baz") + ); + assert_eq!( + normalize_path("C:\\foo\\bar\\..\\..\\"), + String::from("C:\\") + ); + assert_eq!(normalize_path("C:\\foo\\bar\\..\\.."), String::from("C:\\")); + assert_eq!( + normalize_path("~\\foo\\bar\\..\\baz"), + PathBuf::from(windows_home_path()) + .join("foo\\baz") + .to_string_lossy() + ); + assert_eq!(normalize_path("~\\foo\\bar\\..\\.."), windows_home_path()); + } #[test] fn parse_mv_command_works_in_the_basic_case() { From 24ed41f2101d089ff7a5bd8df4ba35936e97873f Mon Sep 17 00:00:00 2001 From: Jackson Schuster <36744439+jtschuster@users.noreply.github.com> Date: Sun, 4 Sep 2022 09:54:32 -0500 Subject: [PATCH 10/31] Clean up --- README.md | 7 +--- mcfly.example.toml | 31 --------------- src/fixed_length_grapheme_string.rs | 2 +- src/interface.rs | 18 ++++----- src/main.rs | 2 +- src/path_update_helpers.rs | 2 +- src/settings.rs | 59 +---------------------------- 7 files changed, 13 insertions(+), 108 deletions(-) delete mode 100644 mcfly.example.toml diff --git a/README.md b/README.md index b3dd54cd..f7aa2d3c 100644 --- a/README.md +++ b/README.md @@ -207,13 +207,10 @@ To avoid McFly's UI messing up your scrollback history in iTerm2, make sure this iterm2 UI instructions ## Settings - -Settings, in particular the interface colors, may be configured in [`~/.mcfly/mcfly.toml`](https://github.com/cantino/mcfly/blob/crossterm-and-colors/mcfly.example.toml). - -A number of settings can also be set via environment variables. To set a setting you should add the following snippets to your `~/.bashrc` / `~/.zshrc` / `~/.config/fish/config.fish`. +A number of settings can be set via environment variables. To set a setting you should add the following snippets to your `~/.bashrc` / `~/.zshrc` / `~/.config/fish/config.fish`. ### Light Mode -To swap the default color scheme for use in a light terminal, set the environment variable `MCFLY_LIGHT`. +To swap the color scheme for use in a light terminal, set the environment variable `MCFLY_LIGHT`. bash / zsh: ```bash diff --git a/mcfly.example.toml b/mcfly.example.toml deleted file mode 100644 index 083bc54f..00000000 --- a/mcfly.example.toml +++ /dev/null @@ -1,31 +0,0 @@ -# Mcfly sample configuration, to be placed in ~/.mcfly/mcfly.toml - -fuzzy = true -results = 25 -key_scheme = "Vim" # Vim or Emacs (case-sensitive) - -[colors] -# Colors correspond to the ANSI colors defined for your terminal, and are -# named in crossterm style (case-insensitive): -# black dark_grey -# dark_red red -# dark_green green -# dark_yellow yellow -# dark_blue blue -# dark_magenta magenta -# dark_cyan cyan -# grey white - -menu_bg = "dark_red" -menu_fg = "white" -menu_deleting_bg = "cyan" -menu_deleting_fg = "dark_red" - -bg = "black" -fg = "white" -prompt_fg = "white" -highlight = "red" -timing = "magenta" -cursor_bg = "dark_grey" -cursor_fg = "white" -cursor_highlight = "red" diff --git a/src/fixed_length_grapheme_string.rs b/src/fixed_length_grapheme_string.rs index 951d0d3e..7587c353 100644 --- a/src/fixed_length_grapheme_string.rs +++ b/src/fixed_length_grapheme_string.rs @@ -27,7 +27,7 @@ impl FixedLengthGraphemeString { FixedLengthGraphemeString { string: String::new(), grapheme_length: 0, - max_grapheme_length: max_grapheme_length, + max_grapheme_length, } } diff --git a/src/interface.rs b/src/interface.rs index 42e8e664..30b95797 100644 --- a/src/interface.rs +++ b/src/interface.rs @@ -15,7 +15,6 @@ use crossterm::terminal::{Clear, ClearType, EnterAlternateScreen}; use crossterm::{cursor, execute, queue}; use humantime::format_duration; use std::io::{stdout, Write}; -use std::str::FromStr; use std::string::String; pub struct Interface<'a> { @@ -82,19 +81,17 @@ impl MenuMode { menu_text } - fn bg(&self, interface: &Interface) -> Color { + fn bg(&self) -> Color { match *self { - MenuMode::Normal => Color::from_str(&interface.settings.colors.menu_bg).unwrap(), - MenuMode::ConfirmDelete => { - Color::from_str(&interface.settings.colors.menu_deleting_bg).unwrap() - } + MenuMode::Normal => Color::Blue, + MenuMode::ConfirmDelete => Color::Red, } } } -const PROMPT_LINE_INDEX: u16 = 2; -const INFO_LINE_INDEX: u16 = 0; -const RESULTS_TOP_INDEX: u16 = 4; +const PROMPT_LINE_INDEX: u16 = 3; +const INFO_LINE_INDEX: u16 = 1; +const RESULTS_TOP_INDEX: u16 = 5; impl<'a> Interface<'a> { pub fn new(settings: &'a Settings, history: &'a History) -> Interface<'a> { @@ -159,7 +156,7 @@ impl<'a> Interface<'a> { cursor::Hide, cursor::MoveTo(0, self.info_line_index()), Clear(ClearType::CurrentLine), - SetBackgroundColor(self.menu_mode.bg(self)), + SetBackgroundColor(self.menu_mode.bg()), SetForegroundColor(Color::White), cursor::MoveTo(1, self.info_line_index()), Print(format!( @@ -198,7 +195,6 @@ impl<'a> Interface<'a> { cursor::MoveTo(0, result_top_index + self.settings.results + 1) ) .unwrap(); - // screen.flush().unwrap(); } fn results(&mut self, screen: &mut W) { diff --git a/src/main.rs b/src/main.rs index 10c1ae24..74c8584e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -84,7 +84,7 @@ fn handle_search(settings: &Settings) { fake_typer::use_tiocsti(&cmd); if result.run { - fake_typer::use_tiocsti( &"\n".to_string()); + fake_typer::use_tiocsti("\n"); } } } diff --git a/src/path_update_helpers.rs b/src/path_update_helpers.rs index 8e4e5aa7..8d92bfa9 100644 --- a/src/path_update_helpers.rs +++ b/src/path_update_helpers.rs @@ -1,5 +1,5 @@ use path_absolutize::*; -use std::path::{Path, PathBuf}; +use std::path::{Path}; use unicode_segmentation::UnicodeSegmentation; pub fn normalize_path(incoming_path: &str) -> String { diff --git a/src/settings.rs b/src/settings.rs index 1ceb9401..5eb98bdd 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -3,10 +3,6 @@ use crate::shell_history; use clap::AppSettings; use clap::{crate_authors, crate_version, value_t}; use clap::{App, Arg, SubCommand}; -use figment::{ - providers::{Format, Serialized, Toml}, - Figment, -}; use serde::{Deserialize, Serialize}; use directories_next::{ProjectDirs, UserDirs}; use std::env; @@ -68,22 +64,6 @@ pub enum HistoryFormat { Fish, } -#[derive(Debug, Serialize, Deserialize)] -pub struct Colors { - pub menu_bg: String, - pub menu_fg: String, - pub menu_deleting_bg: String, - pub menu_deleting_fg: String, - pub bg: String, - pub fg: String, - pub prompt_fg: String, - pub highlight: String, - pub timing: String, - pub cursor_bg: String, - pub cursor_fg: String, - pub cursor_highlight: String, -} - #[derive(Debug, Serialize, Deserialize)] pub struct Settings { pub mode: Mode, @@ -109,7 +89,6 @@ pub struct Settings { pub delete_without_confirm: bool, pub interface_view: InterfaceView, pub result_sort: ResultSort, - pub colors: Colors, pub disable_menu: bool, } @@ -139,20 +118,6 @@ impl Default for Settings { delete_without_confirm: false, interface_view: InterfaceView::Top, result_sort: ResultSort::Rank, - colors: Colors { - menu_bg: "Blue".to_string(), - menu_fg: "White".to_string(), - menu_deleting_bg: "Red".to_string(), - menu_deleting_fg: "Cyan".to_string(), - bg: "Black".to_string(), - fg: "White".to_string(), - prompt_fg: "White".to_string(), - highlight: "Green".to_string(), - timing: "Blue".to_string(), - cursor_bg: "Grey".to_string(), - cursor_fg: "Black".to_string(), - cursor_highlight: "Green".to_string(), - }, disable_menu: false, } } @@ -284,29 +249,7 @@ impl Settings { ) .get_matches(); - let mut default_settings = Settings::default(); - - if env::var("MCFLY_LIGHT").is_ok() { - default_settings.colors = Colors { - menu_bg: "Blue".to_string(), - menu_fg: "White".to_string(), - menu_deleting_bg: "Red".to_string(), - menu_deleting_fg: "Cyan".to_string(), - bg: "White".to_string(), - fg: "Black".to_string(), - prompt_fg: "Black".to_string(), - highlight: "Blue".to_string(), - timing: "Blue".to_string(), - cursor_bg: "Dark_Grey".to_string(), - cursor_fg: "White".to_string(), - cursor_highlight: "White".to_string(), - }; - } - - let mut settings: Settings = Figment::from(Serialized::defaults(default_settings)) - .merge(Toml::file(Settings::mcfly_config_path())) - .extract() - .unwrap(); + let mut settings = Settings::default(); if matches.is_present("init") { settings.skip_environment_check = true; From 44e79e724714fd33a3548a0f9bc446a9484a92bf Mon Sep 17 00:00:00 2001 From: Jackson Schuster <36744439+jtschuster@users.noreply.github.com> Date: Sun, 4 Sep 2022 14:35:34 -0500 Subject: [PATCH 11/31] clean a little more --- .gitignore | 1 + Cargo.lock | 71 +++---------------------------------------------- Cargo.toml | 3 --- mcfly.ps1 | 12 +++++++-- src/main.rs | 1 - src/settings.rs | 42 ++++++++++++++--------------- 6 files changed, 35 insertions(+), 95 deletions(-) diff --git a/.gitignore b/.gitignore index aa2de79a..e1c99503 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ update.sh .zsh_history .zshrc /.fish +.vscode diff --git a/Cargo.lock b/Cargo.lock index 3f2e23c9..7c9f940b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -21,9 +21,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "0.7.18" +version = "0.7.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e" dependencies = [ "memchr", ] @@ -46,15 +46,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "atomic" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b88d82667eca772c4aa12f0f1348b3ae643424c8876448f3f7bd5787032e234c" -dependencies = [ - "autocfg", -] - [[package]] name = "atty" version = "0.2.14" @@ -409,19 +400,6 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a" -[[package]] -name = "figment" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "790b4292c72618abbab50f787a477014fe15634f96291de45672ce46afe122df" -dependencies = [ - "atomic", - "serde", - "toml", - "uncased", - "version_check", -] - [[package]] name = "foreign-types" version = "0.3.2" @@ -652,16 +630,13 @@ dependencies = [ "csv", "directories-next", "dirs 2.0.2", - "figment", "humantime", "itertools", "libc", "path-absolutize", "rand 0.8.5", "regex", - "relative-path", "rusqlite", - "serde", "shellexpand", "unicode-segmentation", ] @@ -785,9 +760,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.13.1" +version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "074864da206b4973b84eb91683020dbefd6a8c3f0f38e054d93954e891935e4e" +checksum = "2f7254b99e31cad77da24b08ebf628882739a608578bb1bcdfc1f9c21260d7c0" [[package]] name = "parking_lot" @@ -1030,12 +1005,6 @@ version = "0.6.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" -[[package]] -name = "relative-path" -version = "1.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0df32d82cedd1499386877b062ebe8721f806de80b08d183c70184ef17dd1d42" - [[package]] name = "rusqlite" version = "0.28.0" @@ -1073,20 +1042,6 @@ name = "serde" version = "1.0.144" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0f747710de3dcd43b88c9168773254e809d8ddbdf9653b84e2554ab219f17860" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.144" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94ed3a816fb1d101812f83e789f888322c34e291f894f19590dc310963e87a00" -dependencies = [ - "proc-macro2 1.0.43", - "quote 1.0.21", - "syn 1.0.99", -] [[package]] name = "shellexpand" @@ -1203,24 +1158,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "toml" -version = "0.5.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" -dependencies = [ - "serde", -] - -[[package]] -name = "uncased" -version = "0.9.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09b01702b0fd0b3fadcf98e098780badda8742d4f4a7676615cad90e8ac73622" -dependencies = [ - "version_check", -] - [[package]] name = "unicode-ident" version = "1.0.3" diff --git a/Cargo.toml b/Cargo.toml index 88f89c77..cf54a8b1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,17 +26,14 @@ clap = "2" csv = "1" crossterm = "0.18" dirs = "2.0" -figment = { version = "0.10", features = ["toml"] } humantime = "2.1" directories-next = "2.0" itertools = "0.10" libc = "0.2" rand = "0.8" regex = "1" -serde = { version = "1.0", features = ["derive"] } autopilot = "0.4.0" path-absolutize = "3.0.13" -relative-path = "1.7" shellexpand = "2.1" unicode-segmentation = "1.9" diff --git a/mcfly.ps1 b/mcfly.ps1 index d25c6244..c0d1ed21 100644 --- a/mcfly.ps1 +++ b/mcfly.ps1 @@ -53,6 +53,12 @@ $null = New-Module mcfly { $LASTEXITCODE = $lastExitTmp } + function Invoke-McFly { + $lastExitTmp = $LASTEXITCODE + Start-Process -FilePath '::MCFLY::' -ArgumentList "search" -NoNewWindow -Wait + $LASTEXITCODE = $lastExitTmp + } + <# .SYNOPSIS Add a command to McFly's history. @@ -96,9 +102,11 @@ $null = New-Module mcfly { $line = $null $cursor = $null [Microsoft.PowerShell.PSConsoleReadline]::GetBufferState([ref]$line, [ref]$cursor) - [Microsoft.PowerShell.PSConsoleReadLine]::DeleteLine - Invoke-McFly -CommandToComplete $line + [Microsoft.PowerShell.PSConsoleReadLine]::DeleteLine() + "#mcfly: $line" | Out-File -FilePath $env:MCFLY_HISTORY -Append + Invoke-McFly } + Export-ModuleMember -Function @( "Invoke-McFly" "Add-CommandToMcFly" diff --git a/src/main.rs b/src/main.rs index 74c8584e..5d07bc9e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -80,7 +80,6 @@ fn handle_search(settings: &Settings) { fs::write(path, &out) .unwrap_or_else(|err| panic!("McFly error: unable to write to {}: {}", path, err)); } else { - fake_typer::delete_chars(settings.command.chars().count()); fake_typer::use_tiocsti(&cmd); if result.run { diff --git a/src/settings.rs b/src/settings.rs index 5eb98bdd..3067f84d 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -3,7 +3,6 @@ use crate::shell_history; use clap::AppSettings; use clap::{crate_authors, crate_version, value_t}; use clap::{App, Arg, SubCommand}; -use serde::{Deserialize, Serialize}; use directories_next::{ProjectDirs, UserDirs}; use std::env; use std::path::PathBuf; @@ -11,7 +10,7 @@ use std::str::FromStr; use std::time::SystemTime; use std::time::UNIX_EPOCH; -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug)] pub enum Mode { Add, Search, @@ -20,13 +19,13 @@ pub enum Mode { Init, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug)] pub enum KeyScheme { Emacs, Vim, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug)] pub enum InitMode { Bash, Zsh, @@ -34,19 +33,19 @@ pub enum InitMode { Powershell, } -#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Debug, PartialEq, Eq)] pub enum InterfaceView { Top, Bottom, } -#[derive(Debug, Serialize, Deserialize, Clone)] +#[derive(Debug, Clone)] pub enum ResultSort { Rank, LastRun, } -#[derive(Debug, Clone, Copy, Serialize, Deserialize)] +#[derive(Debug, Clone, Copy)] pub enum HistoryFormat { /// bash format - commands in plain text, one per line, with multi-line commands joined. /// HISTTIMEFORMAT is assumed to be empty. @@ -64,7 +63,7 @@ pub enum HistoryFormat { Fish, } -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug)] pub struct Settings { pub mode: Mode, pub debug: bool, @@ -431,20 +430,19 @@ impl Settings { if let Some(values) = search_matches.values_of("command") { settings.command = values.collect::>().join(" "); } else { - settings.command = "".to_string(); - //settings.command = shell_history::last_history_line( - // &settings.mcfly_history, - // settings.history_format, - //) - //.unwrap_or_default() - //.trim_start_matches("#mcfly: ") - //.trim_start_matches("#mcfly:") - //.to_string(); - //shell_history::delete_last_history_entry_if_search( - // &settings.mcfly_history, - // settings.history_format, - // settings.debug, - //); + settings.command = shell_history::last_history_line( + &settings.mcfly_history, + settings.history_format, + ) + .unwrap_or_default() + .trim_start_matches("#mcfly: ") + .trim_start_matches("#mcfly:") + .to_string(); + shell_history::delete_last_history_entry_if_search( + &settings.mcfly_history, + settings.history_format, + settings.debug, + ); } } From 2ff4ff238f73d647ef2ae293e18c490c009519a4 Mon Sep 17 00:00:00 2001 From: Jackson Schuster <36744439+jtschuster@users.noreply.github.com> Date: Sun, 4 Sep 2022 14:42:02 -0500 Subject: [PATCH 12/31] VSCode files gitignore --- .gitignore | 2 +- .vscode/launch.json | 75 --------------------------------------------- 2 files changed, 1 insertion(+), 76 deletions(-) delete mode 100644 .vscode/launch.json diff --git a/.gitignore b/.gitignore index e1c99503..709309bd 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,4 @@ update.sh .zsh_history .zshrc /.fish -.vscode +.vscode/**/* diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 9425f2e1..00000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,75 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "type": "lldb", - "request": "attach", - "name": "Attach", - "pid": "${command:pickMyProcess}" // use ${command:pickProcess} to pick other users' processes - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug unit tests in library 'mcfly'", - "cargo": { - "args": [ - "test", - "--no-run", - "--lib", - "--package=mcfly" - ], - "filter": { - "name": "mcfly", - "kind": "lib" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug executable 'mcfly'", - "cargo": { - "args": [ - "build", - "--bin=mcfly", - "--package=mcfly" - ], - "filter": { - "name": "mcfly", - "kind": "bin" - } - }, - "args": ["--history_format", "zsh", "search"], - "env": { - "MCFLY_SESSION_ID" : "asdfasdfasdfasdf", - "HISTFILE" : "C:\\Users\\jschuster\\AppData\\Roaming\\Microsoft\\Windows\\PowerShell\\PSReadLine\\ConsoleHost_history.txt", - "MCFLY_HISTORY" : "C:\\Users\\jschuster\\AppData\\Roaming\\Microsoft\\Windows\\PowerShell\\PSReadLine\\ConsoleHost_history.txt" - }, - "cwd": "${workspaceFolder}" - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug unit tests in executable 'mcfly'", - "cargo": { - "args": [ - "test", - "--no-run", - "--bin=mcfly", - "--package=mcfly" - ], - "filter": { - "name": "mcfly", - "kind": "bin" - } - }, - "args": [], - "cwd": "${workspaceFolder}" - } - ] -} \ No newline at end of file From d7f9ff24b3f31f97589e88f5ff037030f3668375 Mon Sep 17 00:00:00 2001 From: Jackson Schuster <36744439+jtschuster@users.noreply.github.com> Date: Sun, 4 Sep 2022 14:51:51 -0500 Subject: [PATCH 13/31] Final clean --- src/fake_typer.rs | 7 ---- src/interface.rs | 87 +---------------------------------------------- src/settings.rs | 13 +------ 3 files changed, 2 insertions(+), 105 deletions(-) diff --git a/src/fake_typer.rs b/src/fake_typer.rs index eae0b3ff..bb07a72c 100644 --- a/src/fake_typer.rs +++ b/src/fake_typer.rs @@ -20,10 +20,3 @@ pub fn use_tiocsti(string: &str) { pub fn use_tiocsti(string: &str) { autopilot::key::type_string(string, &[], 0.0, 0.0); } - -pub fn delete_chars(n : usize) -{ - for _ in 0..n { - autopilot::key::tap(&autopilot::key::Code(autopilot::key::KeyCode::Backspace), &[], 0, 0); - } -} diff --git a/src/interface.rs b/src/interface.rs index 30b95797..2b1c4446 100644 --- a/src/interface.rs +++ b/src/interface.rs @@ -882,7 +882,7 @@ impl<'a> Interface<'a> { let max_grapheme_length = if width > debug_space { width - debug_space - 9 } else { - width + 11 }; let mut out = FixedLengthGraphemeString::empty(max_grapheme_length); @@ -939,91 +939,6 @@ impl<'a> Interface<'a> { out.string } - fn _truncate_for_display( - screen: &mut T, - command: &Command, - search: &str, - _width: u16, - highlighted_text_color: Color, - text_color: Color, - debug: bool, - ) -> String { - let mut prev: usize = 0; - let _debug_space = if debug { 90 } else { 0 }; - // let max_grapheme_length = if width > debug_space { - // width - debug_space - 9 - // } else { - // 11 - // }; - // let mut out = FixedLengthGraphemeString::empty(max_grapheme_length); - - if !search.is_empty() { - for (start, end) in &command.match_bounds { - if prev != *start { - let _ = queue!(screen, Print(&command.cmd[prev..*start])); - } - - let _ = queue!(screen, SetForegroundColor(highlighted_text_color)); - let _ = queue!(screen, Print(&command.cmd[*start..*end])); - let _ = queue!(screen, SetForegroundColor(text_color)); - prev = *end; - } - } - - if prev != command.cmd.len() { - let _ = queue!(screen, Print(&command.cmd[prev..])); - } - - if debug { - // out.max_grapheme_length += debug_space; - let _ = queue!(screen, Print(" ")); - let _ = queue!(screen, SetForegroundColor(Color::Blue)); - let _ = queue!(screen, Print(format!("rnk: {:.*} ", 2, command.rank))); - let _ = queue!( - screen, - Print(format!("age: {:.*} ", 2, command.features.age_factor)) - ); - let _ = queue!( - screen, - Print(format!("lng: {:.*} ", 2, command.features.length_factor)) - ); - let _ = queue!( - screen, - Print(format!("ext: {:.*} ", 0, command.features.exit_factor)) - ); - let _ = queue!( - screen, - Print(format!( - "r_ext: {:.*} ", - 0, command.features.recent_failure_factor - )) - ); - // out.push_grapheme_str(format!("dir: {:.*} ", 3, command.features.dir_factor)); - // out.push_grapheme_str(format!( - // "s_dir: {:.*} ", - // 3, command.features.selected_dir_factor - // )); - // out.push_grapheme_str(format!("ovlp: {:.*} ", 3, command.features.overlap_factor)); - // out.push_grapheme_str(format!( - // "i_ovlp: {:.*} ", - // 3, command.features.immediate_overlap_factor - // )); - // out.push_grapheme_str(format!( - // "occ: {:.*}", - // 2, command.features.occurrences_factor - // )); - // out.push_grapheme_str(format!( - // "s_occ: {:.*} ", - // 2, command.features.selected_occurrences_factor - // )); - - // out.push_str(&format!("{}", SetForegroundColor(text_color))); - } - - // out.string - "".to_string() - } - fn result_top_index(&self) -> u16 { let (_width, height): (u16, u16) = terminal::size().unwrap(); diff --git a/src/settings.rs b/src/settings.rs index 3067f84d..21e10c7a 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -1,4 +1,3 @@ - use crate::shell_history; use clap::AppSettings; use clap::{crate_authors, crate_version, value_t}; @@ -79,8 +78,8 @@ pub struct Settings { pub old_dir: Option, pub append_to_histfile: bool, pub refresh_training_cache: bool, - pub key_scheme: KeyScheme, pub lightmode: bool, + pub key_scheme: KeyScheme, pub history_format: HistoryFormat, pub limit: Option, pub skip_environment_check: bool, @@ -488,12 +487,6 @@ impl Settings { _ => unreachable!(), // If all subcommands are defined above, anything else is unreachable!() } - if env::var("MCFLY_KEY_SCHEME").is_ok() { - settings.key_scheme = match env::var("MCFLY_KEY_SCHEME").as_ref().map(String::as_ref) { - Ok("vim") => KeyScheme::Vim, - _ => KeyScheme::Emacs, - }; - } settings.lightmode = match env::var_os("MCFLY_LIGHT") { Some(_val) => true, None => false, @@ -519,10 +512,6 @@ impl Settings { Settings::mcfly_base_path(cache_dir).join(PathBuf::from("training-cache.v1.csv")) } - pub fn mcfly_config_path() -> PathBuf { - Settings::mcfly_dir_in_home().unwrap().join(PathBuf::from("mcfly.toml")) - } - // Use ~/.mcfly only if it already exists, otherwise create 'mcfly' folder in XDG_DATA_DIR pub fn mcfly_db_path() -> PathBuf { let data_dir = Settings::mcfly_xdg_dir().data_dir().to_path_buf(); From a74cadd0f44f1146523aa8031ab3411c1b3c0bc6 Mon Sep 17 00:00:00 2001 From: Jackson Schuster <36744439+jtschuster@users.noreply.github.com> Date: Sun, 4 Sep 2022 15:11:37 -0500 Subject: [PATCH 14/31] Couple other small changes --- mcfly.ps1 | 4 ++-- src/fixed_length_grapheme_string.rs | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/mcfly.ps1 b/mcfly.ps1 index c0d1ed21..e44014d1 100644 --- a/mcfly.ps1 +++ b/mcfly.ps1 @@ -11,7 +11,7 @@ $null = New-Module mcfly { # We need PSReadLine for a number of capabilities if ($null -eq (Get-Module -Name PSReadLine)) { - Write-Output "Installing PSReadLine as McFly dependency" + Write-Host "Installing PSReadLine as McFly dependency" Install-Module PSReadLine } @@ -24,7 +24,7 @@ $null = New-Module mcfly { $fileExists = Test-Path -path $env:HISTFILE if (-not $fileExists) { - Write-Output "McFly: ${env:HISTFILE} does not exist or is not readable. Please fix this or set HISTFILE to something else before using McFly."; + Write-Host "McFly: ${env:HISTFILE} does not exist or is not readable. Please fix this or set HISTFILE to something else before using McFly."; return 1; } diff --git a/src/fixed_length_grapheme_string.rs b/src/fixed_length_grapheme_string.rs index 7587c353..2cd710f3 100644 --- a/src/fixed_length_grapheme_string.rs +++ b/src/fixed_length_grapheme_string.rs @@ -1,5 +1,4 @@ -use std::{io::{Write}}; - +use std::io::Write; use unicode_segmentation::UnicodeSegmentation; #[derive(Debug)] From 0033d7c5b78f33d940e373ee92c1f94008c263ed Mon Sep 17 00:00:00 2001 From: Jackson Schuster <36744439+jtschuster@users.noreply.github.com> Date: Sun, 4 Sep 2022 15:14:56 -0500 Subject: [PATCH 15/31] format --- src/fixed_length_grapheme_string.rs | 3 +-- src/init.rs | 6 ++--- src/path_update_helpers.rs | 2 +- src/settings.rs | 40 +++++++++++++++++------------ 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/fixed_length_grapheme_string.rs b/src/fixed_length_grapheme_string.rs index 2cd710f3..5e903128 100644 --- a/src/fixed_length_grapheme_string.rs +++ b/src/fixed_length_grapheme_string.rs @@ -8,8 +8,7 @@ pub struct FixedLengthGraphemeString { pub max_grapheme_length: u16, } -impl Write for FixedLengthGraphemeString -{ +impl Write for FixedLengthGraphemeString { fn write(&mut self, buf: &[u8]) -> std::io::Result { let s = String::from_utf8(buf.to_vec()).unwrap(); self.push_str(&s); diff --git a/src/init.rs b/src/init.rs index de413ad3..2a8c76b1 100644 --- a/src/init.rs +++ b/src/init.rs @@ -1,6 +1,5 @@ -use std::env; - use super::settings::InitMode; +use std::env; pub struct Init {} @@ -35,7 +34,8 @@ impl Init { print!("{}", script); } pub fn init_pwsh() { - let script = include_str!("../mcfly.ps1").replace("::MCFLY::", env::current_exe().unwrap().to_str().unwrap()); + let script = include_str!("../mcfly.ps1") + .replace("::MCFLY::", env::current_exe().unwrap().to_str().unwrap()); print!("{}", script); } } diff --git a/src/path_update_helpers.rs b/src/path_update_helpers.rs index 8d92bfa9..7bba4087 100644 --- a/src/path_update_helpers.rs +++ b/src/path_update_helpers.rs @@ -1,5 +1,5 @@ use path_absolutize::*; -use std::path::{Path}; +use std::path::Path; use unicode_segmentation::UnicodeSegmentation; pub fn normalize_path(incoming_path: &str) -> String { diff --git a/src/settings.rs b/src/settings.rs index 21e10c7a..b32a4629 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -347,16 +347,19 @@ impl Settings { if let Some(dir) = add_matches.value_of("directory") { settings.dir = dir.to_string(); } else { - settings.dir = env::current_dir().unwrap_or_else(|err| { - panic!( - "McFly error: Unable to determine current directory ({})", - err - ) - }).to_str().to_owned().unwrap_or_else(|| { - panic!( - "McFly error: Unable to determine current directory" - ) - }).to_string(); + settings.dir = env::current_dir() + .unwrap_or_else(|err| { + panic!( + "McFly error: Unable to determine current directory ({})", + err + ) + }) + .to_str() + .to_owned() + .unwrap_or_else(|| { + panic!("McFly error: Unable to determine current directory") + }) + .to_string(); } if let Some(old_dir) = add_matches.value_of("old_directory") { @@ -389,12 +392,16 @@ impl Settings { if let Some(dir) = search_matches.value_of("directory") { settings.dir = dir.to_string(); } else { - settings.dir = env::current_dir().unwrap_or_else(|err| { - panic!( - "McFly error: Unable to determine current directory ({})", - err - ) - }).to_str().unwrap().to_string(); + settings.dir = env::current_dir() + .unwrap_or_else(|err| { + panic!( + "McFly error: Unable to determine current directory ({})", + err + ) + }) + .to_str() + .unwrap() + .to_string(); } if let Ok(results) = env::var("MCFLY_RESULTS") { @@ -540,4 +547,3 @@ impl Settings { } } } - From 3fc6a15fdaf50922847aeddc4ad8681c6468bea1 Mon Sep 17 00:00:00 2001 From: Jackson Schuster Date: Sat, 5 Nov 2022 11:35:24 -0500 Subject: [PATCH 16/31] Avoid the black flicker on key strokes by never clearing all --- Cargo.lock | 346 ++++++++++++----------------------------------- src/interface.rs | 11 +- 2 files changed, 95 insertions(+), 262 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7df779ac..94d4a060 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14,7 +14,7 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" dependencies = [ - "getrandom 0.2.7", + "getrandom 0.2.8", "once_cell", "version_check", ] @@ -109,7 +109,7 @@ dependencies = [ name = "bumpalo" version = "3.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1ad822118d20d2c234f427000d5acc36eabe1e29a348c89b63dd60b13f28e5d" +checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" [[package]] name = "byteorder" @@ -117,12 +117,6 @@ version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" -[[package]] -name = "cc" -version = "1.0.73" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" - [[package]] name = "cc" version = "1.0.74" @@ -172,7 +166,6 @@ dependencies = [ ] [[package]] -<<<<<<< HEAD name = "cocoa" version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -187,6 +180,16 @@ dependencies = [ "objc", ] +[[package]] +name = "codespan-reporting" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" +dependencies = [ + "termcolor", + "unicode-width", +] + [[package]] name = "color_quant" version = "1.1.0" @@ -210,25 +213,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" [[package]] -======= -name = "codespan-reporting" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" -dependencies = [ - "termcolor", - "unicode-width", -] - -[[package]] ->>>>>>> 78a5422e7a2bd4213b13691183c020361aea608f name = "core-foundation-sys" version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" [[package]] -<<<<<<< HEAD name = "core-graphics" version = "0.19.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -272,26 +262,24 @@ dependencies = [ [[package]] name = "crossbeam-epoch" -version = "0.9.10" +version = "0.9.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "045ebe27666471bb549370b4b0b3e51b07f56325befa4284db65fc89c02511b1" +checksum = "f916dfc5d356b0ed9dae65f1db9fc9770aa2851d2662b988ccf4fe3516e86348" dependencies = [ "autocfg", "cfg-if 1.0.0", "crossbeam-utils", "memoffset", - "once_cell", "scopeguard", ] [[package]] name = "crossbeam-utils" -version = "0.8.11" +version = "0.8.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51887d4adc7b564537b15adcfb307936f8075dfcd5f00dde9a9f1d29383682bc" +checksum = "edbafec5fa1f196ca66527c1b12c2ec4745ca14b50f1ad8f9f6f720b55d11fac" dependencies = [ "cfg-if 1.0.0", - "once_cell", ] [[package]] @@ -320,8 +308,6 @@ dependencies = [ ] [[package]] -======= ->>>>>>> 78a5422e7a2bd4213b13691183c020361aea608f name = "csv" version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -344,15 +330,6 @@ dependencies = [ ] [[package]] -<<<<<<< HEAD -name = "deflate" -version = "0.7.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707b6a7b384888a70c8d2e8650b3e60170dfc6a67bb4aa67b6dfca57af4bedb4" -dependencies = [ - "adler32", - "byteorder", -======= name = "cxx" version = "1.0.80" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -373,10 +350,10 @@ dependencies = [ "cc", "codespan-reporting", "once_cell", - "proc-macro2", - "quote", + "proc-macro2 1.0.47", + "quote 1.0.21", "scratch", - "syn", + "syn 1.0.103", ] [[package]] @@ -391,10 +368,19 @@ version = "1.0.80" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "309e4fb93eed90e1e14bea0da16b209f81813ba9fc7830c20ed151dd7bc0a4d7" dependencies = [ - "proc-macro2", - "quote", - "syn", ->>>>>>> 78a5422e7a2bd4213b13691183c020361aea608f + "proc-macro2 1.0.47", + "quote 1.0.21", + "syn 1.0.103", +] + +[[package]] +name = "deflate" +version = "0.7.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "707b6a7b384888a70c8d2e8650b3e60170dfc6a67bb4aa67b6dfca57af4bedb4" +dependencies = [ + "adler32", + "byteorder", ] [[package]] @@ -409,7 +395,6 @@ dependencies = [ [[package]] name = "dirs" -<<<<<<< HEAD version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13aea89a5c93364a98e9b37b2fa237effbb694d5cfe01c5b70941f7eb087d5e3" @@ -424,12 +409,6 @@ version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" dependencies = [ -======= -version = "4.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" -dependencies = [ ->>>>>>> 78a5422e7a2bd4213b13691183c020361aea608f "dirs-sys", ] @@ -511,7 +490,6 @@ dependencies = [ ] [[package]] -<<<<<<< HEAD name = "gif" version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -525,11 +503,6 @@ dependencies = [ name = "hashbrown" version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -======= -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" ->>>>>>> 78a5422e7a2bd4213b13691183c020361aea608f checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" dependencies = [ "ahash", @@ -561,19 +534,28 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "iana-time-zone" -<<<<<<< HEAD -version = "0.1.47" +version = "0.1.53" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c495f162af0bf17656d0014a0eded5f3cd2f365fdd204548c2869db89359dc7" +checksum = "64c122667b287044802d6ce17ee2ddf13207ed924c712de9a66a5814d5b64765" dependencies = [ "android_system_properties", "core-foundation-sys 0.8.3", + "iana-time-zone-haiku", "js-sys", - "once_cell", "wasm-bindgen", "winapi", ] +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0703ae284fc167426161c2e3f1da3ea71d94b21bedbcc9494e92b28e334e3dca" +dependencies = [ + "cxx", + "cxx-build", +] + [[package]] name = "image" version = "0.22.5" @@ -609,33 +591,6 @@ dependencies = [ "cfg-if 1.0.0", ] -[[package]] -name = "itertools" -version = "0.10.3" -======= -version = "0.1.53" ->>>>>>> 78a5422e7a2bd4213b13691183c020361aea608f -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64c122667b287044802d6ce17ee2ddf13207ed924c712de9a66a5814d5b64765" -dependencies = [ - "android_system_properties", - "core-foundation-sys", - "iana-time-zone-haiku", - "js-sys", - "wasm-bindgen", - "winapi", -] - -[[package]] -name = "iana-time-zone-haiku" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0703ae284fc167426161c2e3f1da3ea71d94b21bedbcc9494e92b28e334e3dca" -dependencies = [ - "cxx", - "cxx-build", -] - [[package]] name = "itertools" version = "0.10.5" @@ -652,7 +607,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" [[package]] -<<<<<<< HEAD name = "jpeg-decoder" version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -663,15 +617,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.59" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "258451ab10b34f8af53416d1fdab72c22e805f0c92a1136d59470ec0b11138b2" -======= -name = "js-sys" version = "0.3.60" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" ->>>>>>> 78a5422e7a2bd4213b13691183c020361aea608f dependencies = [ "wasm-bindgen", ] @@ -684,17 +632,6 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -<<<<<<< HEAD -version = "0.2.132" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5" - -[[package]] -name = "libsqlite3-sys" -version = "0.25.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f0455f2c1bc9a7caa792907026e469c1d91761fb0ea37cbb16427c77280cf35" -======= version = "0.2.137" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" @@ -704,7 +641,6 @@ name = "libsqlite3-sys" version = "0.25.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "29f835d03d717946d28b1d1ed632eb6f0e24a299388ee623d0c23118d3e8a7fa" ->>>>>>> 78a5422e7a2bd4213b13691183c020361aea608f dependencies = [ "cc", "pkg-config", @@ -712,22 +648,22 @@ dependencies = [ ] [[package]] -<<<<<<< HEAD -name = "lock_api" -version = "0.4.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f80bf5aacaf25cbfc8210d1cfb718f2bf3b11c4c54e5afe36c236853a8ec390" -dependencies = [ - "autocfg", - "scopeguard", -======= name = "link-cplusplus" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9272ab7b96c9046fbc5bc56c06c117cb639fe2d509df0c421cad82d2915cf369" dependencies = [ "cc", ->>>>>>> 78a5422e7a2bd4213b13691183c020361aea608f +] + +[[package]] +name = "lock_api" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" +dependencies = [ + "autocfg", + "scopeguard", ] [[package]] @@ -736,7 +672,6 @@ version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ -<<<<<<< HEAD "cfg-if 1.0.0", ] @@ -753,9 +688,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb" dependencies = [ "libc", -======= - "cfg-if", ->>>>>>> 78a5422e7a2bd4213b13691183c020361aea608f ] [[package]] @@ -880,9 +812,9 @@ dependencies = [ [[package]] name = "num_cpus" -version = "1.13.1" +version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" +checksum = "f6058e64324c71e02bc2b150e4f3bc8286db6c83092132ffa3f6b1eab0f9def5" dependencies = [ "hermit-abi", "libc", @@ -899,10 +831,9 @@ dependencies = [ [[package]] name = "once_cell" -<<<<<<< HEAD -version = "1.14.0" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f7254b99e31cad77da24b08ebf628882739a608578bb1bcdfc1f9c21260d7c0" +checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" [[package]] name = "parking_lot" @@ -931,26 +862,21 @@ dependencies = [ [[package]] name = "path-absolutize" -version = "3.0.13" +version = "3.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3de4b40bd9736640f14c438304c09538159802388febb02c8abaae0846c1f13" +checksum = "0f1d4993b16f7325d90c18c3c6a3327db7808752db8d208cea0acee0abd52c52" dependencies = [ "path-dedot", ] [[package]] name = "path-dedot" -version = "3.0.17" +version = "3.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d611d5291372b3738a34ebf0d1f849e58b1dcc1101032f76a346eaa1f8ddbb5b" +checksum = "9a81540d94551664b72b72829b12bd167c73c9d25fbac0e04fafa8023f7e4901" dependencies = [ "once_cell", ] -======= -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" ->>>>>>> 78a5422e7a2bd4213b13691183c020361aea608f [[package]] name = "pkg-config" @@ -972,13 +898,12 @@ dependencies = [ [[package]] name = "ppv-lite86" -version = "0.2.16" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro2" -<<<<<<< HEAD version = "0.4.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" @@ -988,29 +913,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.43" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab" -======= version = "1.0.47" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" ->>>>>>> 78a5422e7a2bd4213b13691183c020361aea608f dependencies = [ "unicode-ident", ] [[package]] name = "quote" -<<<<<<< HEAD version = "0.6.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" -======= -version = "1.0.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" ->>>>>>> 78a5422e7a2bd4213b13691183c020361aea608f dependencies = [ "proc-macro2 0.4.30", ] @@ -1021,7 +935,7 @@ version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" dependencies = [ - "proc-macro2 1.0.43", + "proc-macro2 1.0.47", ] [[package]] @@ -1045,7 +959,7 @@ checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", "rand_chacha 0.3.1", - "rand_core 0.6.3", + "rand_core 0.6.4", ] [[package]] @@ -1065,7 +979,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core 0.6.3", + "rand_core 0.6.4", ] [[package]] @@ -1083,7 +997,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom 0.2.7", + "getrandom 0.2.8", ] [[package]] @@ -1134,7 +1048,7 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" dependencies = [ - "getrandom 0.2.7", + "getrandom 0.2.8", "redox_syscall", "thiserror", ] @@ -1183,7 +1097,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" [[package]] -<<<<<<< HEAD name = "scoped_threadpool" version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1196,11 +1109,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] -name = "serde" -version = "1.0.144" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f747710de3dcd43b88c9168773254e809d8ddbdf9653b84e2554ab219f17860" -======= name = "scratch" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1211,7 +1119,6 @@ name = "serde" version = "1.0.147" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965" ->>>>>>> 78a5422e7a2bd4213b13691183c020361aea608f [[package]] name = "shellexpand" @@ -1219,7 +1126,6 @@ version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ccc8076840c4da029af4f87e4e8daeb0fca6b87bbb02e10cb60b791450e11e4" dependencies = [ -<<<<<<< HEAD "dirs 4.0.0", ] @@ -1241,9 +1147,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0" dependencies = [ "libc", -======= - "dirs", ->>>>>>> 78a5422e7a2bd4213b13691183c020361aea608f ] [[package]] @@ -1260,15 +1163,9 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "syn" -<<<<<<< HEAD version = "0.15.44" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5" -======= -version = "1.0.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d" ->>>>>>> 78a5422e7a2bd4213b13691183c020361aea608f dependencies = [ "proc-macro2 0.4.30", "quote 0.6.13", @@ -1276,28 +1173,23 @@ dependencies = [ ] [[package]] -<<<<<<< HEAD name = "syn" -version = "1.0.99" -======= -name = "termcolor" -version = "1.1.3" +version = "1.0.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d" dependencies = [ - "winapi-util", + "proc-macro2 1.0.47", + "quote 1.0.21", + "unicode-ident", ] [[package]] -name = "termion" -version = "1.5.6" ->>>>>>> 78a5422e7a2bd4213b13691183c020361aea608f +name = "termcolor" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" dependencies = [ - "proc-macro2 1.0.43", - "quote 1.0.21", - "unicode-ident", + "winapi-util", ] [[package]] @@ -1311,34 +1203,22 @@ dependencies = [ [[package]] name = "thiserror" -<<<<<<< HEAD -version = "1.0.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d0a539a918745651435ac7db7a18761589a94cd7e94cd56999f828bf73c8a57" -======= version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e" ->>>>>>> 78a5422e7a2bd4213b13691183c020361aea608f dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -<<<<<<< HEAD -version = "1.0.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c251e90f708e16c49a16f4917dc2131e75222b72edfa9cb7f7c58ae56aae0c09" -======= version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb" ->>>>>>> 78a5422e7a2bd4213b13691183c020361aea608f dependencies = [ - "proc-macro2 1.0.43", + "proc-macro2 1.0.47", "quote 1.0.21", - "syn 1.0.99", + "syn 1.0.103", ] [[package]] @@ -1366,15 +1246,9 @@ dependencies = [ [[package]] name = "unicode-ident" -<<<<<<< HEAD -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" -======= version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" ->>>>>>> 78a5422e7a2bd4213b13691183c020361aea608f [[package]] name = "unicode-segmentation" @@ -1432,101 +1306,57 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -<<<<<<< HEAD -version = "0.2.82" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc7652e3f6c4706c8d9cd54832c4a4ccb9b5336e2c3bd154d5cccfbf1c1f5f7d" -dependencies = [ - "cfg-if 1.0.0", -======= version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" dependencies = [ - "cfg-if", ->>>>>>> 78a5422e7a2bd4213b13691183c020361aea608f + "cfg-if 1.0.0", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -<<<<<<< HEAD -version = "0.2.82" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "662cd44805586bd52971b9586b1df85cdbbd9112e4ef4d8f41559c334dc6ac3f" -======= version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" ->>>>>>> 78a5422e7a2bd4213b13691183c020361aea608f dependencies = [ "bumpalo", "log", "once_cell", -<<<<<<< HEAD - "proc-macro2 1.0.43", + "proc-macro2 1.0.47", "quote 1.0.21", - "syn 1.0.99", -======= - "proc-macro2", - "quote", - "syn", ->>>>>>> 78a5422e7a2bd4213b13691183c020361aea608f + "syn 1.0.103", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-macro" -<<<<<<< HEAD -version = "0.2.82" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b260f13d3012071dfb1512849c033b1925038373aea48ced3012c09df952c602" -dependencies = [ - "quote 1.0.21", -======= version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" dependencies = [ - "quote", ->>>>>>> 78a5422e7a2bd4213b13691183c020361aea608f + "quote 1.0.21", "wasm-bindgen-macro-support", ] [[package]] name = "wasm-bindgen-macro-support" -<<<<<<< HEAD -version = "0.2.82" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5be8e654bdd9b79216c2929ab90721aa82faf65c48cdf08bdc4e7f51357b80da" -dependencies = [ - "proc-macro2 1.0.43", - "quote 1.0.21", - "syn 1.0.99", -======= version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" dependencies = [ - "proc-macro2", - "quote", - "syn", ->>>>>>> 78a5422e7a2bd4213b13691183c020361aea608f + "proc-macro2 1.0.47", + "quote 1.0.21", + "syn 1.0.103", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -<<<<<<< HEAD -version = "0.2.82" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6598dd0bd3c7d51095ff6531a5b23e02acdc81804e30d8f07afb77b7215a140a" -======= version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" ->>>>>>> 78a5422e7a2bd4213b13691183c020361aea608f [[package]] name = "winapi" diff --git a/src/interface.rs b/src/interface.rs index 2b1c4446..31e1d431 100644 --- a/src/interface.rs +++ b/src/interface.rs @@ -202,7 +202,6 @@ impl<'a> Interface<'a> { screen, cursor::Hide, cursor::MoveTo(1, self.result_top_index()), - Clear(ClearType::All) ) .unwrap(); @@ -246,6 +245,7 @@ impl<'a> Interface<'a> { 1, (command_line_index as i16 + self.result_top_index() as i16) as u16 ), + Clear(ClearType::CurrentLine), SetBackgroundColor(bg), SetForegroundColor(fg), Print(Interface::truncate_for_display( @@ -311,12 +311,12 @@ impl<'a> Interface<'a> { #[allow(unused)] fn debug>(&self, screen: &mut W, s: S) { - let _ = queue!( + queue!( screen, cursor::MoveTo(0, 0), Clear(ClearType::CurrentLine), Print(s.into()) - ); + ).unwrap(); screen.flush().unwrap(); } @@ -394,7 +394,10 @@ impl<'a> Interface<'a> { fn select(&mut self) { let mut screen = stdout(); terminal::enable_raw_mode().unwrap(); - queue!(screen, EnterAlternateScreen, Clear(ClearType::All)).unwrap(); + queue!( + screen, + EnterAlternateScreen, + ).unwrap(); self.refresh_matches(); self.results(&mut screen); From 154d6397b016ad149ed33249e655f74f2a816636 Mon Sep 17 00:00:00 2001 From: Jackson Schuster Date: Sat, 5 Nov 2022 14:31:44 -0500 Subject: [PATCH 17/31] format --- src/interface.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/interface.rs b/src/interface.rs index 31e1d431..b18f0a57 100644 --- a/src/interface.rs +++ b/src/interface.rs @@ -316,7 +316,8 @@ impl<'a> Interface<'a> { cursor::MoveTo(0, 0), Clear(ClearType::CurrentLine), Print(s.into()) - ).unwrap(); + ) + .unwrap(); screen.flush().unwrap(); } @@ -394,10 +395,7 @@ impl<'a> Interface<'a> { fn select(&mut self) { let mut screen = stdout(); terminal::enable_raw_mode().unwrap(); - queue!( - screen, - EnterAlternateScreen, - ).unwrap(); + queue!(screen, EnterAlternateScreen).unwrap(); self.refresh_matches(); self.results(&mut screen); From 5c978dda284ed17674e9e502a3d86c59bddfbbe6 Mon Sep 17 00:00:00 2001 From: Jackson Schuster Date: Sun, 6 Nov 2022 12:16:07 -0600 Subject: [PATCH 18/31] Add loop to clear lines where there are no longer matches --- src/interface.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/interface.rs b/src/interface.rs index b18f0a57..cd8557f2 100644 --- a/src/interface.rs +++ b/src/interface.rs @@ -211,7 +211,10 @@ impl<'a> Interface<'a> { self.selection = self.matches.len() - 1; } - for (index, command) in self.matches.iter().enumerate() { + // We need the index of the last handled command after the loop, so declare outside of loop + let mut index : usize = 0; + for command in self.matches.iter() { + let mut fg = if self.settings.lightmode { Color::Black } else { @@ -306,6 +309,22 @@ impl<'a> Interface<'a> { ) .unwrap(); } + index += 1; + } + + // Since we only clear by line instead of clearing the screen each update, + // we need to clear all the lines that may have previously had a command + for i in index..(self.settings.results as usize) { + let command_line_index = self.command_line_index(i as i16); + queue!( + screen, + cursor::MoveTo( + 1, + (command_line_index as i16 + self.result_top_index() as i16) as u16 + ), + Clear(ClearType::CurrentLine) + ).unwrap(); + } } From 0eeb04cb7d5cbf0d9eb02ac05299bcf20aa4462e Mon Sep 17 00:00:00 2001 From: Jackson Schuster Date: Sun, 6 Nov 2022 16:14:11 -0600 Subject: [PATCH 19/31] Format --- src/interface.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/interface.rs b/src/interface.rs index cd8557f2..d002d72d 100644 --- a/src/interface.rs +++ b/src/interface.rs @@ -212,9 +212,8 @@ impl<'a> Interface<'a> { } // We need the index of the last handled command after the loop, so declare outside of loop - let mut index : usize = 0; + let mut index: usize = 0; for command in self.matches.iter() { - let mut fg = if self.settings.lightmode { Color::Black } else { @@ -323,8 +322,8 @@ impl<'a> Interface<'a> { (command_line_index as i16 + self.result_top_index() as i16) as u16 ), Clear(ClearType::CurrentLine) - ).unwrap(); - + ) + .unwrap(); } } From 558b1478a5539dce65893af89ba9147f256c0cfe Mon Sep 17 00:00:00 2001 From: Jackson Schuster Date: Sun, 26 Feb 2023 15:55:26 -0800 Subject: [PATCH 20/31] pwsh --- src/cli.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cli.rs b/src/cli.rs index 53bfc766..cd5e7cb4 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -124,6 +124,7 @@ pub enum InitMode { Bash, Zsh, Fish, + Powershell, } impl Cli { From f9e802d59f55e08ca07bc7aeb47805ec52d972c9 Mon Sep 17 00:00:00 2001 From: Jackson Schuster Date: Sun, 26 Feb 2023 16:12:15 -0800 Subject: [PATCH 21/31] Clear every results line --- Cargo.lock | 326 ++++++++++++++++++++++++++++++++++------------- Cargo.toml | 1 - src/interface.rs | 29 +++-- 3 files changed, 258 insertions(+), 98 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 94d4a060..d7f87f71 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -37,26 +37,6 @@ dependencies = [ "libc", ] -[[package]] -name = "ansi_term" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" -dependencies = [ - "winapi", -] - -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi", - "libc", - "winapi", -] - [[package]] name = "autocfg" version = "1.1.0" @@ -152,17 +132,39 @@ dependencies = [ [[package]] name = "clap" -version = "2.34.0" +version = "4.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" +checksum = "ec0b0588d44d4d63a87dbd75c136c166bbfd9a86a31cb89e09906521c7d3f5e3" dependencies = [ - "ansi_term", - "atty", "bitflags", + "clap_derive", + "clap_lex", + "is-terminal", + "once_cell", "strsim", - "textwrap", - "unicode-width", - "vec_map", + "termcolor", +] + +[[package]] +name = "clap_derive" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "684a277d672e91966334af371f1a7b5833f9aa00b07c84e92fbce95e00208ce8" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2 1.0.47", + "quote 1.0.21", + "syn 1.0.103", +] + +[[package]] +name = "clap_lex" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "350b9cf31731f9957399229e9b2adc51eeabdfbe9d71d9a0552275fd12710d09" +dependencies = [ + "os_str_bytes", ] [[package]] @@ -284,25 +286,26 @@ dependencies = [ [[package]] name = "crossterm" -version = "0.18.2" +version = "0.26.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e86d73f2a0b407b5768d10a8c720cf5d2df49a9efc10ca09176d201ead4b7fb" +checksum = "a84cda67535339806297f1b331d6dd6320470d2a0fe65381e79ee9e156dd3d13" dependencies = [ "bitflags", "crossterm_winapi", - "lazy_static", + "filedescriptor", "libc", "mio", "parking_lot", "signal-hook", + "signal-hook-mio", "winapi", ] [[package]] name = "crossterm_winapi" -version = "0.6.2" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2265c3f8e080075d9b6417aa72293fc71662f34b4af2612d8d1b074d29510db" +checksum = "2ae1b35a484aa10e07fe0638d02301c5ad24de82d310ccbd2f3693da5f09bf1c" dependencies = [ "winapi", ] @@ -440,6 +443,27 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" +[[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 = "fallible-iterator" version = "0.2.0" @@ -452,6 +476,17 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a" +[[package]] +name = "filedescriptor" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7199d965852c3bac31f779ef99cbb4537f80e952e2d6aa0ffeb30cce00f4f46e" +dependencies = [ + "libc", + "thiserror", + "winapi", +] + [[package]] name = "foreign-types" version = "0.3.2" @@ -517,6 +552,12 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + [[package]] name = "hermit-abi" version = "0.1.19" @@ -526,6 +567,12 @@ dependencies = [ "libc", ] +[[package]] +name = "hermit-abi" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" + [[package]] name = "humantime" version = "2.1.0" @@ -583,12 +630,25 @@ dependencies = [ ] [[package]] -name = "instant" -version = "0.1.12" +name = "io-lifetimes" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +checksum = "1abeb7a0dd0f8181267ff8adc397075586500b81b28a73e8a0208b00fc170fb3" dependencies = [ - "cfg-if 1.0.0", + "libc", + "windows-sys", +] + +[[package]] +name = "is-terminal" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b6b32576413a8e69b90e952e4a026476040d81017b80445deda5f2d3921857" +dependencies = [ + "hermit-abi 0.3.1", + "io-lifetimes", + "rustix", + "windows-sys", ] [[package]] @@ -656,6 +716,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 = "lock_api" version = "0.4.9" @@ -692,7 +758,7 @@ dependencies = [ [[package]] name = "mcfly" -version = "0.6.1" +version = "0.7.1" dependencies = [ "autopilot", "chrono", @@ -729,33 +795,14 @@ dependencies = [ [[package]] name = "mio" -version = "0.7.14" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8067b404fe97c70829f082dec8bcf4f71225d7eaea1d8645349cb76fa06205cc" +checksum = "5b9d9a46eff5b4ff64b45a9e316a6d1e0bc719ef429cbec4dc630684212bfdf9" dependencies = [ "libc", "log", - "miow", - "ntapi", - "winapi", -] - -[[package]] -name = "miow" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" -dependencies = [ - "winapi", -] - -[[package]] -name = "ntapi" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c28774a7fd2fbb4f0babd8237ce554b73af68021b5f695a3cebd6c59bac0980f" -dependencies = [ - "winapi", + "wasi 0.11.0+wasi-snapshot-preview1", + "windows-sys", ] [[package]] @@ -816,7 +863,7 @@ version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6058e64324c71e02bc2b150e4f3bc8286db6c83092132ffa3f6b1eab0f9def5" dependencies = [ - "hermit-abi", + "hermit-abi 0.1.19", "libc", ] @@ -835,29 +882,33 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" +[[package]] +name = "os_str_bytes" +version = "6.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" + [[package]] name = "parking_lot" -version = "0.11.2" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" dependencies = [ - "instant", "lock_api", "parking_lot_core", ] [[package]] name = "parking_lot_core" -version = "0.8.5" +version = "0.9.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" +checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521" dependencies = [ "cfg-if 1.0.0", - "instant", "libc", "redox_syscall", "smallvec", - "winapi", + "windows-sys", ] [[package]] @@ -902,6 +953,30 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2 1.0.47", + "quote 1.0.21", + "syn 1.0.103", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2 1.0.47", + "quote 1.0.21", + "version_check", +] + [[package]] name = "proc-macro2" version = "0.4.30" @@ -1090,6 +1165,20 @@ dependencies = [ "smallvec", ] +[[package]] +name = "rustix" +version = "0.36.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f43abb88211988493c1abb44a70efa56ff0ce98f233b7b276146f1f3f7ba9644" +dependencies = [ + "bitflags", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys", + "windows-sys", +] + [[package]] name = "ryu" version = "1.0.11" @@ -1131,15 +1220,25 @@ dependencies = [ [[package]] name = "signal-hook" -version = "0.1.17" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e31d442c16f047a671b5a71e2161d6e68814012b7f5379d269ebd915fac2729" +checksum = "732768f1176d21d09e076c23a93123d40bba92d50c4058da34d45c8de8e682b9" dependencies = [ "libc", - "mio", "signal-hook-registry", ] +[[package]] +name = "signal-hook-mio" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29ad2e15f37ec9a6cc544097b78a1ec90001e9f71b81338ca39f430adaca99af" +dependencies = [ + "libc", + "mio", + "signal-hook", +] + [[package]] name = "signal-hook-registry" version = "1.4.0" @@ -1157,9 +1256,9 @@ checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" [[package]] name = "strsim" -version = "0.8.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" @@ -1192,15 +1291,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "textwrap" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -dependencies = [ - "unicode-width", -] - [[package]] name = "thiserror" version = "1.0.37" @@ -1274,12 +1364,6 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" -[[package]] -name = "vec_map" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" - [[package]] name = "version_check" version = "0.9.4" @@ -1389,6 +1473,72 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7" + +[[package]] +name = "windows_i686_gnu" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640" + +[[package]] +name = "windows_i686_msvc" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" + [[package]] name = "x11" version = "2.20.0" diff --git a/Cargo.toml b/Cargo.toml index 43fc78eb..d64cbd9a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,6 @@ debug = true [dependencies] chrono = "0.4" csv = "1" -crossterm = "0.18" dirs = "2.0" humantime = "2.1" directories-next = "2.0" diff --git a/src/interface.rs b/src/interface.rs index 966ac7c2..1e1f7d7f 100644 --- a/src/interface.rs +++ b/src/interface.rs @@ -200,13 +200,7 @@ impl<'a> Interface<'a> { fn results(&mut self, screen: &mut W) { let result_top_index = self.result_top_index(); - queue!( - screen, - cursor::Hide, - cursor::MoveTo(1, result_top_index), - Clear(ClearType::All) - ) - .unwrap(); + queue!(screen, cursor::Hide, cursor::MoveTo(1, result_top_index)).unwrap(); let (width, _height): (u16, u16) = terminal::size().unwrap(); @@ -250,13 +244,14 @@ impl<'a> Interface<'a> { 1, (command_line_index as i16 + self.result_top_index() as i16) as u16 ), + Clear(ClearType::CurrentLine), SetBackgroundColor(bg), SetForegroundColor(fg), Print(Interface::truncate_for_display( command, &self.input.command, width, - fg_highlight, + highlight, fg, self.debug )) @@ -321,6 +316,22 @@ impl<'a> Interface<'a> { ) .unwrap(); } + index += 1; + } + + // Since we only clear by line instead of clearing the screen each update, + // we need to clear all the lines that may have previously had a command + for i in index..(self.settings.results as usize) { + let command_line_index = self.command_line_index(i as i16); + queue!( + screen, + cursor::MoveTo( + 1, + (command_line_index as i16 + self.result_top_index() as i16) as u16 + ), + Clear(ClearType::CurrentLine) + ) + .unwrap(); } } @@ -412,7 +423,7 @@ impl<'a> Interface<'a> { fn select(&mut self) { let mut screen = stdout(); terminal::enable_raw_mode().unwrap(); - queue!(screen, EnterAlternateScreen, Clear(ClearType::All)).unwrap(); + queue!(screen, EnterAlternateScreen).unwrap(); self.refresh_matches(true); self.results(&mut screen); From c7bf093db457e22b38d6ba073aaf964912300e4e Mon Sep 17 00:00:00 2001 From: Jackson Schuster Date: Mon, 27 Feb 2023 20:34:47 -0800 Subject: [PATCH 22/31] Fix bug in autopilot crate --- Cargo.lock | 266 +++++++++++++++++++++------------------------- Cargo.toml | 2 +- mcfly.ps1 | 4 +- src/fake_typer.rs | 2 + src/interface.rs | 5 +- src/settings.rs | 11 ++ 6 files changed, 139 insertions(+), 151 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d7f87f71..5c7c9d8c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -21,9 +21,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "0.7.19" +version = "0.7.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e" +checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" dependencies = [ "memchr", ] @@ -46,8 +46,7 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "autopilot" version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a2fd0359d0cd30b15419bcce7e6641a3cbe2046c612b3900216dc64bc989558" +source = "git+https://github.com/jtschuster/autopilot-rs#cedea5b5371768d136b8eecd77ce26040fa4c675" dependencies = [ "cocoa", "core-foundation", @@ -73,23 +72,11 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" -[[package]] -name = "bstr" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" -dependencies = [ - "lazy_static", - "memchr", - "regex-automata", - "serde", -] - [[package]] name = "bumpalo" -version = "3.11.1" +version = "3.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" +checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" [[package]] name = "byteorder" @@ -99,9 +86,9 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "cc" -version = "1.0.74" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "581f5dba903aac52ea3feb5ec4810848460ee833876f1f9b0fdeab1f19091574" +checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" [[package]] name = "cfg-if" @@ -117,9 +104,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.22" +version = "0.4.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfd4d1b31faaa3a89d7934dbded3111da0d2ef28e3ebccdb4f0179f5929d1ef1" +checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f" dependencies = [ "iana-time-zone", "js-sys", @@ -132,9 +119,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.1.6" +version = "4.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0b0588d44d4d63a87dbd75c136c166bbfd9a86a31cb89e09906521c7d3f5e3" +checksum = "2f3061d6db6d8fcbbd4b05e057f2acace52e64e96b498c08c2d7a4e65addd340" dependencies = [ "bitflags", "clap_derive", @@ -147,15 +134,15 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.1.0" +version = "4.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "684a277d672e91966334af371f1a7b5833f9aa00b07c84e92fbce95e00208ce8" +checksum = "34d122164198950ba84a918270a3bb3f7ededd25e15f7451673d986f55bd2667" dependencies = [ "heck", "proc-macro-error", - "proc-macro2 1.0.47", - "quote 1.0.21", - "syn 1.0.103", + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.109", ] [[package]] @@ -264,9 +251,9 @@ dependencies = [ [[package]] name = "crossbeam-epoch" -version = "0.9.11" +version = "0.9.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f916dfc5d356b0ed9dae65f1db9fc9770aa2851d2662b988ccf4fe3516e86348" +checksum = "01a9af1f4c2ef74bb8aa1f7e19706bc72d03598c8a570bb5de72243c7a9d9d5a" dependencies = [ "autocfg", "cfg-if 1.0.0", @@ -277,9 +264,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.12" +version = "0.8.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edbafec5fa1f196ca66527c1b12c2ec4745ca14b50f1ad8f9f6f720b55d11fac" +checksum = "4fb766fa798726286dbbb842f174001dab8abc7b627a1dd86e0b7222a95d929f" dependencies = [ "cfg-if 1.0.0", ] @@ -312,11 +299,10 @@ dependencies = [ [[package]] name = "csv" -version = "1.1.6" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22813a6dc45b335f9bade10bf7271dc477e81113e89eb251a0bc2a8a81c536e1" +checksum = "af91f40b7355f82b0a891f50e70399475945bb0b0da4f1700ce60761c9d3e359" dependencies = [ - "bstr", "csv-core", "itoa", "ryu", @@ -334,9 +320,9 @@ dependencies = [ [[package]] name = "cxx" -version = "1.0.80" +version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b7d4e43b25d3c994662706a1d4fcfc32aaa6afd287502c111b237093bb23f3a" +checksum = "86d3488e7665a7a483b57e25bdd90d0aeb2bc7608c8d0346acf2ad3f1caf1d62" dependencies = [ "cc", "cxxbridge-flags", @@ -346,34 +332,34 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.80" +version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84f8829ddc213e2c1368e51a2564c552b65a8cb6a28f31e576270ac81d5e5827" +checksum = "48fcaf066a053a41a81dfb14d57d99738b767febb8b735c3016e469fac5da690" dependencies = [ "cc", "codespan-reporting", "once_cell", - "proc-macro2 1.0.47", - "quote 1.0.21", + "proc-macro2 1.0.51", + "quote 1.0.23", "scratch", - "syn 1.0.103", + "syn 1.0.109", ] [[package]] name = "cxxbridge-flags" -version = "1.0.80" +version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e72537424b474af1460806647c41d4b6d35d09ef7fe031c5c2fa5766047cc56a" +checksum = "a2ef98b8b717a829ca5603af80e1f9e2e48013ab227b68ef37872ef84ee479bf" [[package]] name = "cxxbridge-macro" -version = "1.0.80" +version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "309e4fb93eed90e1e14bea0da16b209f81813ba9fc7830c20ed151dd7bc0a4d7" +checksum = "086c685979a698443656e5cf7856c95c642295a38599f12fb1ff76fb28d19892" dependencies = [ - "proc-macro2 1.0.47", - "quote 1.0.21", - "syn 1.0.103", + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.109", ] [[package]] @@ -439,9 +425,9 @@ dependencies = [ [[package]] name = "either" -version = "1.8.0" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" +checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" [[package]] name = "errno" @@ -560,9 +546,9 @@ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "hermit-abi" -version = "0.1.19" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" dependencies = [ "libc", ] @@ -662,9 +648,9 @@ dependencies = [ [[package]] name = "itoa" -version = "0.4.8" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" +checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440" [[package]] name = "jpeg-decoder" @@ -677,24 +663,18 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.60" +version = "0.3.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" +checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730" dependencies = [ "wasm-bindgen", ] -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - [[package]] name = "libc" -version = "0.2.137" +version = "0.2.139" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" +checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" [[package]] name = "libsqlite3-sys" @@ -709,9 +689,9 @@ dependencies = [ [[package]] name = "link-cplusplus" -version = "1.0.7" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9272ab7b96c9046fbc5bc56c06c117cb639fe2d509df0c421cad82d2915cf369" +checksum = "ecd207c9c713c34f95a097a5b029ac2ce6010530c7b49d7fea24d977dede04f5" dependencies = [ "cc", ] @@ -786,9 +766,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", ] @@ -859,11 +839,11 @@ dependencies = [ [[package]] name = "num_cpus" -version = "1.14.0" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6058e64324c71e02bc2b150e4f3bc8286db6c83092132ffa3f6b1eab0f9def5" +checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" dependencies = [ - "hermit-abi 0.1.19", + "hermit-abi 0.2.6", "libc", ] @@ -878,9 +858,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.16.0" +version = "1.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" +checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" [[package]] name = "os_str_bytes" @@ -960,9 +940,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" dependencies = [ "proc-macro-error-attr", - "proc-macro2 1.0.47", - "quote 1.0.21", - "syn 1.0.103", + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.109", "version_check", ] @@ -972,8 +952,8 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" dependencies = [ - "proc-macro2 1.0.47", - "quote 1.0.21", + "proc-macro2 1.0.51", + "quote 1.0.23", "version_check", ] @@ -988,9 +968,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.47" +version = "1.0.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" +checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6" dependencies = [ "unicode-ident", ] @@ -1006,11 +986,11 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.21" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" +checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" dependencies = [ - "proc-macro2 1.0.47", + "proc-macro2 1.0.51", ] [[package]] @@ -1086,21 +1066,19 @@ dependencies = [ [[package]] name = "rayon" -version = "1.5.3" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd99e5772ead8baa5215278c9b15bf92087709e9c1b2d1f97cdb5a183c933a7d" +checksum = "6db3a213adf02b3bcfd2d3846bb41cb22857d131789e01df434fb7e7bc0759b7" dependencies = [ - "autocfg", - "crossbeam-deque", "either", "rayon-core", ] [[package]] name = "rayon-core" -version = "1.9.3" +version = "1.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "258bcdb5ac6dad48491bb2992db6b7cf74878b0384908af124823d118c99683f" +checksum = "356a0625f1954f730c0201cdab48611198dc6ce21f4acff55089b5a78e6e835b" dependencies = [ "crossbeam-channel", "crossbeam-deque", @@ -1130,26 +1108,20 @@ dependencies = [ [[package]] name = "regex" -version = "1.6.0" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b" +checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" dependencies = [ "aho-corasick", "memchr", "regex-syntax", ] -[[package]] -name = "regex-automata" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" - [[package]] name = "regex-syntax" -version = "0.6.27" +version = "0.6.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" +checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" [[package]] name = "rusqlite" @@ -1181,9 +1153,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.11" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" +checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde" [[package]] name = "scoped_threadpool" @@ -1199,15 +1171,15 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "scratch" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8132065adcfd6e02db789d9285a0deb2f3fcb04002865ab67d5fb103533898" +checksum = "ddccb15bcce173023b3fedd9436f882a0739b8dfb45e4f6b6002bee5929f61b2" [[package]] name = "serde" -version = "1.0.147" +version = "1.0.152" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965" +checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" [[package]] name = "shellexpand" @@ -1241,9 +1213,9 @@ dependencies = [ [[package]] name = "signal-hook-registry" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0" +checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" dependencies = [ "libc", ] @@ -1273,42 +1245,42 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.103" +version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ - "proc-macro2 1.0.47", - "quote 1.0.21", + "proc-macro2 1.0.51", + "quote 1.0.23", "unicode-ident", ] [[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", ] [[package]] name = "thiserror" -version = "1.0.37" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e" +checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.37" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb" +checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f" dependencies = [ - "proc-macro2 1.0.47", - "quote 1.0.21", - "syn 1.0.103", + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.109", ] [[package]] @@ -1325,9 +1297,9 @@ dependencies = [ [[package]] name = "time" -version = "0.1.44" +version = "0.1.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" +checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" dependencies = [ "libc", "wasi 0.10.0+wasi-snapshot-preview1", @@ -1336,15 +1308,15 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.5" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" +checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" [[package]] name = "unicode-segmentation" -version = "1.10.0" +version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fdbf052a0783de01e944a6ce7a8cb939e295b1e7be835a1112c3b9a7f047a5a" +checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" [[package]] name = "unicode-width" @@ -1390,9 +1362,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.83" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" +checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" dependencies = [ "cfg-if 1.0.0", "wasm-bindgen-macro", @@ -1400,47 +1372,47 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.83" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" +checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9" dependencies = [ "bumpalo", "log", "once_cell", - "proc-macro2 1.0.47", - "quote 1.0.21", - "syn 1.0.103", + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.109", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.83" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" +checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" dependencies = [ - "quote 1.0.21", + "quote 1.0.23", "wasm-bindgen-macro-support", ] [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.83" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" +checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" dependencies = [ - "proc-macro2 1.0.47", - "quote 1.0.21", - "syn 1.0.103", + "proc-macro2 1.0.51", + "quote 1.0.23", + "syn 1.0.109", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.83" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" +checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" [[package]] name = "winapi" @@ -1541,9 +1513,9 @@ checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" [[package]] name = "x11" -version = "2.20.0" +version = "2.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7ae97874a928d821b061fce3d1fc52f08071dd53c89a6102bc06efcac3b2908" +checksum = "502da5464ccd04011667b11c435cb992822c2c0dbde1770c988480d312a0db2e" dependencies = [ "libc", "pkg-config", diff --git a/Cargo.toml b/Cargo.toml index d64cbd9a..839c8d17 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ itertools = "0.10" libc = "0.2" rand = "0.8" regex = "1" -autopilot = "0.4.0" +autopilot = {git="https://github.com/jtschuster/autopilot-rs"} path-absolutize = "3.0.13" shellexpand = "2.1" unicode-segmentation = "1.9" diff --git a/mcfly.ps1 b/mcfly.ps1 index e44014d1..c71a67e6 100644 --- a/mcfly.ps1 +++ b/mcfly.ps1 @@ -79,7 +79,7 @@ $null = New-Module mcfly { ) $ExitCode = $ExitCode ?? 0; $Command | Out-File -FilePath $env:MCFLY_HISTORY -Append - Start-Process -FilePath '::MCFLY::' -ArgumentList add, --exit, $ExitCode, --append-to-histfile -NoNewWindow | Write-Host + Start-Process -FilePath '::MCFLY::' -ArgumentList add, --exit, $ExitCode, --append-to-histfile, $env:HISTFILE -NoNewWindow | Write-Host } # We need to make sure we call out AddToHistoryHandler right after each command is called @@ -111,4 +111,4 @@ $null = New-Module mcfly { "Invoke-McFly" "Add-CommandToMcFly" ) -} \ No newline at end of file +} diff --git a/src/fake_typer.rs b/src/fake_typer.rs index bb07a72c..31bb7b32 100644 --- a/src/fake_typer.rs +++ b/src/fake_typer.rs @@ -1,6 +1,8 @@ +#[cfg(not(windows))] use libc; // Should we be using https://docs.rs/libc/0.2.44/libc/fn.ioctl.html instead? +#[cfg(not(windows))] extern "C" { pub fn ioctl(fd: libc::c_int, request: libc::c_ulong, arg: ...) -> libc::c_int; } diff --git a/src/interface.rs b/src/interface.rs index 1e1f7d7f..89d737d4 100644 --- a/src/interface.rs +++ b/src/interface.rs @@ -8,7 +8,7 @@ use crate::settings::{InterfaceView, KeyScheme}; use crate::settings::{ResultSort, Settings}; use chrono::{Duration, TimeZone, Utc}; use crossterm::event::KeyCode::Char; -use crossterm::event::{read, Event, KeyCode, KeyEvent, KeyModifiers}; +use crossterm::event::{read, Event, KeyCode, KeyEvent, KeyEventKind, KeyModifiers}; use crossterm::style::{Color, Print, SetBackgroundColor, SetForegroundColor}; use crossterm::terminal::{self, LeaveAlternateScreen}; use crossterm::terminal::{Clear, ClearType, EnterAlternateScreen}; @@ -495,6 +495,9 @@ impl<'a> Interface<'a> { } fn select_with_emacs_key_scheme(&mut self, event: KeyEvent) -> bool { + if event.kind == KeyEventKind::Release { + return false; + } match event { KeyEvent { code: KeyCode::Enter, diff --git a/src/settings.rs b/src/settings.rs index 70be687a..e8adf8ef 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -377,6 +377,7 @@ impl Settings { } } +#[cfg(not(windows))] fn pwd() -> String { env::var("PWD").unwrap_or_else(|err| { panic!( @@ -386,6 +387,16 @@ fn pwd() -> String { }) } +#[cfg(windows)] +fn pwd() -> String { + env::current_dir().unwrap_or_else(|err| { + panic!( + "McFly error: Unable to determine current directory ({})", + err + ) + }).display().to_string() +} + fn is_env_var_truthy(name: &str) -> bool { match env::var(name) { Ok(val) => { From 7ed407935d6556747e80de7d6db94b129f917baf Mon Sep 17 00:00:00 2001 From: Jackson Schuster Date: Tue, 28 Feb 2023 15:40:59 -0800 Subject: [PATCH 23/31] Fix clippy warnings --- src/interface.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/interface.rs b/src/interface.rs index 89d737d4..da5e2eda 100644 --- a/src/interface.rs +++ b/src/interface.rs @@ -242,7 +242,7 @@ impl<'a> Interface<'a> { screen, cursor::MoveTo( 1, - (command_line_index as i16 + self.result_top_index() as i16) as u16 + (command_line_index + self.result_top_index() as i16) as u16 ), Clear(ClearType::CurrentLine), SetBackgroundColor(bg), @@ -307,7 +307,7 @@ impl<'a> Interface<'a> { screen, cursor::MoveTo( width - 9, - (command_line_index as i16 + self.result_top_index() as i16) as u16 + (command_line_index + self.result_top_index() as i16) as u16 ), SetForegroundColor(timing_color), Print(format!("{:>9}", duration)), @@ -327,7 +327,7 @@ impl<'a> Interface<'a> { screen, cursor::MoveTo( 1, - (command_line_index as i16 + self.result_top_index() as i16) as u16 + (command_line_index + self.result_top_index() as i16) as u16 ), Clear(ClearType::CurrentLine) ) From a020f683479e442560c4c599ca12bb88875530eb Mon Sep 17 00:00:00 2001 From: Jackson Schuster Date: Sun, 5 Mar 2023 15:59:06 -0800 Subject: [PATCH 24/31] fmt --- src/settings.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/settings.rs b/src/settings.rs index 5db6fe32..1fe1b7f9 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -401,12 +401,15 @@ fn pwd() -> String { #[cfg(windows)] fn pwd() -> String { - env::current_dir().unwrap_or_else(|err| { - panic!( - "McFly error: Unable to determine current directory ({})", - err - ) - }).display().to_string() + env::current_dir() + .unwrap_or_else(|err| { + panic!( + "McFly error: Unable to determine current directory ({})", + err + ) + }) + .display() + .to_string() } fn is_env_var_truthy(name: &str) -> bool { From f074c9373f503acff9809a73ecd83754dee21819 Mon Sep 17 00:00:00 2001 From: Jackson Schuster Date: Sun, 5 Mar 2023 16:38:58 -0800 Subject: [PATCH 25/31] make autopilot a dependency on windows only --- Cargo.toml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 839c8d17..f9540b47 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,10 +22,8 @@ dirs = "2.0" humantime = "2.1" directories-next = "2.0" itertools = "0.10" -libc = "0.2" rand = "0.8" regex = "1" -autopilot = {git="https://github.com/jtschuster/autopilot-rs"} path-absolutize = "3.0.13" shellexpand = "2.1" unicode-segmentation = "1.9" @@ -43,3 +41,8 @@ features = ["use-dev-tty"] version = "4" features = ["derive"] +[target.'cfg(not(windows))'.dependencies] +libc = "0.2" + +[target.'cfg(windows)'.dependencies] +autopilot = {git="https://github.com/jtschuster/autopilot-rs"} From 0a3013fc9c00d0f2c6ee607e00e6162db51650f3 Mon Sep 17 00:00:00 2001 From: Jackson Schuster Date: Mon, 11 Sep 2023 16:01:06 -0500 Subject: [PATCH 26/31] Merge main --- .github/workflows/mean_bean_deploy.yml | 2 +- CHANGELOG.txt | 15 + Cargo.lock | 683 +++++++++++-------------- Cargo.toml | 14 +- README.md | 14 + mcfly.fish | 4 +- mcfly.ps1 | 2 +- mcfly.zsh | 24 +- pkg/brew/mcfly.rb | 6 +- src/history/history.rs | 12 +- src/interface.rs | 73 ++- src/settings.rs | 21 +- src/shell_history.rs | 8 +- src/training_sample_generator.rs | 3 +- 14 files changed, 444 insertions(+), 437 deletions(-) diff --git a/.github/workflows/mean_bean_deploy.yml b/.github/workflows/mean_bean_deploy.yml index ff797f92..5e2eb6ae 100644 --- a/.github/workflows/mean_bean_deploy.yml +++ b/.github/workflows/mean_bean_deploy.yml @@ -130,7 +130,7 @@ jobs: with: tag_name: ${{ github.ref }} release_name: ${{ github.ref }} - draft: false + draft: true prerelease: false - name: Upload Release Asset id: upload-release-asset diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 2e72f148..ca8e3be0 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,3 +1,18 @@ +0.8.1 - Jun 3, 2023 + - Fix use of MCFLY_DISABLE_MENU (thanks @barklan!) + - Support Fish private mode support (thanks @Aeron!) + - Always set MCFLY_HISTORY in zsh to support subshells (thanks @utkarshgupta137!) + - Allow linking mcfly with system-provided sqlite with sqlite-bundled feature flag (thanks @jirutka!) + - And allow sourcing in zsh more than once (thanks @ahatzz11 and @deekshithanand!) + - Reduce size by removing unnecessary/unused regex features (thanks @jirutka!) + - Add per-directory history (thanks @rawkode!) + +0.8.0 - Mar 6, 2023 + - Add forward-compatibility check for database schema (thanks @bnprks!) + - Add MCFLY_DISABLE_RUN_COMMAND option to disable command running (thanks @chaserhkj!) + - Add customizable prompt with MCFLY_PROMPT (thanks @vedkothavade!) + - Replace termion with crossterm (big change, thanks @jtschuster!) + - Allow ENV variables to be set to FALSE 0.7.1 - Dec 15, 2022 - Ensure at least MCFLY_HISTFILE is set for history import when HISTFILE is missing 0.7.0 - Dec 10, 2022 diff --git a/Cargo.lock b/Cargo.lock index 5c7c9d8c..120ddb69 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10,24 +10,36 @@ checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234" [[package]] name = "ahash" -version = "0.7.6" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" dependencies = [ - "getrandom 0.2.8", + "cfg-if 1.0.0", "once_cell", "version_check", ] [[package]] name = "aho-corasick" -version = "0.7.20" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" +checksum = "0c378d78423fdad8089616f827526ee33c19f2fddbd5de1629152c9593ba4783" dependencies = [ "memchr", ] +[[package]] +name = "allocator-api2" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" + +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + [[package]] name = "android_system_properties" version = "0.1.5" @@ -37,6 +49,54 @@ dependencies = [ "libc", ] +[[package]] +name = "anstream" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f58811cfac344940f1a400b6e6231ce35171f614f26439e80f8c1465c5cc0c" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b84bf0a05bbb2a83e5eb6fa36bb6e87baa08193c35ff52bbf6b38d8af2890e46" + +[[package]] +name = "anstyle-parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "938874ff5980b03a87c5524b3ae5b59cf99b1d6bc836848df7bc5ada9643c333" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58f54d10c6dfa51283a066ceab3ec1ab78d13fae00aa49243a45e4571fb79dfd" +dependencies = [ + "anstyle", + "windows-sys", +] + [[package]] name = "autocfg" version = "1.1.0" @@ -46,7 +106,7 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "autopilot" version = "0.4.0" -source = "git+https://github.com/jtschuster/autopilot-rs#cedea5b5371768d136b8eecd77ce26040fa4c675" +source = "git+https://github.com/autopilot-rs/autopilot-rs#ae5263bfde2e9de1ff0a59c4db6a4a4e8aacb3b9" dependencies = [ "cocoa", "core-foundation", @@ -74,9 +134,9 @@ checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" [[package]] name = "bumpalo" -version = "3.12.0" +version = "3.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" +checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" [[package]] name = "byteorder" @@ -86,9 +146,12 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "cc" -version = "1.0.79" +version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +dependencies = [ + "libc", +] [[package]] name = "cfg-if" @@ -104,55 +167,57 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.23" +version = "0.4.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f" +checksum = "defd4e7873dbddba6c7c91e199c7fcb946abc4a6a4ac3195400bcfb01b5de877" dependencies = [ + "android-tzdata", "iana-time-zone", "js-sys", - "num-integer", "num-traits", - "time", "wasm-bindgen", - "winapi", + "windows-targets", ] [[package]] name = "clap" -version = "4.1.7" +version = "4.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f3061d6db6d8fcbbd4b05e057f2acace52e64e96b498c08c2d7a4e65addd340" +checksum = "6a13b88d2c62ff462f88e4a121f17a82c1af05693a2f192b5c38d14de73c19f6" dependencies = [ - "bitflags", + "clap_builder", "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bb9faaa7c2ef94b2743a21f5a29e6f0010dff4caa69ac8e9d6cf8b6fa74da08" +dependencies = [ + "anstream", + "anstyle", "clap_lex", - "is-terminal", - "once_cell", "strsim", - "termcolor", ] [[package]] name = "clap_derive" -version = "4.1.7" +version = "4.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34d122164198950ba84a918270a3bb3f7ededd25e15f7451673d986f55bd2667" +checksum = "0862016ff20d69b84ef8247369fabf5c008a7417002411897d40ee1f4532b873" dependencies = [ "heck", - "proc-macro-error", - "proc-macro2 1.0.51", - "quote 1.0.23", - "syn 1.0.109", + "proc-macro2 1.0.66", + "quote 1.0.33", + "syn 2.0.32", ] [[package]] name = "clap_lex" -version = "0.3.2" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "350b9cf31731f9957399229e9b2adc51eeabdfbe9d71d9a0552275fd12710d09" -dependencies = [ - "os_str_bytes", -] +checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961" [[package]] name = "cocoa" @@ -169,22 +234,18 @@ dependencies = [ "objc", ] -[[package]] -name = "codespan-reporting" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" -dependencies = [ - "termcolor", - "unicode-width", -] - [[package]] name = "color_quant" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + [[package]] name = "core-foundation" version = "0.7.0" @@ -203,9 +264,9 @@ checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" [[package]] name = "core-foundation-sys" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" +checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" [[package]] name = "core-graphics" @@ -230,9 +291,9 @@ dependencies = [ [[package]] name = "crossbeam-channel" -version = "0.5.6" +version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521" +checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" dependencies = [ "cfg-if 1.0.0", "crossbeam-utils", @@ -240,9 +301,9 @@ dependencies = [ [[package]] name = "crossbeam-deque" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "715e8152b692bba2d374b53d4875445368fdf21a94751410af607a5ac677d1fc" +checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef" dependencies = [ "cfg-if 1.0.0", "crossbeam-epoch", @@ -251,9 +312,9 @@ dependencies = [ [[package]] name = "crossbeam-epoch" -version = "0.9.13" +version = "0.9.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01a9af1f4c2ef74bb8aa1f7e19706bc72d03598c8a570bb5de72243c7a9d9d5a" +checksum = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7" dependencies = [ "autocfg", "cfg-if 1.0.0", @@ -264,9 +325,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.14" +version = "0.8.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb766fa798726286dbbb842f174001dab8abc7b627a1dd86e0b7222a95d929f" +checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" dependencies = [ "cfg-if 1.0.0", ] @@ -290,18 +351,18 @@ dependencies = [ [[package]] name = "crossterm_winapi" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ae1b35a484aa10e07fe0638d02301c5ad24de82d310ccbd2f3693da5f09bf1c" +checksum = "acdd7c62a3665c7f6830a51635d9ac9b23ed385797f70a83bb8bafe9c572ab2b" dependencies = [ "winapi", ] [[package]] name = "csv" -version = "1.2.0" +version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af91f40b7355f82b0a891f50e70399475945bb0b0da4f1700ce60761c9d3e359" +checksum = "626ae34994d3d8d668f4269922248239db4ae42d538b14c398b74a52208e8086" dependencies = [ "csv-core", "itoa", @@ -318,50 +379,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "cxx" -version = "1.0.91" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86d3488e7665a7a483b57e25bdd90d0aeb2bc7608c8d0346acf2ad3f1caf1d62" -dependencies = [ - "cc", - "cxxbridge-flags", - "cxxbridge-macro", - "link-cplusplus", -] - -[[package]] -name = "cxx-build" -version = "1.0.91" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48fcaf066a053a41a81dfb14d57d99738b767febb8b735c3016e469fac5da690" -dependencies = [ - "cc", - "codespan-reporting", - "once_cell", - "proc-macro2 1.0.51", - "quote 1.0.23", - "scratch", - "syn 1.0.109", -] - -[[package]] -name = "cxxbridge-flags" -version = "1.0.91" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2ef98b8b717a829ca5603af80e1f9e2e48013ab227b68ef37872ef84ee479bf" - -[[package]] -name = "cxxbridge-macro" -version = "1.0.91" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "086c685979a698443656e5cf7856c95c642295a38599f12fb1ff76fb28d19892" -dependencies = [ - "proc-macro2 1.0.51", - "quote 1.0.23", - "syn 1.0.109", -] - [[package]] name = "deflate" version = "0.7.20" @@ -425,30 +442,9 @@ dependencies = [ [[package]] name = "either" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" - -[[package]] -name = "errno" -version = "0.2.8" +version = "1.9.0" 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", -] +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" [[package]] name = "fallible-iterator" @@ -501,9 +497,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.8" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" +checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" dependencies = [ "cfg-if 1.0.0", "libc", @@ -522,18 +518,19 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.12.3" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" dependencies = [ "ahash", + "allocator-api2", ] [[package]] name = "hashlink" -version = "0.8.1" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69fe1fcf8b4278d860ad0548329f892a3631fb63f82574df68275f34cdbe0ffa" +checksum = "e8094feaf31ff591f651a2664fb9cfd92bba7a60ce3197265e9482ebe753c8f7" dependencies = [ "hashbrown", ] @@ -546,18 +543,9 @@ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "hermit-abi" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" -dependencies = [ - "libc", -] - -[[package]] -name = "hermit-abi" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" +checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" [[package]] name = "humantime" @@ -567,26 +555,25 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "iana-time-zone" -version = "0.1.53" +version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64c122667b287044802d6ce17ee2ddf13207ed924c712de9a66a5814d5b64765" +checksum = "2fad5b825842d2b38bd206f3e81d6957625fd7f0a361e345c30e01a0ae2dd613" dependencies = [ "android_system_properties", - "core-foundation-sys 0.8.3", + "core-foundation-sys 0.8.4", "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "winapi", + "windows", ] [[package]] name = "iana-time-zone-haiku" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0703ae284fc167426161c2e3f1da3ea71d94b21bedbcc9494e92b28e334e3dca" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" dependencies = [ - "cxx", - "cxx-build", + "cc", ] [[package]] @@ -615,28 +602,6 @@ dependencies = [ "adler32", ] -[[package]] -name = "io-lifetimes" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1abeb7a0dd0f8181267ff8adc397075586500b81b28a73e8a0208b00fc170fb3" -dependencies = [ - "libc", - "windows-sys", -] - -[[package]] -name = "is-terminal" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21b6b32576413a8e69b90e952e4a026476040d81017b80445deda5f2d3921857" -dependencies = [ - "hermit-abi 0.3.1", - "io-lifetimes", - "rustix", - "windows-sys", -] - [[package]] name = "itertools" version = "0.10.5" @@ -648,9 +613,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.5" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440" +checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" [[package]] name = "jpeg-decoder" @@ -663,18 +628,18 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.61" +version = "0.3.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730" +checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a" dependencies = [ "wasm-bindgen", ] [[package]] name = "libc" -version = "0.2.139" +version = "0.2.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" +checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" [[package]] name = "libsqlite3-sys" @@ -687,26 +652,11 @@ dependencies = [ "vcpkg", ] -[[package]] -name = "link-cplusplus" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecd207c9c713c34f95a097a5b029ac2ce6010530c7b49d7fea24d977dede04f5" -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 = "lock_api" -version = "0.4.9" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" +checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" dependencies = [ "autocfg", "scopeguard", @@ -714,12 +664,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.17" +version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" -dependencies = [ - "cfg-if 1.0.0", -] +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" [[package]] name = "lzw" @@ -738,7 +685,7 @@ dependencies = [ [[package]] name = "mcfly" -version = "0.7.1" +version = "0.8.1" dependencies = [ "autopilot", "chrono", @@ -753,6 +700,7 @@ dependencies = [ "path-absolutize", "rand 0.8.5", "regex", + "relative-path", "rusqlite", "shellexpand", "unicode-segmentation", @@ -760,24 +708,24 @@ dependencies = [ [[package]] name = "memchr" -version = "2.5.0" +version = "2.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +checksum = "8f232d6ef707e1956a43342693d2a31e72989554d58299d7a88738cc95b0d35c" [[package]] name = "memoffset" -version = "0.7.1" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4" +checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c" dependencies = [ "autocfg", ] [[package]] name = "mio" -version = "0.8.6" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b9d9a46eff5b4ff64b45a9e316a6d1e0bc719ef429cbec4dc630684212bfdf9" +checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" dependencies = [ "libc", "log", @@ -830,20 +778,20 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2" dependencies = [ "autocfg", ] [[package]] name = "num_cpus" -version = "1.15.0" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi 0.2.6", + "hermit-abi", "libc", ] @@ -858,15 +806,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.17.1" +version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" - -[[package]] -name = "os_str_bytes" -version = "6.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" [[package]] name = "parking_lot" @@ -880,40 +822,40 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.7" +version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521" +checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447" dependencies = [ "cfg-if 1.0.0", "libc", - "redox_syscall", + "redox_syscall 0.3.5", "smallvec", - "windows-sys", + "windows-targets", ] [[package]] name = "path-absolutize" -version = "3.0.14" +version = "3.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f1d4993b16f7325d90c18c3c6a3327db7808752db8d208cea0acee0abd52c52" +checksum = "e4af381fe79fa195b4909485d99f73a80792331df0625188e707854f0b3383f5" dependencies = [ "path-dedot", ] [[package]] name = "path-dedot" -version = "3.0.18" +version = "3.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a81540d94551664b72b72829b12bd167c73c9d25fbac0e04fafa8023f7e4901" +checksum = "07ba0ad7e047712414213ff67533e6dd477af0a4e1d14fb52343e53d30ea9397" dependencies = [ "once_cell", ] [[package]] name = "pkg-config" -version = "0.3.26" +version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" +checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" [[package]] name = "png" @@ -933,30 +875,6 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" -[[package]] -name = "proc-macro-error" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" -dependencies = [ - "proc-macro-error-attr", - "proc-macro2 1.0.51", - "quote 1.0.23", - "syn 1.0.109", - "version_check", -] - -[[package]] -name = "proc-macro-error-attr" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" -dependencies = [ - "proc-macro2 1.0.51", - "quote 1.0.23", - "version_check", -] - [[package]] name = "proc-macro2" version = "0.4.30" @@ -968,9 +886,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.51" +version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6" +checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" dependencies = [ "unicode-ident", ] @@ -986,11 +904,11 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.23" +version = "1.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" dependencies = [ - "proc-macro2 1.0.51", + "proc-macro2 1.0.66", ] [[package]] @@ -1052,7 +970,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom 0.2.8", + "getrandom 0.2.10", ] [[package]] @@ -1066,9 +984,9 @@ dependencies = [ [[package]] name = "rayon" -version = "1.6.1" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6db3a213adf02b3bcfd2d3846bb41cb22857d131789e01df434fb7e7bc0759b7" +checksum = "1d2df5196e37bcc87abebc0053e20787d73847bb33134a69841207dd0a47f03b" dependencies = [ "either", "rayon-core", @@ -1076,9 +994,9 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.10.2" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "356a0625f1954f730c0201cdab48611198dc6ce21f4acff55089b5a78e6e835b" +checksum = "4b8f95bd6966f5c87776639160a66bd8ab9895d9d4ab01ddba9fc60661aebe8d" dependencies = [ "crossbeam-channel", "crossbeam-deque", @@ -1095,22 +1013,43 @@ dependencies = [ "bitflags", ] +[[package]] +name = "redox_syscall" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" +dependencies = [ + "bitflags", +] + [[package]] name = "redox_users" version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" dependencies = [ - "getrandom 0.2.8", - "redox_syscall", + "getrandom 0.2.10", + "redox_syscall 0.2.16", "thiserror", ] [[package]] name = "regex" -version = "1.7.1" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" +checksum = "697061221ea1b4a94a624f67d0ae2bfe4e22b8a17b6a192afb11046542cc8c47" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2f401f4955220693b56f8ec66ee9c78abffd8d1c4f23dc41a23839eb88f0795" dependencies = [ "aho-corasick", "memchr", @@ -1119,9 +1058,15 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.28" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" + +[[package]] +name = "relative-path" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" +checksum = "c707298afce11da2efef2f600116fa93ffa7a032b5d7b628aa17711ec81383ca" [[package]] name = "rusqlite" @@ -1137,25 +1082,11 @@ dependencies = [ "smallvec", ] -[[package]] -name = "rustix" -version = "0.36.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f43abb88211988493c1abb44a70efa56ff0ce98f233b7b276146f1f3f7ba9644" -dependencies = [ - "bitflags", - "errno", - "io-lifetimes", - "libc", - "linux-raw-sys", - "windows-sys", -] - [[package]] name = "ryu" -version = "1.0.12" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde" +checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" [[package]] name = "scoped_threadpool" @@ -1165,21 +1096,29 @@ checksum = "1d51f5df5af43ab3f1360b429fa5e0152ac5ce8c0bd6485cae490332e96846a8" [[package]] name = "scopeguard" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] -name = "scratch" -version = "1.0.3" +name = "serde" +version = "1.0.188" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddccb15bcce173023b3fedd9436f882a0739b8dfb45e4f6b6002bee5929f61b2" +checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" +dependencies = [ + "serde_derive", +] [[package]] -name = "serde" -version = "1.0.152" +name = "serde_derive" +version = "1.0.188" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" +checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" +dependencies = [ + "proc-macro2 1.0.66", + "quote 1.0.33", + "syn 2.0.32", +] [[package]] name = "shellexpand" @@ -1192,9 +1131,9 @@ dependencies = [ [[package]] name = "signal-hook" -version = "0.3.15" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "732768f1176d21d09e076c23a93123d40bba92d50c4058da34d45c8de8e682b9" +checksum = "8621587d4798caf8eb44879d42e56b9a93ea5dcd315a6487c357130095b62801" dependencies = [ "libc", "signal-hook-registry", @@ -1222,9 +1161,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.10.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" [[package]] name = "strsim" @@ -1245,42 +1184,33 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.109" +version = "2.0.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +checksum = "239814284fd6f1a4ffe4ca893952cdd93c224b6a1571c9a9eadd670295c0c9e2" dependencies = [ - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.66", + "quote 1.0.33", "unicode-ident", ] -[[package]] -name = "termcolor" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" -dependencies = [ - "winapi-util", -] - [[package]] name = "thiserror" -version = "1.0.38" +version = "1.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0" +checksum = "9d6d7a740b8a666a7e828dd00da9c0dc290dff53154ea77ac109281de90589b7" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.38" +version = "1.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f" +checksum = "49922ecae66cc8a249b77e68d1d0623c1b2c514f0060c27cdc68bd62a1219d35" dependencies = [ - "proc-macro2 1.0.51", - "quote 1.0.23", - "syn 1.0.109", + "proc-macro2 1.0.66", + "quote 1.0.33", + "syn 2.0.32", ] [[package]] @@ -1295,22 +1225,11 @@ dependencies = [ "num-traits", ] -[[package]] -name = "time" -version = "0.1.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" -dependencies = [ - "libc", - "wasi 0.10.0+wasi-snapshot-preview1", - "winapi", -] - [[package]] name = "unicode-ident" -version = "1.0.6" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" +checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" [[package]] name = "unicode-segmentation" @@ -1318,18 +1237,18 @@ version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" -[[package]] -name = "unicode-width" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" - [[package]] name = "unicode-xid" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + [[package]] name = "vcpkg" version = "0.2.15" @@ -1348,12 +1267,6 @@ version = "0.9.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" -[[package]] -name = "wasi" -version = "0.10.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -1362,9 +1275,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.84" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" +checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342" dependencies = [ "cfg-if 1.0.0", "wasm-bindgen-macro", @@ -1372,47 +1285,47 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.84" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9" +checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" dependencies = [ "bumpalo", "log", "once_cell", - "proc-macro2 1.0.51", - "quote 1.0.23", - "syn 1.0.109", + "proc-macro2 1.0.66", + "quote 1.0.33", + "syn 2.0.32", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.84" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" +checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" dependencies = [ - "quote 1.0.23", + "quote 1.0.33", "wasm-bindgen-macro-support", ] [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.84" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" +checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ - "proc-macro2 1.0.51", - "quote 1.0.23", - "syn 1.0.109", + "proc-macro2 1.0.66", + "quote 1.0.33", + "syn 2.0.32", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.84" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" +checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" [[package]] name = "winapi" @@ -1430,35 +1343,35 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -[[package]] -name = "winapi-util" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" -dependencies = [ - "winapi", -] - [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-sys" -version = "0.45.0" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ "windows-targets", ] [[package]] name = "windows-targets" -version = "0.42.1" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", @@ -1471,45 +1384,45 @@ dependencies = [ [[package]] name = "windows_aarch64_gnullvm" -version = "0.42.1" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_msvc" -version = "0.42.1" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_i686_gnu" -version = "0.42.1" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_msvc" -version = "0.42.1" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_x86_64_gnu" -version = "0.42.1" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnullvm" -version = "0.42.1" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_msvc" -version = "0.42.1" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "x11" diff --git a/Cargo.toml b/Cargo.toml index f9540b47..64d8acba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mcfly" -version = "0.7.1" +version = "0.8.1" authors = ["Andrew Cantino "] edition = "2021" description = "McFly replaces your default ctrl-r shell history search with an intelligent search engine that takes into account your working directory and the context of recently executed commands. McFly's suggestions are prioritized in real time with a small neural network." @@ -23,20 +23,20 @@ humantime = "2.1" directories-next = "2.0" itertools = "0.10" rand = "0.8" -regex = "1" path-absolutize = "3.0.13" +regex = { version = "1", default-features = false, features = ["perf", "std"] } +relative-path = "1.7" shellexpand = "2.1" unicode-segmentation = "1.9" [dependencies.rusqlite] version = "0.28" -features = ["bundled", "functions", "unlock_notify"] +features = ["functions", "unlock_notify"] [dependencies.crossterm] version = "0.26" features = ["use-dev-tty"] - [dependencies.clap] version = "4" features = ["derive"] @@ -45,4 +45,8 @@ features = ["derive"] libc = "0.2" [target.'cfg(windows)'.dependencies] -autopilot = {git="https://github.com/jtschuster/autopilot-rs"} +autopilot = {git="https://github.com/autopilot-rs/autopilot-rs"} + +[features] +default = ["sqlite-bundled"] +sqlite-bundled = ["rusqlite/bundled"] diff --git a/README.md b/README.md index 8d34f2d9..773384a8 100644 --- a/README.md +++ b/README.md @@ -271,6 +271,19 @@ fish: set -gx MCFLY_RESULTS 50 ``` +### Delete without confirmation +To delete without confirmation, set `MCFLY_DELETE_WITHOUT_CONFIRM` to true. + +bash / zsh: +```bash +export MCFLY_DELETE_WITHOUT_CONFIRM=true +``` + +fish: +```bash +set -gx MCFLY_DELETE_WITHOUT_CONFIRM true +``` + ### Interface view To change interface view, set `MCFLY_INTERFACE_VIEW` (default: `TOP`). Available options: `TOP` and `BOTTOM` @@ -324,6 +337,7 @@ fish: ```bash set -gx MCFLY_PROMPT "❯" ``` +Note that only single-character-prompts are allowed. setting `MCFLY_PROMPT` to `""` will reset it to the default prompt. ### Database Location diff --git a/mcfly.fish b/mcfly.fish index 7fe5a584..1d0ee9b6 100644 --- a/mcfly.fish +++ b/mcfly.fish @@ -31,7 +31,9 @@ if test "$__MCFLY_LOADED" != "loaded" end function __mcfly_add_command -d 'Add run commands to McFly database' -e fish_postexec - # First, retain return code of last command before we lose it + # Check for the private mode + test -n "$fish_private_mode"; and return + # Retain return code of last command before we lose it set -l last_status $status # Handle first call of this function after sourcing mcfly.fish, when the old PWD won't be set set -q __MCFLY_OLD_PWD; or set -g __MCFLY_OLD_PWD "$PWD" diff --git a/mcfly.ps1 b/mcfly.ps1 index c71a67e6..d69fd632 100644 --- a/mcfly.ps1 +++ b/mcfly.ps1 @@ -16,7 +16,7 @@ $null = New-Module mcfly { } # Get history file and make a dummy file for psreadline (hopefully after it has loaded the real history file to its in memory history) - $env:HISTFILE = $null -eq $env:HISTFILE ? (Get-PSReadLineOption).HistorySavePath : $env:HISTFILE; + $env:HISTFILE = $null -eq $env:HISTFILE -or "" -eq $env:HISTFILE ? (Get-PSReadLineOption).HistorySavePath : $env:HISTFILE; $_PSREADLINEHISTORY = (Get-PSReadLineOption).HistorySavePath $psreadline_dummy = New-TemporaryFile Set-PSReadLineOption -HistorySavePath $psreadline_dummy.FullName diff --git a/mcfly.zsh b/mcfly.zsh index c91ccecf..6c480447 100644 --- a/mcfly.zsh +++ b/mcfly.zsh @@ -1,9 +1,7 @@ #!/bin/zsh # Ensure stdin is a tty -# Avoid loading this file more than once -if [[ -o interactive ]] && [[ "$__MCFLY_LOADED" != "loaded" ]]; then - __MCFLY_LOADED="loaded" +if [[ -o interactive ]]; then # Setup MCFLY_HISTFILE and make sure it exists. export MCFLY_HISTFILE="${HISTFILE:-$HOME/.zsh_history}" @@ -26,9 +24,7 @@ if [[ -o interactive ]] && [[ "$__MCFLY_LOADED" != "loaded" ]]; then setopt interactive_comments # allow comments in interactive shells (like Bash does) # McFly's temporary, per-session history file. - if [[ ! -f "${MCFLY_HISTORY}" ]]; then - export MCFLY_HISTORY=$(command mktemp ${TMPDIR:-/tmp}/mcfly.XXXXXXXX) - fi + export MCFLY_HISTORY=$(command mktemp ${TMPDIR:-/tmp}/mcfly.XXXXXXXX) # Check if we need to use extended history if [[ -o extendedhistory ]]; then @@ -55,14 +51,24 @@ if [[ -o interactive ]] && [[ "$__MCFLY_LOADED" != "loaded" ]]; then $MCFLY_PATH --history_format $MCFLY_HISTORY_FORMAT add --exit ${exit_code} return ${exit_code} # Restore the original exit code by returning it. } - precmd_functions+=(mcfly_prompt_command) + + if [[ -z $precmd_functions ]] || [[ "${precmd_functions[(ie)mcfly_prompt_command]}" -gt ${#precmd_functions} ]]; then + precmd_functions+=(mcfly_prompt_command) + else + [ -n "$MCFLY_DEBUG" ] && echo "mcfly_prompt_command already in precmd_functions, skipping" + fi # Cleanup $MCFLY_HISTORY tmp files on exit. - exit_logger() { + mcfly_exit_logger() { [ -n "$MCFLY_DEBUG" ] && echo "mcfly.zsh: Exiting and removing $MCFLY_HISTORY" command rm -f $MCFLY_HISTORY } - zshexit_functions+=(exit_logger) + + if [[ -z $zshexit_functions ]] || [[ "${zshexit_functions[(ie)mcfly_exit_logger]}" -gt ${#zshexit_functions} ]]; then + zshexit_functions+=(mcfly_exit_logger) + else + [ -n "$MCFLY_DEBUG" ] && echo "mcfly_exit_logger already in zshexit_functions, skipping" + fi # If this is an interactive shell, take ownership of ctrl-r. if [[ $- =~ .*i.* ]]; then diff --git a/pkg/brew/mcfly.rb b/pkg/brew/mcfly.rb index b818543f..609bbbd1 100644 --- a/pkg/brew/mcfly.rb +++ b/pkg/brew/mcfly.rb @@ -7,16 +7,16 @@ # brew untap cantino/mcfly class Mcfly < Formula - version 'v0.7.1' + version 'v0.8.1' desc "McFly" homepage "https://github.com/cantino/mcfly" if OS.mac? url "https://github.com/cantino/mcfly/releases/download/#{version}/mcfly-#{version}-x86_64-apple-darwin.tar.gz" - sha256 "2d62398984b908ca06403f6ed9198702e8e193799fef57c9b7d38e69b7b4a33d" + sha256 "db8d125c040fa9f97ba9b7777d1109ff2598db386f42e79e24aef66556500c11" elsif OS.linux? url "https://github.com/cantino/mcfly/releases/download/#{version}/mcfly-#{version}-x86_64-unknown-linux-musl.tar.gz" - sha256 "76c54d1b320aaf39f2f65e628615e3eaa2a56f94dce8547e542b7ec94a3c9346" + sha256 "31231a4085f73eef41ab222e08518b7912cce55e7c1396931818a0fbfacf4fef" end def install diff --git a/src/history/history.rs b/src/history/history.rs index 39f44d89..92363cbb 100644 --- a/src/history/history.rs +++ b/src/history/history.rs @@ -10,7 +10,7 @@ use std::{fmt, fs, io}; use crate::history::{db_extensions, schema}; use crate::network::Network; use crate::path_update_helpers; -use crate::settings::{HistoryFormat, ResultSort, Settings}; +use crate::settings::{HistoryFormat, ResultFilter, ResultSort, Settings}; use crate::simplified_command::SimplifiedCommand; use itertools::Itertools; use rusqlite::types::ToSql; @@ -442,9 +442,11 @@ impl History { names } + #[allow(clippy::too_many_arguments)] pub fn build_cache_table( &self, dir: &str, + result_filter: &ResultFilter, session_id: &Option, start_time: Option, end_time: Option, @@ -524,6 +526,11 @@ impl History { 0 }; + let dir_filter_off = match &result_filter { + ResultFilter::Global => true, + ResultFilter::CurrentDirectory => false, + }; + self.connection.execute( "CREATE TEMP TABLE contextual_commands AS SELECT id, cmd, cmd_tpl, session_id, when_run, MAX(when_run) AS last_run, exit_code, selected, dir, @@ -565,13 +572,14 @@ impl History { COUNT(*) / :max_occurrences AS occurrences_factor FROM commands c - WHERE id > :min_id AND when_run > :start_time AND when_run < :end_time + WHERE id > :min_id AND when_run > :start_time AND when_run < :end_time AND (:dir_filter_off OR dir LIKE :directory) GROUP BY cmd ORDER BY id DESC;", named_params! { ":when_run_max": &when_run_max, ":history_duration": &(when_run_max - when_run_min), ":directory": &dir.to_owned(), + ":dir_filter_off": &dir_filter_off, ":max_occurrences": &max_occurrences, ":max_length": &max_length, ":max_selected_occurrences": &max_selected_occurrences, diff --git a/src/interface.rs b/src/interface.rs index 66ef017b..00a847dd 100644 --- a/src/interface.rs +++ b/src/interface.rs @@ -4,7 +4,7 @@ use crate::history::History; use crate::fixed_length_grapheme_string::FixedLengthGraphemeString; use crate::history::Command; use crate::history_cleaner; -use crate::settings::{InterfaceView, KeyScheme}; +use crate::settings::{InterfaceView, KeyScheme, ResultFilter}; use crate::settings::{ResultSort, Settings}; use chrono::{Duration, TimeZone, Utc}; use crossterm::event::KeyCode::Char; @@ -29,6 +29,7 @@ pub struct Interface<'a> { menu_mode: MenuMode, in_vim_insert_mode: bool, result_sort: ResultSort, + result_filter: ResultFilter, } pub struct SelectionResult { @@ -77,11 +78,17 @@ impl MenuMode { } match interface.result_sort { - ResultSort::Rank => menu_text.push_str("F1 - Switch Sort to Time | "), - ResultSort::LastRun => menu_text.push_str("F1 - Switch Sort to Rank | "), + ResultSort::Rank => menu_text.push_str("F1 - Rank Sort | "), + ResultSort::LastRun => menu_text.push_str("F1 - Time Sort | "), + } + + menu_text.push_str("F2 - Delete | "); + + match interface.result_filter { + ResultFilter::Global => menu_text.push_str("F3 - All Directories"), + ResultFilter::CurrentDirectory => menu_text.push_str("F3 - This Directory"), } - menu_text.push_str("F2 - Delete"); menu_text } @@ -111,6 +118,7 @@ impl<'a> Interface<'a> { menu_mode: MenuMode::Normal, in_vim_insert_mode: true, result_sort: settings.result_sort.to_owned(), + result_filter: settings.result_filter.to_owned(), } } @@ -144,6 +152,7 @@ impl<'a> Interface<'a> { fn build_cache_table(&self) { self.history.build_cache_table( &self.settings.dir.to_owned(), + &self.result_filter, &Some(self.settings.session_id.to_owned()), None, None, @@ -153,24 +162,26 @@ impl<'a> Interface<'a> { } fn menubar(&self, screen: &mut W) { - let (width, _height): (u16, u16) = terminal::size().unwrap(); + if !self.settings.disable_menu { + let (width, _height): (u16, u16) = terminal::size().unwrap(); - queue!( - screen, - cursor::Hide, - cursor::MoveTo(0, self.info_line_index()), - Clear(ClearType::CurrentLine), - SetBackgroundColor(self.menu_mode.bg()), - SetForegroundColor(Color::White), - cursor::MoveTo(1, self.info_line_index()), - Print(format!( - "{text:width$}", - text = self.menu_mode.text(self), - width = width as usize - 1 - )), - SetBackgroundColor(Color::Reset) - ) - .unwrap(); + queue!( + screen, + cursor::Hide, + cursor::MoveTo(0, self.info_line_index()), + Clear(ClearType::CurrentLine), + SetBackgroundColor(self.menu_mode.bg()), + SetForegroundColor(Color::White), + cursor::MoveTo(1, self.info_line_index()), + Print(format!( + "{text:width$}", + text = self.menu_mode.text(self), + width = width as usize - 1 + )), + SetBackgroundColor(Color::Reset) + ) + .unwrap(); + } } fn prompt(&self, screen: &mut W) { @@ -416,10 +427,18 @@ impl<'a> Interface<'a> { } } + fn switch_result_filter(&mut self) { + self.result_filter = match self.result_filter { + ResultFilter::Global => ResultFilter::CurrentDirectory, + ResultFilter::CurrentDirectory => ResultFilter::Global, + }; + self.build_cache_table(); + } + fn select(&mut self) { let mut screen = stdout(); terminal::enable_raw_mode().unwrap(); - queue!(screen, EnterAlternateScreen).unwrap(); + queue!(screen, EnterAlternateScreen, Clear(ClearType::All)).unwrap(); self.refresh_matches(true); self.results(&mut screen); @@ -491,7 +510,7 @@ impl<'a> Interface<'a> { } fn select_with_emacs_key_scheme(&mut self, event: KeyEvent) -> bool { - if event.kind == KeyEventKind::Release { + if event.kind != KeyEventKind::Press { return false; } match event { @@ -665,6 +684,13 @@ impl<'a> Interface<'a> { } } + KeyEvent { + code: KeyCode::F(3), + .. + } => { + self.switch_result_filter(); + self.refresh_matches(true); + } _ => {} } @@ -820,6 +846,7 @@ impl<'a> Interface<'a> { self.input.clear(); return true; } + KeyEvent { code: KeyCode::Left | Char('h'), .. diff --git a/src/settings.rs b/src/settings.rs index 1fe1b7f9..1f65a838 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -43,6 +43,12 @@ pub enum ResultSort { LastRun, } +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum ResultFilter { + Global, + CurrentDirectory, +} + #[derive(Debug, Clone, Copy)] pub enum HistoryFormat { /// bash format - commands in plain text, one per line, with multi-line commands joined. @@ -86,6 +92,7 @@ pub struct Settings { pub delete_without_confirm: bool, pub interface_view: InterfaceView, pub result_sort: ResultSort, + pub result_filter: ResultFilter, pub disable_menu: bool, pub prompt: String, pub disable_run_command: bool, @@ -117,6 +124,7 @@ impl Default for Settings { delete_without_confirm: false, interface_view: InterfaceView::Top, result_sort: ResultSort::Rank, + result_filter: ResultFilter::Global, disable_menu: false, prompt: String::from("$"), disable_run_command: false, @@ -139,7 +147,7 @@ impl Settings { .and_then(|o| o.parse::().ok()); settings.interface_view = match env::var("MCFLY_INTERFACE_VIEW") { - Ok(val) => match val.as_str() { + Ok(val) => match val.to_uppercase().as_str() { "TOP" => InterfaceView::Top, "BOTTOM" => InterfaceView::Bottom, _ => InterfaceView::Top, @@ -148,7 +156,7 @@ impl Settings { }; settings.result_sort = match env::var("MCFLY_RESULTS_SORT") { - Ok(val) => match val.as_str() { + Ok(val) => match val.to_uppercase().as_str() { "RANK" => ResultSort::Rank, "LAST_RUN" => ResultSort::LastRun, _ => ResultSort::Rank, @@ -156,6 +164,15 @@ impl Settings { _ => ResultSort::Rank, }; + settings.result_filter = match env::var("MCFLY_RESULTS_FILTER") { + Ok(val) => match val.to_uppercase().as_str() { + "GLOBAL" => ResultFilter::Global, + "CURRENT_DIRECTORY" => ResultFilter::CurrentDirectory, + _ => ResultFilter::Global, + }, + _ => ResultFilter::Global, + }; + settings.session_id = cli.session_id.unwrap_or_else(|| env::var("MCFLY_SESSION_ID") .unwrap_or_else(|err| { diff --git a/src/shell_history.rs b/src/shell_history.rs index a5eb5924..8fc83042 100644 --- a/src/shell_history.rs +++ b/src/shell_history.rs @@ -117,7 +117,7 @@ pub fn full_history(path: &Path, history_format: HistoryFormat) -> Vec { let history_contents = read_ignoring_utf_errors(path); - let zsh_timestamp_and_duration_regex = Regex::new(r"^: \d+:\d+;").unwrap(); + let zsh_timestamp_and_duration_regex = Regex::new(r"^: [0-9]+:[0-9]+;").unwrap(); let when = SystemTime::now() .duration_since(UNIX_EPOCH) .unwrap_or_else(|err| panic!("McFly error: Time went backwards ({})", err)) @@ -131,7 +131,7 @@ pub fn full_history(path: &Path, history_format: HistoryFormat) -> Vec { let history_contents = read_and_unmetafy(path); - let zsh_timestamp_and_duration_regex = Regex::new(r"^: \d+:\d+;").unwrap(); + let zsh_timestamp_and_duration_regex = Regex::new(r"^: [0-9]+:[0-9]+;").unwrap(); let when = SystemTime::now() .duration_since(UNIX_EPOCH) .unwrap_or_else(|err| panic!("McFly error: Time went backwards ({})", err)) @@ -192,7 +192,7 @@ pub fn delete_last_history_entry_if_search( commands.pop(); } - let starts_with_mcfly = Regex::new(r"^(: \d+:\d+;)?#mcfly:").unwrap(); + let starts_with_mcfly = Regex::new(r"^(: [0-9]+:[0-9]+;)?#mcfly:").unwrap(); if commands.is_empty() || !starts_with_mcfly.is_match(&commands[commands.len() - 1].command) { return; // Abort if empty or the last line isn't a comment. @@ -226,7 +226,7 @@ pub fn delete_last_history_entry_if_search( pub fn delete_lines(path: &Path, history_format: HistoryFormat, command: &str) { let commands = full_history(path, history_format); - let zsh_timestamp_and_duration_regex = Regex::new(r"^: \d+:\d+;").unwrap(); + let zsh_timestamp_and_duration_regex = Regex::new(r"^: [0-9]+:[0-9]+;").unwrap(); let lines = commands .into_iter() diff --git a/src/training_sample_generator.rs b/src/training_sample_generator.rs index fd98c088..e9b3ecdf 100644 --- a/src/training_sample_generator.rs +++ b/src/training_sample_generator.rs @@ -1,7 +1,7 @@ use crate::history::Command; use crate::history::Features; use crate::history::History; -use crate::settings::Settings; +use crate::settings::{ResultFilter, Settings}; use crate::training_cache; use rand::seq::IteratorRandom; use std::fs; @@ -55,6 +55,7 @@ impl TrainingSampleGenerator { // Unwrap is safe here because we check command.dir.is_none() above. history.build_cache_table( &command.dir.to_owned().unwrap(), + &ResultFilter::Global, &Some(command.session_id.clone()), None, command.when_run, From 26719611ea6a40a5965287457c3a84fd47ae3260 Mon Sep 17 00:00:00 2001 From: Jackson Schuster Date: Tue, 12 Sep 2023 09:59:20 -0500 Subject: [PATCH 27/31] Add command to temp file by default instead of using autopilot --- mcfly.ps1 | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/mcfly.ps1 b/mcfly.ps1 index d69fd632..425b1a07 100644 --- a/mcfly.ps1 +++ b/mcfly.ps1 @@ -49,13 +49,25 @@ $null = New-Module mcfly { function Invoke-McFly { Param([string]$CommandToComplete) $lastExitTmp = $LASTEXITCODE - Start-Process -FilePath '::MCFLY::' -ArgumentList "search", "$CommandToComplete" -NoNewWindow -Wait - $LASTEXITCODE = $lastExitTmp - } - - function Invoke-McFly { - $lastExitTmp = $LASTEXITCODE - Start-Process -FilePath '::MCFLY::' -ArgumentList "search" -NoNewWindow -Wait + $tempFile = New-TemporaryFile + Start-Process -FilePath '::MCFLY::' -ArgumentList "search", "$CommandToComplete", -o, "$tempFile" -NoNewWindow -Wait + foreach($line in Get-Content $tempFile) { + $key, $value = $line -split ' ', 2 + if ("mode" -eq $key) { + $mode = $value + } + if ("commandline" -eq $key) { + $commandline = $value + } + } + if(-not ($null -eq $commandline)) { + [Microsoft.PowerShell.PSConsoleReadLine]::DeleteLine() + [Microsoft.PowerShell.PSConsoleReadline]::Insert($commandline) + if("run" -eq $mode) { + [Microsoft.PowerShell.PSConsoleReadline]::AcceptLine() + } + } + Remove-Item $tempFile $LASTEXITCODE = $lastExitTmp } @@ -102,9 +114,8 @@ $null = New-Module mcfly { $line = $null $cursor = $null [Microsoft.PowerShell.PSConsoleReadline]::GetBufferState([ref]$line, [ref]$cursor) - [Microsoft.PowerShell.PSConsoleReadLine]::DeleteLine() - "#mcfly: $line" | Out-File -FilePath $env:MCFLY_HISTORY -Append - Invoke-McFly + # "#mcfly: $line" | Out-File -FilePath $env:MCFLY_HISTORY -Append + Invoke-McFly -CommandToComplete $line } Export-ModuleMember -Function @( From 1f172600e8b6e06034877996e16ceb2b77471bfd Mon Sep 17 00:00:00 2001 From: Jackson Schuster Date: Tue, 12 Sep 2023 10:42:37 -0500 Subject: [PATCH 28/31] Always load mcfly, add blank line to mcfly history before call --- mcfly.ps1 | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/mcfly.ps1 b/mcfly.ps1 index 425b1a07..dcfe964a 100644 --- a/mcfly.ps1 +++ b/mcfly.ps1 @@ -1,14 +1,6 @@ #!/usr/bin/env pwsh -# Ensure stdin is a tty -# Can't - $null = New-Module mcfly { - if ($env:__MCFLY_LOADED -eq "loaded") { - return ; - } - $env:__MCFLY_LOADED = "loaded"; - # We need PSReadLine for a number of capabilities if ($null -eq (Get-Module -Name PSReadLine)) { Write-Host "Installing PSReadLine as McFly dependency" @@ -29,7 +21,6 @@ $null = New-Module mcfly { } # MCFLY_SESSION_ID is used by McFly internally to keep track of the commands from a particular terminal session. - $MCFLY_SESSION_ID = new-guid $env:MCFLY_SESSION_ID = $MCFLY_SESSION_ID @@ -114,7 +105,7 @@ $null = New-Module mcfly { $line = $null $cursor = $null [Microsoft.PowerShell.PSConsoleReadline]::GetBufferState([ref]$line, [ref]$cursor) - # "#mcfly: $line" | Out-File -FilePath $env:MCFLY_HISTORY -Append + "#mcfly: $line" | Out-File -FilePath $env:MCFLY_HISTORY -Append Invoke-McFly -CommandToComplete $line } From db36db480af2515afaff00eb6a6c1728431363ea Mon Sep 17 00:00:00 2001 From: Jackson Schuster Date: Tue, 12 Sep 2023 11:32:47 -0500 Subject: [PATCH 29/31] Remove Dirs dep, fix non-windows warning, add unwrap_or --- Cargo.lock | 41 +++++++++++--------------------------- Cargo.toml | 1 - mcfly.ps1 | 1 - src/path_update_helpers.rs | 3 ++- 4 files changed, 14 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 120ddb69..c6ed4854 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14,7 +14,7 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "once_cell", "version_check", ] @@ -153,12 +153,6 @@ dependencies = [ "libc", ] -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - [[package]] name = "cfg-if" version = "1.0.0" @@ -286,7 +280,7 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] @@ -295,7 +289,7 @@ version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "crossbeam-utils", ] @@ -305,7 +299,7 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "crossbeam-epoch", "crossbeam-utils", ] @@ -317,7 +311,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7" dependencies = [ "autocfg", - "cfg-if 1.0.0", + "cfg-if", "crossbeam-utils", "memoffset", "scopeguard", @@ -329,7 +323,7 @@ version = "0.8.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] @@ -395,20 +389,10 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "339ee130d97a610ea5a5872d2bbb130fdf68884ff09d3028b81bec8a1ac23bbc" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "dirs-sys-next", ] -[[package]] -name = "dirs" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13aea89a5c93364a98e9b37b2fa237effbb694d5cfe01c5b70941f7eb087d5e3" -dependencies = [ - "cfg-if 0.1.10", - "dirs-sys", -] - [[package]] name = "dirs" version = "4.0.0" @@ -490,7 +474,7 @@ version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "libc", "wasi 0.9.0+wasi-snapshot-preview1", ] @@ -501,7 +485,7 @@ version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "libc", "wasi 0.11.0+wasi-snapshot-preview1", ] @@ -693,7 +677,6 @@ dependencies = [ "crossterm", "csv", "directories-next", - "dirs 2.0.2", "humantime", "itertools", "libc", @@ -826,7 +809,7 @@ version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "libc", "redox_syscall 0.3.5", "smallvec", @@ -1126,7 +1109,7 @@ version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ccc8076840c4da029af4f87e4e8daeb0fca6b87bbb02e10cb60b791450e11e4" dependencies = [ - "dirs 4.0.0", + "dirs", ] [[package]] @@ -1279,7 +1262,7 @@ version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "wasm-bindgen-macro", ] diff --git a/Cargo.toml b/Cargo.toml index 64d8acba..d1463096 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,6 @@ debug = true [dependencies] chrono = "0.4" csv = "1" -dirs = "2.0" humantime = "2.1" directories-next = "2.0" itertools = "0.10" diff --git a/mcfly.ps1 b/mcfly.ps1 index dcfe964a..cb9373e2 100644 --- a/mcfly.ps1 +++ b/mcfly.ps1 @@ -9,7 +9,6 @@ $null = New-Module mcfly { # Get history file and make a dummy file for psreadline (hopefully after it has loaded the real history file to its in memory history) $env:HISTFILE = $null -eq $env:HISTFILE -or "" -eq $env:HISTFILE ? (Get-PSReadLineOption).HistorySavePath : $env:HISTFILE; - $_PSREADLINEHISTORY = (Get-PSReadLineOption).HistorySavePath $psreadline_dummy = New-TemporaryFile Set-PSReadLineOption -HistorySavePath $psreadline_dummy.FullName diff --git a/src/path_update_helpers.rs b/src/path_update_helpers.rs index 7bba4087..3cf70dc1 100644 --- a/src/path_update_helpers.rs +++ b/src/path_update_helpers.rs @@ -9,7 +9,7 @@ pub fn normalize_path(incoming_path: &str) -> String { .absolutize_from(std::env::current_dir().unwrap().as_path()) .unwrap() .to_str() - .unwrap() + .unwrap_or_else(|| panic!("McFly error: Path must be a valid UTF8 string")) .to_string(); } @@ -127,6 +127,7 @@ mod tests { assert_eq!(normalize_path("~/foo/bar/../.."), env::var("HOME").unwrap()); } + #[cfg(windows)] fn windows_home_path() -> String { PathBuf::from(env::var("HOMEDRIVE").unwrap()) .join(env::var("HOMEPATH").unwrap()) From a28ab7683e0f2606e87fddea8e8048ff4e76f7ec Mon Sep 17 00:00:00 2001 From: Jackson Schuster Date: Tue, 12 Sep 2023 12:13:22 -0500 Subject: [PATCH 30/31] Remove relative-path --- Cargo.lock | 7 ------- Cargo.toml | 1 - 2 files changed, 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c6ed4854..aab2ba68 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -683,7 +683,6 @@ dependencies = [ "path-absolutize", "rand 0.8.5", "regex", - "relative-path", "rusqlite", "shellexpand", "unicode-segmentation", @@ -1045,12 +1044,6 @@ version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" -[[package]] -name = "relative-path" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c707298afce11da2efef2f600116fa93ffa7a032b5d7b628aa17711ec81383ca" - [[package]] name = "rusqlite" version = "0.28.0" diff --git a/Cargo.toml b/Cargo.toml index d1463096..fe505fbf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,6 @@ itertools = "0.10" rand = "0.8" path-absolutize = "3.0.13" regex = { version = "1", default-features = false, features = ["perf", "std"] } -relative-path = "1.7" shellexpand = "2.1" unicode-segmentation = "1.9" From c8e8bc0498fcbdb88ff0b363c63f2a722276f49f Mon Sep 17 00:00:00 2001 From: Jackson Schuster Date: Tue, 12 Sep 2023 12:20:14 -0500 Subject: [PATCH 31/31] Use PWD function instead of env::curent_dir in normalize path --- src/path_update_helpers.rs | 3 ++- src/settings.rs | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/path_update_helpers.rs b/src/path_update_helpers.rs index 3cf70dc1..887b1440 100644 --- a/src/path_update_helpers.rs +++ b/src/path_update_helpers.rs @@ -1,3 +1,4 @@ +use crate::settings::pwd; use path_absolutize::*; use std::path::Path; use unicode_segmentation::UnicodeSegmentation; @@ -6,7 +7,7 @@ pub fn normalize_path(incoming_path: &str) -> String { let expanded_path = shellexpand::tilde(incoming_path).to_string(); println!("{}", expanded_path); return Path::new(&expanded_path) - .absolutize_from(std::env::current_dir().unwrap().as_path()) + .absolutize_from(pwd()) .unwrap() .to_str() .unwrap_or_else(|| panic!("McFly error: Path must be a valid UTF8 string")) diff --git a/src/settings.rs b/src/settings.rs index 1f65a838..1ddc750c 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -407,7 +407,7 @@ impl Settings { } #[cfg(not(windows))] -fn pwd() -> String { +pub fn pwd() -> String { env::var("PWD").unwrap_or_else(|err| { panic!( "McFly error: Unable to determine current directory ({})", @@ -417,7 +417,7 @@ fn pwd() -> String { } #[cfg(windows)] -fn pwd() -> String { +pub fn pwd() -> String { env::current_dir() .unwrap_or_else(|err| { panic!(