114 releases (16 breaking)

0.17.4 Oct 26, 2024
0.16.4 Oct 6, 2024
0.15.0 Apr 17, 2024
0.14.0 Mar 31, 2024
0.1.3 May 26, 2021

#49 in Graphics APIs

Download history 121/week @ 2024-08-02 11/week @ 2024-08-09 76/week @ 2024-08-16 51/week @ 2024-08-23 4/week @ 2024-08-30 579/week @ 2024-09-13 70/week @ 2024-09-20 73/week @ 2024-09-27 163/week @ 2024-10-04 20/week @ 2024-10-11 313/week @ 2024-10-18 396/week @ 2024-10-25 18/week @ 2024-11-01

752 downloads per month

MIT license

470KB
12K SLoC

Surf-N-Term

Build Status MIT License Crate API Docs

This crate is used to interact with Posix terminal. It can be used to

  • Read events from the terminal
  • Send commands to the terminal
  • Render on a surface which will be reconciled with current content of the terminal
  • Issue direct commends to the terminal
  • Supports kitty/sixel image protocol

Simple example

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

Used by

  • you should checkout my sweep program to interactively filter through list of items

Dependencies

~7MB
~130K SLoC