From fad8d972128f43a2e7bad9915065444756a622fe Mon Sep 17 00:00:00 2001 From: Jeff Date: Mon, 28 Aug 2023 17:15:05 -0400 Subject: [PATCH] Add ANSI coloring --- Cargo.lock | 10 ++++++++++ Cargo.toml | 1 + src/bin/dust.rs | 34 ++-------------------------------- 3 files changed, 13 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8809745..b1ab4c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -161,6 +161,15 @@ 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 = "anstream" version = "0.5.0" @@ -921,6 +930,7 @@ checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" name = "dust-lang" version = "0.1.0" dependencies = [ + "ansi_term", "chrono", "clap", "comfy-table", diff --git a/Cargo.toml b/Cargo.toml index 7a8b0d5..596c06c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,3 +35,4 @@ reqwest = { version = "0.11.18", features = ["blocking", "json"] } serde_json = "1.0.104" egui_extras = "0.22.0" rustyline = { version = "12.0.0", features = ["with-file-history", "derive"] } +ansi_term = "0.12.1" diff --git a/src/bin/dust.rs b/src/bin/dust.rs index b0d6689..33b5991 100644 --- a/src/bin/dust.rs +++ b/src/bin/dust.rs @@ -62,9 +62,6 @@ struct DustReadline { tool_hints: Vec, - #[rustyline(Validator)] - validator: MatchingBracketValidator, - #[rustyline(Hinter)] hinter: HistoryHinter, } @@ -73,7 +70,6 @@ impl DustReadline { fn new() -> Self { Self { completer: FilenameCompleter::new(), - validator: MatchingBracketValidator::new(), hinter: HistoryHinter {}, tool_hints: TOOL_LIST .iter() @@ -133,36 +129,10 @@ impl Hinter for DustReadline { } impl Highlighter for DustReadline { - fn highlight<'l>(&self, line: &'l str, pos: usize) -> std::borrow::Cow<'l, str> { - let _ = pos; - Cow::Borrowed(line) - } - - fn highlight_prompt<'b, 's: 'b, 'p: 'b>( - &'s self, - prompt: &'p str, - default: bool, - ) -> std::borrow::Cow<'b, str> { - let _ = default; - Cow::Borrowed(prompt) - } - fn highlight_hint<'h>(&self, hint: &'h str) -> std::borrow::Cow<'h, str> { - Cow::Borrowed(hint) - } + let highlighted = ansi_term::Colour::Red.paint(hint).to_string(); - fn highlight_candidate<'c>( - &self, - candidate: &'c str, // FIXME should be Completer::Candidate - completion: rustyline::CompletionType, - ) -> std::borrow::Cow<'c, str> { - let _ = completion; - Cow::Borrowed(candidate) - } - - fn highlight_char(&self, line: &str, pos: usize) -> bool { - let _ = (line, pos); - false + Cow::Owned(highlighted) } }