#surf #term #posix #terminal #n

surf_n_term

Posix terminal rendering library

28 releases

Uses new Rust 2021

0.3.12 Jan 2, 2022
0.3.11 Dec 23, 2021
0.3.9 Nov 30, 2021
0.1.3 May 26, 2021
Download history 31/week @ 2021-09-26 24/week @ 2021-10-03 15/week @ 2021-10-10 22/week @ 2021-10-17 115/week @ 2021-10-24 48/week @ 2021-10-31 22/week @ 2021-11-07 64/week @ 2021-11-14 93/week @ 2021-11-21 27/week @ 2021-11-28 28/week @ 2021-12-05 20/week @ 2021-12-12 44/week @ 2021-12-19 6/week @ 2021-12-26 51/week @ 2022-01-02 17/week @ 2022-01-09

118 downloads per month

MIT license

290KB
8K SLoC

Surf-N-Term

Build Status MIT License Crate API Docs

This crate is used to interract 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  - implementes Terminal trait
        // - event - is a TerminalEvent
        // - view  - is a Suface that can be used to render on, see render module for defails
        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 filtter through list of items

Dependencies

~6MB
~111K SLoC

a