-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Respect termios ECHO
flag
#673
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,6 +149,9 @@ | |
// Manage optional kitty protocol | ||
kitty_protocol: KittyProtocolGuard, | ||
|
||
// Echo typed input | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As this an absolutely obscure usecase I think expanding this to a small doccomment with pointers what you are trying to achieve and the relation to the |
||
echo_on: bool, | ||
|
||
#[cfg(feature = "external_printer")] | ||
external_printer: Option<ExternalPrinter<String>>, | ||
} | ||
|
@@ -218,6 +221,7 @@ | |
cursor_shapes: None, | ||
bracketed_paste: BracketedPasteGuard::default(), | ||
kitty_protocol: KittyProtocolGuard::default(), | ||
echo_on: true, | ||
#[cfg(feature = "external_printer")] | ||
external_printer: None, | ||
} | ||
|
@@ -609,6 +613,14 @@ | |
/// 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); | ||
} | ||
|
||
terminal::enable_raw_mode()?; | ||
self.bracketed_paste.enter(); | ||
self.kitty_protocol.enter(); | ||
|
@@ -618,6 +630,7 @@ | |
self.bracketed_paste.exit(); | ||
self.kitty_protocol.exit(); | ||
terminal::disable_raw_mode()?; | ||
|
||
result | ||
} | ||
|
||
|
@@ -1638,14 +1651,17 @@ | |
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, | ||
) | ||
} else { | ||
(String::new(), String::new()) | ||
}; | ||
|
||
let hint: String = if self.hints_active() { | ||
self.hinter.as_mut().map_or_else(String::new, |hinter| { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not super critical but we could make this a unix only dependency for slightly faster downloads on windows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, forgot to do that.