8 unstable releases (3 breaking)

0.4.0 Jul 27, 2024
0.3.0 Jul 16, 2024
0.2.1 Jul 1, 2024
0.1.3 Jun 29, 2024

#381 in Command-line interface


Used in termsnap

MIT/Apache

38KB
963 lines

Termsnap 📸

Create SVGs from terminal output

MIT/Apache 2.0 Crates.io Docs

This provides utilities for in-memory emulation of ANSI-escaped terminal data and rendering emulated terminal screens to SVG files. Have a look at the documentation or see the Termsnap README.


lib.rs:

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));

Dependencies

~5–18MB
~197K SLoC