feat(vt): port the stream layer between parser and handlers

Ports ZIG/src/terminal/stream.zig: the Stream feeds bytes through the
UTF-8 decoder and parser and dispatches every CSI/ESC/OSC/DCS/APC and
C0/C1 control to a Handler as a high-level Action (all 95 Zig
variants). Zig's comptime handler interface becomes a Handler trait with
an associated error type, a required vt() and an optional vt_raw() hook.

Performance: next_slice() processes 4 KiB chunks, finds ESC with memchr
and decodes printable runs in bulk (scalar port of ZIG/src/simd's
index_of / utf8_decode_until_control_seq), plus the CSI parameter fast
path.

Terminals must construct the stream with Stream::new_alloc so the OSC
parser accepts allocating commands (colors, OSC 133), as in Zig.

Minor differences: after a stray UTF-8 byte the rest of the chunk
returns to the fast path, and a spurious Zig warning after CSI 2/5 W is
dropped.

Test Plan:
- cargo test -p ghostty-vt (448 passed; 37/38 stream tests ported,
  the skipped one only exercises the C ABI)
This commit is contained in:
ddidderr committed 2026-10-11 21:59:15 +02:00
1 parent 3afe938b95
commit 800fe5be5e
7 files changed
+2635 -6

No files matched your search

+7
View File
@@ -49,6 +49,13 @@ impl Utf8Decoder {
}
}
/// True if the decoder is in the middle of a multi-byte sequence
/// (Zig: `state != 0`).
#[inline]
pub const fn in_sequence(&self) -> bool {
self.state != ACCEPT_STATE
}
/// Takes the next byte in the utf-8 sequence and emits a tuple of
/// - The codepoint that was generated, if there is one.
/// - A boolean that indicates whether the provided byte was consumed.