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
add support for non-english (non-ascii) utf-8 text input #185
Comments
adsick
changed the title
add support for non-english (non-ascii) utf-8 input
add support for non-english (non-ascii) utf-8 text input
Mar 18, 2022
This may be related to #181. In which prompts are you experiencing the issues? |
there is no panic, but displaying is broken. see near/near-cli-rs#97 |
I have an hotfix for those who want to get a temporary solution:
fn chars_width(chars: Chars) -> usize {
chars.fold(0, |acc, c| acc + char_width(c))
}
fn char_width(chr: char) -> usize {
// Not exactly correct here, you may need to make some adjustments as needed
if chr.is_ascii() {
1
} else {
2
}
}
loop {
match term.read_key()? {
Key::Backspace if position > 0 => {
position -= 1;
let chr = chars.remove(position);
term.clear_chars(char_width(chr))?;
let tail: String = chars[position..].iter().collect();
if !tail.is_empty() {
term.write_str(&tail)?;
term.move_cursor_left(chars_width(tail.chars()))?;
}
term.flush()?;
}
Key::Char(chr) if !chr.is_ascii_control() => {
chars.insert(position, chr);
position += 1;
let tail: String =
iter::once(&chr).chain(chars[position..].iter()).collect();
term.write_str(&tail)?;
term.move_cursor_left(chars_width(tail.chars()) - char_width(chr))?;
term.flush()?;
}
Key::ArrowLeft if position > 0 => {
term.move_cursor_left(char_width(chars[position - 1]))?;
position -= 1;
term.flush()?;
}
Key::ArrowRight if position < chars.len() => {
term.move_cursor_right(char_width(chars[position]))?;
position += 1;
term.flush()?;
}
// ...
}
} |
This is probably related to #116? |
I can't reproduce this on the latest master Edit: it's fixed in #269 @pksunkara perhaps it's fixed? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Recently I've observed that the crate is not able to handle non-english symbols (e.g. russian/ukrainian...)
The text was updated successfully, but these errors were encountered: