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

add support for non-english (non-ascii) utf-8 text input #185

Closed
adsick opened this issue Mar 17, 2022 · 5 comments
Closed

add support for non-english (non-ascii) utf-8 text input #185

adsick opened this issue Mar 17, 2022 · 5 comments

Comments

@adsick
Copy link

adsick commented Mar 17, 2022

Recently I've observed that the crate is not able to handle non-english symbols (e.g. russian/ukrainian...)

@adsick 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
@deg0nz
Copy link
Contributor

deg0nz commented Mar 31, 2022

This may be related to #181.

In which prompts are you experiencing the issues?

@adsick
Copy link
Author

adsick commented Apr 1, 2022

there is no panic, but displaying is broken. see near/near-cli-rs#97

@lisiur
Copy link

lisiur commented Jul 5, 2022

I have an hotfix for those who want to get a temporary solution:

src/prompts/input.rs around line 300

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()?;
        }
        // ...
    }
}

@schneiderfelipe
Copy link

This is probably related to #116?

@Gordon01
Copy link
Contributor

Gordon01 commented Sep 11, 2023

I can't reproduce this on the latest master
image

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants