From 8593aba4696583808b8f712907eca601f24ac807 Mon Sep 17 00:00:00 2001 From: FroVolod <36816899+FroVolod@users.noreply.github.com> Date: Tue, 13 Dec 2022 17:47:50 +0200 Subject: [PATCH] Changed library "dialoguer" to "inquire" (#3) * start * removed "dialoguer" * modified example files * modified "Select" for to_cli_args * modified choose_variant --- Cargo.lock | 340 ++++++++++++------ Cargo.toml | 7 +- examples/advanced_struct.rs | 10 +- examples/struct_with_context.rs | 6 +- examples/to_cli_args.rs | 42 ++- .../methods/choose_variant.rs | 35 +- .../interactive_clap/methods/input_arg.rs | 8 +- src/lib.rs | 14 + 8 files changed, 294 insertions(+), 168 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c957c0f..b50adcc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -30,9 +30,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "backtrace" @@ -88,7 +88,7 @@ version = "4.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "16a1b0f6422af32d5da0c58e2703320f379216ee70198241c84173a8c5ac28f3" dependencies = [ - "heck 0.4.0", + "heck", "proc-macro-error", "proc-macro2", "quote", @@ -132,37 +132,35 @@ dependencies = [ ] [[package]] -name = "console" -version = "0.15.0" +name = "crossterm" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a28b32d32ca44b70c3e4acd7db1babf555fa026e385fb95f18028f88848b3c31" +checksum = "e64e6c0fbe2c17357405f7c758c1ef960fce08bdfb2c03d88d2a18d7e09c4b67" dependencies = [ - "encode_unicode", + "bitflags", + "crossterm_winapi", "libc", - "once_cell", - "regex", - "terminal_size", - "unicode-width", + "mio", + "parking_lot", + "signal-hook", + "signal-hook-mio", "winapi", ] [[package]] -name = "dialoguer" +name = "crossterm_winapi" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61579ada4ec0c6031cfac3f86fdba0d195a7ebeb5e36693bd53cb5999a25beeb" +checksum = "2ae1b35a484aa10e07fe0638d02301c5ad24de82d310ccbd2f3693da5f09bf1c" dependencies = [ - "console", - "lazy_static", - "tempfile", - "zeroize", + "winapi", ] [[package]] -name = "encode_unicode" -version = "0.3.6" +name = "dyn-clone" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" +checksum = "4f94fa09c2aeea5b8839e414b7b841bf429fd25b9c522116ac97ee87856d88b2" [[package]] name = "eyre" @@ -174,30 +172,12 @@ dependencies = [ "once_cell", ] -[[package]] -name = "fastrand" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3fcf0cee53519c866c09b5de1f6c56ff9d647101f81c1964fa632e148896cdf" -dependencies = [ - "instant", -] - [[package]] name = "gimli" version = "0.26.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4" -[[package]] -name = "heck" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" -dependencies = [ - "unicode-segmentation", -] - [[package]] name = "heck" version = "0.4.0" @@ -220,12 +200,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" [[package]] -name = "instant" -version = "0.1.12" +name = "inquire" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +checksum = "e6055ce38cac9b10ac819ed4a509d92ccbc60808152c19ff9121c98198964272" dependencies = [ - "cfg-if", + "bitflags", + "crossterm", + "dyn-clone", + "lazy_static", + "newline-converter", + "thiserror", + "unicode-segmentation", + "unicode-width", ] [[package]] @@ -234,11 +221,11 @@ version = "0.1.0" dependencies = [ "clap", "color-eyre", - "dialoguer", + "inquire", "interactive_clap_derive", "shell-words", "strum", - "strum_macros 0.20.1 (registry+https://github.com/rust-lang/crates.io-index)", + "strum_macros", ] [[package]] @@ -259,9 +246,28 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.117" +version = "0.2.138" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e74d72e0f9b65b5b4ca49a346af3976df0f9c61d550727f349ecd559f251a26c" +checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8" + +[[package]] +name = "lock_api" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +dependencies = [ + "cfg-if", +] [[package]] name = "memchr" @@ -279,6 +285,27 @@ dependencies = [ "autocfg", ] +[[package]] +name = "mio" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5d732bc30207a6423068df043e3d02e0735b155ad7ce1a6f76fe2baa5b158de" +dependencies = [ + "libc", + "log", + "wasi", + "windows-sys", +] + +[[package]] +name = "newline-converter" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f71d09d5c87634207f894c6b31b6a2b2c64ea3bdcf71bd5599fdbbe1600c00f" +dependencies = [ + "unicode-segmentation", +] + [[package]] name = "object" version = "0.27.1" @@ -306,6 +333,29 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2386b4ebe91c2f7f51082d4cefa145d030e33a1842a96b12e4885cc3c01f7a55" +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ff9f3fef3968a3ec5945535ed654cb38ff72d7495a25619e2247fb15a2ed9ba" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-sys", +] + [[package]] name = "pin-project-lite" version = "0.2.8" @@ -363,36 +413,24 @@ dependencies = [ "bitflags", ] -[[package]] -name = "regex" -version = "1.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" -dependencies = [ - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.6.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" - -[[package]] -name = "remove_dir_all" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" -dependencies = [ - "winapi", -] - [[package]] name = "rustc-demangle" version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" +[[package]] +name = "rustversion" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97477e48b4cf8603ad5f7aaf897467cf42ab4218a38ef76fb14c2d6773a6d6a8" + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + [[package]] name = "sharded-slab" version = "0.1.4" @@ -408,6 +446,42 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde" +[[package]] +name = "signal-hook" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a253b5e89e2698464fc26b545c9edceb338e18a89effeeecfea192c3025be29d" +dependencies = [ + "libc", + "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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0" +dependencies = [ + "libc", +] + +[[package]] +name = "smallvec" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" + [[package]] name = "strsim" version = "0.10.0" @@ -416,32 +490,23 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "strum" -version = "0.20.1" -source = "git+https://github.com/frol/strum?branch=feat/discriminants-pass-through-attributes#83c18208c9f0f0f4c412694ec0ba89f3eab026f9" -dependencies = [ - "strum_macros 0.20.1 (git+https://github.com/frol/strum?branch=feat/discriminants-pass-through-attributes)", -] - -[[package]] -name = "strum_macros" -version = "0.20.1" +version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee8bc6b87a5112aeeab1f4a9f7ab634fe6cbefc4850006df31267f4cfb9e3149" +checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f" dependencies = [ - "heck 0.3.3", - "proc-macro2", - "quote", - "syn", + "strum_macros", ] [[package]] name = "strum_macros" -version = "0.20.1" -source = "git+https://github.com/frol/strum?branch=feat/discriminants-pass-through-attributes#83c18208c9f0f0f4c412694ec0ba89f3eab026f9" +version = "0.24.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" dependencies = [ - "heck 0.3.3", + "heck", "proc-macro2", "quote", + "rustversion", "syn", ] @@ -456,20 +521,6 @@ dependencies = [ "unicode-xid", ] -[[package]] -name = "tempfile" -version = "3.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" -dependencies = [ - "cfg-if", - "fastrand", - "libc", - "redox_syscall", - "remove_dir_all", - "winapi", -] - [[package]] name = "termcolor" version = "1.1.2" @@ -480,13 +531,23 @@ dependencies = [ ] [[package]] -name = "terminal_size" -version = "0.1.17" +name = "thiserror" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df" +checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e" dependencies = [ - "libc", - "winapi", + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb" +dependencies = [ + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -560,9 +621,9 @@ checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" [[package]] name = "unicode-segmentation" -version = "1.8.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b" +checksum = "0fdbf052a0783de01e944a6ce7a8cb939e295b1e7be835a1112c3b9a7f047a5a" [[package]] name = "unicode-width" @@ -588,6 +649,12 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + [[package]] name = "winapi" version = "0.3.9" @@ -620,7 +687,58 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] -name = "zeroize" -version = "1.5.2" +name = "windows-sys" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c88870063c39ee00ec285a2f8d6a966e5b6fb2becc4e8dac77ed0d370ed6006" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +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.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" + +[[package]] +name = "windows_i686_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" + +[[package]] +name = "windows_i686_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" diff --git a/Cargo.toml b/Cargo.toml index 206074d..5a85641 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,15 +12,14 @@ edition = "2018" [dependencies] interactive_clap_derive = { path = "interactive_clap_derive" } +strum = { version = "0.24", features = ["derive"] } +strum_macros = "0.24" [dev-dependencies] shell-words = "1.0.0" clap = { version = "4.0.18", features = ["derive"] } -strum = { git = "https://github.com/frol/strum", branch = "feat/discriminants-pass-through-attributes", features = ["derive"] } -strum_macros = "0.20" - -dialoguer = "0.9" +inquire = "0.5" color-eyre = "0.5" diff --git a/examples/advanced_struct.rs b/examples/advanced_struct.rs index 6452f1e..01e6574 100644 --- a/examples/advanced_struct.rs +++ b/examples/advanced_struct.rs @@ -7,6 +7,8 @@ // => args: Ok(Args { age: 30, first_name: "QWE", second_name: "QWERTY" }) // To learn more about the parameters, use "help" flag: ./advanced_struct --help +use inquire::{CustomType, Text}; + #[derive(Debug, interactive_clap_derive::InteractiveClap)] #[interactive_clap(skip_default_from_cli)] struct Args { @@ -58,15 +60,11 @@ impl Args { } fn input_age(_context: &()) -> color_eyre::eyre::Result { - Ok(dialoguer::Input::new() - .with_prompt("How old are you?") - .interact_text()?) + Ok(CustomType::new("How old are you?").prompt()?) } fn input_second_name(_context: &()) -> color_eyre::eyre::Result { - Ok(dialoguer::Input::new() - .with_prompt("What is your last name?") - .interact_text()?) + Ok(Text::new("What is your last name?").prompt()?) } fn from_cli_age( diff --git a/examples/struct_with_context.rs b/examples/struct_with_context.rs index ab59e49..d2048b1 100644 --- a/examples/struct_with_context.rs +++ b/examples/struct_with_context.rs @@ -6,6 +6,8 @@ // ./struct_with_context account QWERTY => offline_args: Ok(OfflineArgs { account: Sender { sender_account_id: "QWERTY" } }) // To learn more about the parameters, use "help" flag: ./struct_with_context --help +use inquire::Text; + mod common; #[derive(Debug, Clone, interactive_clap_derive::InteractiveClap)] @@ -55,9 +57,7 @@ pub struct Sender { impl Sender { fn input_sender_account_id(context: &OfflineArgsContext) -> color_eyre::eyre::Result { println!("Let's use context: {:?}", context); - Ok(dialoguer::Input::new() - .with_prompt("What is the account ID?") - .interact_text()?) + Ok(Text::new("What is the account ID?").prompt()?) } } diff --git a/examples/to_cli_args.rs b/examples/to_cli_args.rs index 421883a..baab2d3 100644 --- a/examples/to_cli_args.rs +++ b/examples/to_cli_args.rs @@ -7,10 +7,10 @@ // ./to_cli_args display => Your console command: display // To learn more about the parameters, use "help" flag: ./to_cli_args --help -use dialoguer::{theme::ColorfulTheme, Select}; +use inquire::Select; use strum::{EnumDiscriminants, EnumIter, EnumMessage, IntoEnumIterator}; -use interactive_clap::ToCliArgs; +use interactive_clap::{ToCliArgs, SelectVariantOrBack}; mod common; @@ -55,22 +55,19 @@ impl Submit { fn choose_variant( _context: common::ConnectionConfig, ) -> color_eyre::eyre::Result> { - let variants = SubmitDiscriminants::iter().collect::>(); - let mut submits = variants - .iter() - .map(|p| p.get_message().unwrap().to_owned()) - .collect::>(); - submits.push("back".to_string()); - let select_submit = Select::with_theme(&ColorfulTheme::default()) - .with_prompt("How would you like to proceed") - .items(&submits) - .default(0) - .interact() - .unwrap(); - match variants.get(select_submit) { - Some(SubmitDiscriminants::Send) => Ok(Some(Submit::Send)), - Some(SubmitDiscriminants::Display) => Ok(Some(Submit::Display)), - None => Ok(None), + let selected_variant = Select::new( + "How would you like to proceed", + SubmitDiscriminants::iter() + .map(SelectVariantOrBack::Variant) + .chain([SelectVariantOrBack::Back]) + .collect(), + ) + .prompt() + .unwrap(); + match selected_variant { + SelectVariantOrBack::Variant(SubmitDiscriminants::Send) => Ok(Some(Submit::Send)), + SelectVariantOrBack::Variant(SubmitDiscriminants::Display) => Ok(Some(Submit::Display)), + SelectVariantOrBack::Back => Ok(None), } } } @@ -79,6 +76,15 @@ impl interactive_clap::ToCli for Submit { type CliVariant = Submit; } +impl std::fmt::Display for SubmitDiscriminants { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + match self { + Self::Send => write!(f, "send"), + Self::Display => write!(f, "display"), + } + } +} + fn main() { let mut cli_online_args = OnlineArgs::parse(); let context = common::ConnectionConfig::Testnet; //#[interactive_clap(context = common::ConnectionConfig)] diff --git a/interactive_clap_derive/src/derives/interactive_clap/methods/choose_variant.rs b/interactive_clap_derive/src/derives/interactive_clap/methods/choose_variant.rs index 51d0ed2..4e0abf1 100644 --- a/interactive_clap_derive/src/derives/interactive_clap/methods/choose_variant.rs +++ b/interactive_clap_derive/src/derives/interactive_clap/methods/choose_variant.rs @@ -18,7 +18,7 @@ pub fn fn_choose_variant( let variant_ident = &variants[0].ident; let mut cli_variant = quote!(); - let mut actions_push_back = quote! {actions.push("back".to_string())}; + let mut actions_push_back = quote! {.chain([SelectVariantOrBack::Back])}; let mut ast_attrs: Vec<&str> = std::vec::Vec::new(); if !ast.attrs.is_empty() { @@ -105,32 +105,27 @@ pub fn fn_choose_variant( } }); cli_variant = quote! { - use dialoguer::{theme::ColorfulTheme, Select}; + use interactive_clap::SelectVariantOrBack; + use inquire::Select; use strum::{EnumMessage, IntoEnumIterator}; fn prompt_variant(prompt: &str) -> Option where T: IntoEnumIterator + EnumMessage, T: Copy + Clone, { - let variants = T::iter().collect::>(); - let mut actions = variants - .iter() - .map(|p| { - p.get_message() - .unwrap_or_else(|| "error[This entry does not have an option message!!]") - .to_owned() - }) - .collect::>(); - #actions_push_back; - - let selected = Select::with_theme(&ColorfulTheme::default()) - .with_prompt(prompt) - .items(&actions) - .default(0) - .interact() + let selected_variant = Select::new( + prompt, + T::iter() + .map(SelectVariantOrBack::Variant) + #actions_push_back + .collect(), + ) + .prompt() .unwrap(); - - variants.get(selected).cloned() + match selected_variant { + SelectVariantOrBack::Variant(variant) => Some(variant), + SelectVariantOrBack::Back => None, + } }; let variant = if let Some(variant) = prompt_variant(#literal.to_string().as_str()) { variant diff --git a/interactive_clap_derive/src/derives/interactive_clap/methods/input_arg.rs b/interactive_clap_derive/src/derives/interactive_clap/methods/input_arg.rs index 96f5bc5..5800b76 100644 --- a/interactive_clap_derive/src/derives/interactive_clap/methods/input_arg.rs +++ b/interactive_clap_derive/src/derives/interactive_clap/methods/input_arg.rs @@ -35,9 +35,7 @@ pub fn vec_fn_input_arg( fn #fn_input_arg( _context: &#input_context_dir, ) -> color_eyre::eyre::Result<#ty> { - Ok(dialoguer::Input::new() - .with_prompt(#promt) - .interact_text()?) + Ok(inquire::CustomType::new(#promt).prompt()?) } }; } @@ -66,9 +64,7 @@ pub fn vec_fn_input_arg( fn #fn_input_arg( _context: &#input_context_dir, ) -> color_eyre::eyre::Result<#ty> { - Ok(dialoguer::Input::new() - .with_prompt(#literal.to_string().as_str()) - .interact_text()?) + Ok(inquire::CustomType::new(#literal.to_string().as_str()).prompt()?) } } }) diff --git a/src/lib.rs b/src/lib.rs index e6bb3de..1e65808 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -40,3 +40,17 @@ pub trait FromCli { where Self: Sized + ToCli; } + +pub enum SelectVariantOrBack { + Variant(T), + Back, +} +impl std::fmt::Display for SelectVariantOrBack { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + if let Self::Variant(variant) = self { + f.write_str(variant.get_message().unwrap()) + } else { + f.write_str("back") + } + } +}