Conversation
Signed-off-by: Dave Grantham <dwg@linuxprogrammer.org>
djc
left a comment
There was a problem hiding this comment.
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.
Signed-off-by: Dave Grantham <dwg@linuxprogrammer.org>
|
reverted back to 0.16.0 as well. |
| 'H' => Ok(Key::Home), | ||
| 'F' => Ok(Key::End), | ||
| 'Z' => Ok(Key::BackTab), | ||
| '0'..='9' => { |
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
I could refactor this to reduce the indentation at several levels. I was trying to keep my edits minimal. If it were me I would refactor the block to be something like:
loop {
match read_single_char(fd)? {
Some('\x1b') => break match read_single_char(fd)? {
Some('[') => match read_single_char(fd)? {
Some(c) => match c {
'A' => Ok(Key::ArrowUp),
//...
'0'..='9' => read_cursor_pos(c),
_ => read_tilde_seq(c),
}
_ => Ok(Key::UnknownEscSeq(vec![c])),
}
Some(c) => Ok(Key::UnknownEscSeq(vec![c])),
_ => Ok(Key::Escape)
}
Some(c) => read_non_escape_seq(c),
None => {
// there is no subsequent byte ready to be read, block and wait for
// input negative timeout means that it will block indefinitely
match select_or_poll_term_fd(fd, -1) {
Ok(_) => continue,
Err(_) => break Err(io::Error::last_os_error()),
}
}
}
}
fn read_cursor_pos(c: char) -> Result<Key, io::Error> {
//...
}
fn read_tilde_seq(c: char) -> Result<Key, io::Error> {
//...
}
fn read_non_escape_seq(c: char) -> Result<Key, io::Error> {
//...
}
Do you think moving the match arm bodies to functions is easier to read?
There was a problem hiding this comment.
I might prefer that but let's not do it in this PR.
For this PR, do you think we need the specific read_cursor_pos() stuff inside the generic read_single_key_impl(), or can we get away with just having it in cursor_position()?
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 dwg@linuxprogrammer.org