Crate termsnap_lib

Source
Expand description

In-memory emulation of ANSI-escaped terminal data and rendering emulated terminal screens to SVG files.

use termsnap_lib::{FontMetrics, Term, VoidPtyWriter};

// Create a new terminal emulator and process some bytes.
let mut term = Term::new(24, 80, VoidPtyWriter);
for byte in b"a line of \x1B[32mcolored\x1B[0m terminal data" {
    term.process(*byte);
}

// Create a snapshot of the terminal screen grid.
let screen = term.current_screen();

let text: String = screen.cells().map(|c| c.c).collect();
assert_eq!(text.trim(), "a line of colored terminal data");

assert_eq!(&format!("{}", screen.get(0, 0).unwrap().fg), "#839496");
assert_eq!(&format!("{}", screen.get(0, 10).unwrap().fg), "#859900");

// Render the screen to SVG.
println!("{}", screen.to_svg(&[], FontMetrics::DEFAULT));

Structs§

Cell
The unicode character and style of a single cell in the terminal grid.
FontMetrics
Metrics for rendering a monospaced font.
Rgb
A color in the sRGB color space.
Screen
A static snapshot of a terminal screen.
Term
An in-memory terminal emulator.
VoidPtyWriter
A PtyWriter that ignores all responses.

Enums§

AnsiSignal

Traits§

PtyWriter
A sink for responses sent by the terminal emulator. The terminal emulator sends responses to ANSI requests. Implement this trait to process these responses, e.g., by sending them to the requesting pseudoterminal.

Functions§

emulate
Feed an ANSI sequence through a terminal emulator, returning the resulting terminal screen contents.