Skip to content

Conversation

dhuseby
Copy link

@dhuseby dhuseby commented Aug 22, 2025

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]

Signed-off-by: Dave Grantham <[email protected]>
Copy link
Member

@djc djc left a 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.

@@ -0,0 +1,50 @@
extern crate console;
Copy link
Member

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this not helpful?

Copy link
Member

@djc djc Aug 26, 2025

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.

Copy link
Author

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> {
Copy link
Member

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood.

Copy link
Author

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)?;
Copy link
Member

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.

Copy link
Author

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]>
@dhuseby
Copy link
Author

dhuseby commented Aug 26, 2025

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' => {
Copy link
Member

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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants