Skip to content

Commit

Permalink
Respect termios ECHO flag
Browse files Browse the repository at this point in the history
  • Loading branch information
IanManske committed Nov 29, 2023
1 parent 93af55c commit b4b48cf
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ crossbeam = { version = "0.8.2", optional = true }
crossterm = { version = "0.27.0", features = ["serde"] }
fd-lock = "3.0.3"
itertools = "0.10.3"
nix = { version = "0.27.1", features = ["term"] }
nu-ansi-term = "0.49.0"
rusqlite = { version = "0.29.0", optional = true }
serde = { version = "1.0", features = ["derive"] }
Expand Down
32 changes: 24 additions & 8 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ pub struct Reedline {
// Manage optional kitty protocol
kitty_protocol: KittyProtocolGuard,

// Echo typed input
echo_on: bool,

#[cfg(feature = "external_printer")]
external_printer: Option<ExternalPrinter<String>>,
}
Expand Down Expand Up @@ -218,6 +221,7 @@ impl Reedline {
cursor_shapes: None,
bracketed_paste: BracketedPasteGuard::default(),
kitty_protocol: KittyProtocolGuard::default(),
echo_on: true,
#[cfg(feature = "external_printer")]
external_printer: None,
}
Expand Down Expand Up @@ -609,6 +613,14 @@ impl Reedline {
/// Returns a [`std::io::Result`] in which the `Err` type is [`std::io::Result`]
/// and the `Ok` variant wraps a [`Signal`] which handles user inputs.
pub fn read_line(&mut self, prompt: &dyn Prompt) -> Result<Signal> {
// Needs to be done before `terminal::enable_raw_mode()` which modifies the terminal flags
#[cfg(unix)]
if let Ok(attr) = nix::sys::termios::tcgetattr(std::io::stdin()) {
self.echo_on = attr
.local_flags
.contains(nix::sys::termios::LocalFlags::ECHO);
}

Check warning on line 622 in src/engine.rs

View check run for this annotation

Codecov / codecov/patch

src/engine.rs#L618-L622

Added lines #L618 - L622 were not covered by tests

terminal::enable_raw_mode()?;
self.bracketed_paste.enter();
self.kitty_protocol.enter();
Expand All @@ -618,6 +630,7 @@ impl Reedline {
self.bracketed_paste.exit();
self.kitty_protocol.exit();
terminal::disable_raw_mode()?;

result
}

Expand Down Expand Up @@ -1638,14 +1651,17 @@ impl Reedline {
let cursor_position_in_buffer = self.editor.insertion_point();
let buffer_to_paint = self.editor.get_buffer();

let (before_cursor, after_cursor) = self
.highlighter
.highlight(buffer_to_paint, cursor_position_in_buffer)
.render_around_insertion_point(
cursor_position_in_buffer,
prompt,
self.use_ansi_coloring,
);
let (before_cursor, after_cursor) = if self.echo_on {
self.highlighter
.highlight(buffer_to_paint, cursor_position_in_buffer)
.render_around_insertion_point(
cursor_position_in_buffer,
prompt,
self.use_ansi_coloring,
)

Check warning on line 1661 in src/engine.rs

View check run for this annotation

Codecov / codecov/patch

src/engine.rs#L1654-L1661

Added lines #L1654 - L1661 were not covered by tests
} else {
(String::new(), String::new())

Check warning on line 1663 in src/engine.rs

View check run for this annotation

Codecov / codecov/patch

src/engine.rs#L1663

Added line #L1663 was not covered by tests
};

let hint: String = if self.hints_active() {
self.hinter.as_mut().map_or_else(String::new, |hinter| {
Expand Down

0 comments on commit b4b48cf

Please sign in to comment.