Crates.io | surf_n_term |
lib.rs | surf_n_term |
version | 0.17.4 |
source | src |
created_at | 2021-04-30 12:53:57.920236 |
updated_at | 2024-10-26 14:27:18.912548 |
description | Posix terminal rendering library |
homepage | https://github.com/aslpavel/surf-n-term |
repository | https://github.com/aslpavel/surf-n-term.git |
max_upload_size | |
id | 391535 |
size | 527,178 |
This crate is used to interact with Posix terminal. It can be used to
use surf_n_term::{Terminal, TerminalEvent, Error};
fn main() -> Result<(), Error> {
let ctrl_c = TerminalEvent::Key("ctrl+c".parse()?);
let mut term = SystemTerminal::new()?;
term.run_render(|term, event, mut view| -> Result<_, Error> {
// This function will be executed on each event from terminal
// - term - implements Terminal trait
// - event - is a TerminalEvent
// - view - is a Surface that can be used to render on, see render module for details
match event {
Some(event) if &event == &ctrl_c => {
// exit if 'ctrl+c' is pressed
Ok(TerminalAction::Quit(()))
}
_ => {
// do some rendering by updating the view
Ok(TerminalAction::Wait)
},
}
})?;
Ok(())
}
Full examples can be found in example submodule
$ cargo run --example mandelbrot
$ cargo run --example mouse
$ cargo run --example events