Skip to content
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

read only one byte in read_single_key unless we find an escape sequence #62

Merged
merged 2 commits into from
May 8, 2020

Conversation

rjwalters
Copy link

When input is pasted into a unix terminal and collected using read_single_key I noticed that only every 20th character was available. I don't think it should be necessary to read more than one byte at a time. (Hopefully no unicode issues etc.)

@rjwalters
Copy link
Author

This causes problems for keystrokes that are longer than one byte... for example in dialoguer's Select functionality. I think we need to look for multibyte keystrokes and read more of the buffer when we find them...

b"\x1b[D" => Key::ArrowLeft,
b"\x1b[C" => Key::ArrowRight,
b"\x1b[A" => Key::ArrowUp,
b"\x1b[B" => Key::ArrowDown,
b"\n" | b"\r" => Key::Enter,
b"\x1b" => Key::Escape,
b"\x7f" => Key::Backspace,
b"\x1b[H" => Key::Home,
b"\x1b[F" => Key::End,
b"\t" => Key::Tab,
b"\x1b[3~" => Key::Del,

@pksunkara
Copy link
Collaborator

Sounds good, but how does utf8 work with this?

@rjwalters rjwalters changed the title only read one byte when reading one character read only one byte in read_single_key unless we find an escape sequence May 7, 2020
@rjwalters
Copy link
Author

I added special cases to capture UTF-8 based on https://en.wikipedia.org/wiki/UTF-8

@pksunkara pksunkara merged commit 1307823 into console-rs:master May 8, 2020
@pksunkara
Copy link
Collaborator

Thanks. This is great work. Really appreciate it. Feel free to open PRs anytime you want. I will always respond fast. 😄

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