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

#392 in Command-line interface

Download history 20/week @ 2024-07-20 143/week @ 2024-07-27 2/week @ 2024-08-03 14/week @ 2024-09-14 1/week @ 2024-09-21 7/week @ 2024-09-28

523 downloads per month
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

~6–16MB
~216K SLoC