-
-
Notifications
You must be signed in to change notification settings - Fork 127
feat: add get cursor position #269
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Dave Grantham <[email protected]>
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.
Here's some initial feedback. It doesn't look like this needs a semver-incompatible version bump. It does look like it needs either a Windows implementation or a Unix-only guard.
examples/cursor_position.rs
Outdated
@@ -0,0 +1,50 @@ | |||
extern crate console; |
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.
Please drop the added example.
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.
Is this not helpful?
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.
I don't think think every tiny feature merits an example that then has to be maintained forever -- I think how to use this feature is pretty clear and the effort is better spent on good API docs.
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.
removed
src/ansi.rs
Outdated
@@ -189,7 +189,7 @@ fn find_ansi_code_exclusive(it: &mut Peekable<CharIndices>) -> Option<(usize, us | |||
|
|||
/// Helper function to strip ansi codes. | |||
#[cfg(feature = "alloc")] | |||
pub fn strip_ansi_codes(s: &str) -> Cow<str> { | |||
pub fn strip_ansi_codes(s: &str) -> Cow<'_, str> { |
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.
Since this is independent of your other changes, please isolate it in a separate commit.
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.
Understood.
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.
fixed
src/unix_term.rs
Outdated
io::stdout().flush()?; | ||
|
||
// Read the response from the terminal | ||
let key = read_single_key(false)?; |
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.
Nit: please inline the key
binding.
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.
fixed
Signed-off-by: Dave Grantham <[email protected]>
reverted back to 0.16.0 as well. |
@@ -258,6 +258,44 @@ fn read_single_key_impl(fd: RawFd) -> Result<Key, io::Error> { | |||
'H' => Ok(Key::Home), | |||
'F' => Ok(Key::End), | |||
'Z' => Ok(Key::BackTab), | |||
'0'..='9' => { |
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.
Does it make sense to keep this inside read_single_key_impl()
when it effectively is only expected inside a call to read_single_key()
?
(Part of this is is the very deeply nested indentation level making this code harder to follow.)
This adds the ability to get the current cursor position using the ansi cursor
position query sequence. Sometimes it is useful to know where you are in the
terminal when your program first starts up, or when you are doing some complex
terminal manipulation.
Signed-off-by: Dave Grantham [email protected]