#surf #term #posix #terminal #n

surf_n_term

Posix terminal rendering library

42 releases (4 breaking)

Uses new Rust 2021

0.5.6 Jul 28, 2022
0.4.1 May 23, 2022
0.3.15 Mar 11, 2022
0.3.11 Dec 23, 2021
0.1.3 May 26, 2021
Download history 65/week @ 2022-04-23 219/week @ 2022-04-30 235/week @ 2022-05-07 551/week @ 2022-05-14 189/week @ 2022-05-21 308/week @ 2022-05-28 215/week @ 2022-06-04 16/week @ 2022-06-11 2/week @ 2022-06-18 35/week @ 2022-06-25 119/week @ 2022-07-02 101/week @ 2022-07-09 90/week @ 2022-07-16 133/week @ 2022-07-23 63/week @ 2022-07-30

414 downloads per month

MIT license

335KB
9K 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

~4MB
~82K SLoC