From 8e4c8fc8d8f4a88ba5f449ffa7973eb3f8e327d5 Mon Sep 17 00:00:00 2001 From: Lin Date: Thu, 9 Jun 2022 17:37:17 +0800 Subject: [PATCH] =?UTF-8?q?feat(message):=20=F0=9F=8E=89=20type=20select?= =?UTF-8?q?=20to=20fuzzy=20select.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ommit d:escript. --- Cargo.lock | 19 +++++++++++++++++++ Cargo.toml | 2 +- src/message.rs | 6 +++--- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 167b1e7..e91e7fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -92,6 +92,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8c8ae48e400addc32a8710c8d62d55cb84249a7d58ac4cd959daecfbaddc545" dependencies = [ "console", + "fuzzy-matcher", "tempfile", "zeroize", ] @@ -112,6 +113,15 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "fuzzy-matcher" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54614a3312934d066701a80f20f15fa3b56d67ac7722b39eea5b4c9dd1d66c94" +dependencies = [ + "thread_local", +] + [[package]] name = "getrandom" version = "0.2.2" @@ -473,6 +483,15 @@ version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" +[[package]] +name = "thread_local" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180" +dependencies = [ + "once_cell", +] + [[package]] name = "tinyvec" version = "1.1.1" diff --git a/Cargo.toml b/Cargo.toml index df592b2..f9460a5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ lto = true [dependencies] clap = "3.1.18" console = "0.15.0" -dialoguer = "0.10.1" +dialoguer = { version = "0.10.1", features = ["editor", "fuzzy-select"] } git2 = "0.14.4" toml = "0.5.9" serde = { version = "1.0.137", features = ["derive"] } diff --git a/src/message.rs b/src/message.rs index 1f5611a..7603800 100644 --- a/src/message.rs +++ b/src/message.rs @@ -1,4 +1,4 @@ -use dialoguer::{theme::ColorfulTheme, Input, Select}; +use dialoguer::{theme::ColorfulTheme, FuzzySelect, Input}; use dialoguer::{Confirm, Editor}; use crate::log::grc_err_println; @@ -149,11 +149,11 @@ impl Messager { /// type of commit message. fn ask_type(&mut self) { - let selection = Select::with_theme(&ColorfulTheme::default()) + let selection = FuzzySelect::with_theme(&ColorfulTheme::default()) .items(&self.type_list()) .default(0) .interact() - .unwrap(); + .expect("Failed to select commit type."); // Custom TYPE. if selection == self.commit_type_descript.len() - 1 {