I'm writing an ncurses app with Rust.
I want the user to be able to input Unicode (UTF-8) characters. Besides printing them to screen, I am going to build up a search string from the characters.
Here's a minimal example:
use ncurses::*;
fn main() {
initscr();
loop {
let input = get_wch();
match input.unwrap() {
WchResult::Char(ch) => {
match ch {
27 => break,
_ => { mvaddstr(0, 0, &format!("spam {}", ch)); }
}
},
WchResult::KeyCode(code) => { mvaddstr(0, 0, &format!("eggs {}", code)); }
}
}
endwin();
}
I was told that if I want to read UTF-8 characters, I should use get_wch()
, however when I input ć
, what is printed is ~G
. For ASCII characters, it prints spam <ch>
.
How do I handle Unicode properly in an ncurses app?