From 9ecd4a5dc48752105fee4f5e862fc61ee9b071ac Mon Sep 17 00:00:00 2001 From: Badr Bouslikhin Date: Sun, 8 Jan 2023 00:58:26 +0100 Subject: [PATCH 1/4] Feature gate local echo. --- Cargo.toml | 4 ++++ src/lib.rs | 37 ++++++++++++++++++++++++------------- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 22c946a..92a32d9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,5 +11,9 @@ readme = "README.md" [dependencies] +[features] +no-echo = [] + + [dev-dependencies] pancurses = "0.16" diff --git a/src/lib.rs b/src/lib.rs index 1e092a9..45d2496 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -282,6 +282,14 @@ where return; } let outcome = if input == 0x0D { + #[cfg(feature = "no-echo")] + { + // Echo the command + write!(self.context, "\r").unwrap(); + if let Ok(s) = core::str::from_utf8(&self.buffer[0..self.used]) { + write!(self.context, "{}", s).unwrap(); + } + } // Handle the command self.process_command(); Outcome::CommandProcessed @@ -296,19 +304,22 @@ where self.buffer[self.used] = input; self.used += 1; - // We have to do this song and dance because `self.prompt()` needs - // a mutable reference to self, and we can't have that while - // holding a reference to the buffer at the same time. - // This line grabs the buffer, checks it's OK, then releases it again - let valid = core::str::from_utf8(&self.buffer[0..self.used]).is_ok(); - // Now we've released the buffer, we can draw the prompt - if valid { - write!(self.context, "\r").unwrap(); - self.prompt(false); - } - // Grab the buffer again to render it to the screen - if let Ok(s) = core::str::from_utf8(&self.buffer[0..self.used]) { - write!(self.context, "{}", s).unwrap(); + #[cfg(not(feature = "no-echo"))] + { + // We have to do this song and dance because `self.prompt()` needs + // a mutable reference to self, and we can't have that while + // holding a reference to the buffer at the same time. + // This line grabs the buffer, checks it's OK, then releases it again + let valid = core::str::from_utf8(&self.buffer[0..self.used]).is_ok(); + // Now we've released the buffer, we can draw the prompt + if valid { + write!(self.context, "\r").unwrap(); + self.prompt(false); + } + // Grab the buffer again to render it to the screen + if let Ok(s) = core::str::from_utf8(&self.buffer[0..self.used]) { + write!(self.context, "{}", s).unwrap(); + } } Outcome::NeedMore } else { From 409de918c3f55327a772963c22c276a7fe942d54 Mon Sep 17 00:00:00 2001 From: Badr Bouslikhin Date: Tue, 14 Mar 2023 19:03:39 +0100 Subject: [PATCH 2/4] Flip logic and enable echo by default --- Cargo.toml | 3 ++- src/lib.rs | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 92a32d9..24acfa9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,8 @@ readme = "README.md" [features] -no-echo = [] +default = ["echo"] +echo = [] [dev-dependencies] diff --git a/src/lib.rs b/src/lib.rs index 45d2496..5df292b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -282,7 +282,7 @@ where return; } let outcome = if input == 0x0D { - #[cfg(feature = "no-echo")] + #[cfg(not(feature = "echo"))] { // Echo the command write!(self.context, "\r").unwrap(); @@ -304,7 +304,7 @@ where self.buffer[self.used] = input; self.used += 1; - #[cfg(not(feature = "no-echo"))] + #[cfg(feature = "echo")] { // We have to do this song and dance because `self.prompt()` needs // a mutable reference to self, and we can't have that while From 8a16411e9da90ad1eebdb9a08db6b5ae797a710a Mon Sep 17 00:00:00 2001 From: Badr Bouslikhin Date: Wed, 15 Mar 2023 15:44:49 +0100 Subject: [PATCH 3/4] Add echo feature documentation. --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index 5df292b..52d7bc2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -276,6 +276,7 @@ where /// Add a byte to the menu runner's buffer. If this byte is a /// carriage-return, the buffer is scanned and the appropriate action /// performed. + /// By default, an echo feature is enabled to display commands on the terminal. pub fn input_byte(&mut self, input: u8) { // Strip carriage returns if input == 0x0A { From ecbeb9b093670190678b8abaf91cd4129a68395b Mon Sep 17 00:00:00 2001 From: Badr Bouslikhin Date: Wed, 15 Mar 2023 15:45:05 +0100 Subject: [PATCH 4/4] Add v0.3.3 to changelog. --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 2b73ab2..a5c95c9 100644 --- a/README.md +++ b/README.md @@ -171,6 +171,10 @@ It contains multiple paragraphs and should be preceeded by the parameter list. * None +### v0.3.3 + +* Add the possibility to disable local echo (via echo feature, enabled by default) + ### v0.3.2 * Shortened help output.