From 9aac63a412e3ce2169a58e2b1af7c22784eb0fd2 Mon Sep 17 00:00:00 2001 From: ttys3 Date: Mon, 18 Jan 2021 23:08:28 +0800 Subject: [PATCH] fix(commit): fixup fuzzy finder feature --- .gitignore | 1 + Cargo.lock | 20 ++++++++++++++++++-- Cargo.toml | 3 ++- src/cmd/commit.rs | 25 +++++++++++++++++-------- 4 files changed, 38 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 53eaa21..b309da6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target **/*.rs.bk +/.idea \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 56372bd..df296c8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -176,6 +176,21 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "console" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cc80946b3480f421c2f17ed1cb841753a371c7c5104f51d507e13f532c856aa" +dependencies = [ + "encode_unicode", + "lazy_static", + "libc", + "regex", + "terminal_size", + "unicode-width", + "winapi", +] + [[package]] name = "const_fn" version = "0.4.5" @@ -190,9 +205,10 @@ checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" [[package]] name = "convco" -version = "0.3.3" +version = "0.3.4" dependencies = [ "chrono", + "console 0.14.0", "dialoguer", "git2", "handlebars", @@ -400,7 +416,7 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f4aa86af7b19b40ef9cbef761ed411a49f0afa06b7b6dcd3dfe2f96a3c546138" dependencies = [ - "console", + "console 0.11.3", "lazy_static", "tempfile", ] diff --git a/Cargo.toml b/Cargo.toml index 73b152b..bd46139 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "convco" -version = "0.3.3" +version = "0.3.4" description = "Conventional commit tools" keywords = ["conventional", "commit", "changelog", "semantic", "versioning"] categories = ["development-tools::build-utils"] @@ -27,6 +27,7 @@ url = "2.1.1" dialoguer = "0.6.2" thiserror = "1.0.22" skim = "*" +console = "0.14.0" [build-dependencies] structopt = "0.3.16" diff --git a/src/cmd/commit.rs b/src/cmd/commit.rs index d05a886..97f03cf 100644 --- a/src/cmd/commit.rs +++ b/src/cmd/commit.rs @@ -168,9 +168,16 @@ impl Dialog { let item_reader = SkimItemReader::default(); let items = item_reader.of_bufread(Cursor::new(input)); + // use dialoguer::theme::ColorfulTheme; + // let mut header : String = "type: ".to_owned(); + // header.push_str(ColorfulTheme::default().active_item_prefix.to_string().as_str()); + // .header(Some(header.as_str())) let options = SkimOptionsBuilder::default() + .min_height(Some("10")) + .prompt(Some("? type () › ")) .height(Some("25%")) .multi(false) + .reverse(true) .build() .unwrap(); // `run_with` would read and show items from the stream @@ -179,15 +186,17 @@ impl Dialog { .unwrap_or_else(|| Vec::new()); for item in selected_items.iter() { - // print!("{}{}", item.output(), "\n"); - let _: String = dialoguer::Input::with_theme(theme) - .with_prompt("type") - .with_initial_text(item.output().to_string()) - .allow_empty(true) - .interact()?; - return Ok(item.output().to_string()); + let sel = item.output().to_string(); + + let term: &console::Term = &console::Term::stderr(); + let mut buf = String::new(); + let _ = theme.format_input_prompt_selection(&mut buf, "type", &sel); + term.write_line(buf.as_str())?; + term.clear_line()?; + + return Ok(sel); } - Ok("".to_string()) + Ok(selected.to_string()) } // Prompt all