librustty 0.0.0

Experimental pure-Rust terminal emulation library; initial releases focus on VT stream parsing
Documentation
  • Coverage
  • 100%
    49 out of 49 items documented1 out of 1 items with examples
  • Size
  • Source code size: 62.5 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 662.2 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 2s Average build duration of successful builds.
  • all releases: 2s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • nijaru

librustty

librustty is the experimental public Rustty library. The Rust import name is rustty.

Milestone 0 contains only a pure-Rust, incremental VT stream parser. It dispatches printable characters, controls, ESC/CSI sequences, and bounded OSC, DCS, APC, PM, and SOS strings. It does not implement a terminal grid, cursor, styles, PTYs, rendering, or desktop integration.

use rustty::{Handler, Parser};

#[derive(Default)]
struct Collector {
    text: String,
}

impl Handler for Collector {
    fn print(&mut self, ch: char) {
        self.text.push(ch);
    }

    fn execute(&mut self, byte: u8) {
        if byte == b'\n' {
            self.text.push('\n');
        }
    }
}

let mut parser = Parser::new();
let mut collector = Collector::default();
parser.advance(&mut collector, b"hel");
parser.advance(&mut collector, b"lo\n");
parser.finish(&mut collector);
assert_eq!(collector.text, "hello\n");

advance can be called with any chunk size, including one byte at a time. The parser owns its mutable state and can be moved to another thread, but parsing requires exclusive mutable access. Handler event views are borrowed only for the duration of the callback and must be copied if they need to outlive it. DCS events separate their parameter/intermediate prefix, final byte, and bounded passthrough payload; APC, PM, and SOS expose their bounded payload without interpreting it.

The parser replaces malformed or incomplete UTF-8 with U+FFFD. C0 and raw C1 control bytes are dispatched as controls. Control-string payloads are retained only up to ParserOptions::max_string_bytes; excess bytes are discarded and the final event is marked truncated. CSI parameters preserve semicolon and colon structure, including empty values.

The API is experimental and may change in any 0.0.x release.