Crate surf_n_term

source ·
Expand description

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, TerminalAction, SystemTerminal, 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(())
}

Re-exports§

Modules§

  • NFA and DFA
  • Common utility functions used across different modules
  • Decoders
  • Encoders
  • Error type
  • Type describing foreground/background/style-attrs of the terminal cell
  • Handling everything to do with images.
  • Terminal rendering logic
  • Surface object
  • Main interface to interact with terminal
  • Defines View that represents anything that can be rendered into a terminal. As well as some useful implementations such as Text, Flex, Container, …

Structs§

  • Bounding box with sides directed along the axes
  • Alpha premultiplied RGBA color in the linear color space (no gamma correction)
  • Collection of the SubPath treated as a single unit. Represents the same concept as an SVG path
  • sRGBA color packed as [u8; 4]

Enums§

  • The algorithm to use to determine the inside part of a shape, when filling it.

Traits§

  • Common interface to all color representations

Type Aliases§