extern crate ncurses;
use std::char;
use ncurses::*;
#[cfg(feature = "wide")]
fn main()
{
let locale_conf = LcCategory::all;
setlocale(locale_conf, "en_US.UTF-8");
initscr();
raw();
halfdelay(20);
mousemask(ALL_MOUSE_EVENTS as mmask_t, None);
keypad(stdscr(), true);
noecho();
addstr("Enter a character within 2 seconds: ").unwrap();
let ch = wget_wch(stdscr());
match ch {
Some(WchResult::KeyCode(KEY_MOUSE)) => {
attron(A_BOLD | A_BLINK);
addstr("\nMouse").unwrap();
attroff(A_BOLD | A_BLINK);
addstr(" pressed").unwrap();
}
Some(WchResult::KeyCode(_)) => {
attron(A_BOLD | A_BLINK);
addstr("\nKeycode").unwrap();
attroff(A_BOLD | A_BLINK);
addstr(" pressed").unwrap();
}
Some(WchResult::Char(c)) => {
addstr("\nKey pressed: ");
attron(A_BOLD | A_BLINK);
addstr(format!("{}\n", char::from_u32(c as u32).expect("Invalid char")).as_ref()).unwrap();
attroff(A_BOLD | A_BLINK);
}
None => {
addstr("\nYou didn't enter a character in time!").unwrap();
}
}
refresh();
nocbreak();
getch();
endwin();
}
#[cfg(not(feature = "wide"))]
fn main() {
initscr();
addstr("This example requires wide character support.").unwrap();
getch();
endwin();
}