cursormatrix

Crates.iocursormatrix
lib.rscursormatrix
version0.4.0
sourcesrc
created_at2020-12-26 08:36:34.991274
updated_at2022-11-06 09:12:32.753547
descriptionSimple and naive TUI Library for Rust
homepage
repositoryhttps://github.com/yasuyuky/cursormatrix
max_upload_size
id327414
size49,543
Yasuyuki YAMADA (yasuyuky)

documentation

README

cursormatrix

Simple and naive TUI Library for Rust

ci status

Example usage

use cursormatrix::{Direction, Event, Input, Term};

fn handle_event(ev: &Event, term: &mut Term) -> bool {
    match ev {
        &Event::Ctrl(Input::Chars(ref s)) => match s.as_str() {
            "C" => return false,
            _ => (),
        },
        &Event::Raw(Input::Arrow(Direction::Up)) => term.move_up().unwrap(),
        &Event::Raw(Input::Arrow(Direction::Down)) => term.move_down().unwrap(),
        &Event::Raw(Input::BackSpace) => term.cursor.backspace().unwrap(),
        &Event::Raw(Input::Chars(ref s)) => term.print(&s).unwrap(),
        &Event::TermSize(w, h) => term.matrix.refresh(w, h),
        _ => (),
    }
    true
}

fn main() {
    let (mut term, erx) = Term::with_input(true).expect("term");
    term.print("edit").unwrap();
    loop {
        if match erx.recv() {
            Ok(ev) => !handle_event(&ev, &mut term),
            Err(_) => false,
        } {
            break;
        }
    }
}

Test

cargo test

Example

cargo run example --debug
cat FILE | cargo run example --filter
Commit count: 360

cargo fmt