I used to use Termion for managing my dynamic menus, but the truth is that the crate's weight was too much for my production projects.
While searching on the official crates.io website, I came across a crate that served the same purpose as Termion but was lighter and had a lower-level logic. I'm talking about k_board.
I compared them in terms of syntax, and I find k_board even more comfortable than Termion.
Official termion example in crates.io:
fn main() {
let stdin = stdin();
let mut stdout = MouseTerminal::from(stdout().into_raw_mode().unwrap());
write!(stdout, "{}{}q to exit. Click, click, click!", termion::clear::All, termion::cursor::Goto(1, 1)).unwrap();
stdout.flush().unwrap();
for c in stdin.events() {
let evt = c.unwrap();
match evt {
Event::Key(Key::Char('q')) => break,
Event::Mouse(me) => {
match me {
MouseEvent::Press(_, x, y) => {
write!(stdout, "{}x", termion::cursor::Goto(x, y)).unwrap();
},
_ => (),
}
}
_ => {}
}
stdout.flush().unwrap();
}
}
Official k_board example in crates.io:
fn main() {
std::process::Command::new("clear").status().unwrap();
println!("[*] I use k_board lightweight software");
println!("[ ] I use heavyweight software");
for key in Keyboard::new() {
match key {
Keys::Up => {
std::process::Command::new("clear").status().unwrap();
println!("[*] I use k_board lightweight software");
println!("[ ] I use heavyweight software");
}
Keys::Down => {
std::process::Command::new("clear").status().unwrap();
println!("[ ] I use k_board lightweight software");
println!("[*] I use heavyweight software");
}
Keys::Enter => {
break;
}
_ => {}
}
}
}
I've done a comparison between the two, and I'm making the information available to you.
Top comments (0)