Files
ghostty/example/zig-vt-stream
Mitchell Hashimoto 2044e5030f terminal: make stream processing infallible
The terminal.Stream next/nextSlice functions can now no longer fail.
All prior failure modes were fully isolated in the handler `vt`
callbacks. As such, vt callbacks are now required to not return an error
and handle their own errors somehow.

Allowing streams to be fallible before was an incorrect design. It
caused problematic scenarios like in `nextSlice` early terminating
processing due to handler errors. This should not be possible.

There is no safe way to bubble up vt errors through the stream because
if nextSlice is called and multiple errors are returned, we can't
coalesce them. We could modify that to return a partial result but its
just more work for stream that is unnecessary. The handler can do all of
this.

This work was discovered due to cleanups to prepare for more C APIs.
Less errors make C APIs easier to implement! And, it helps clean up our
Zig, too.
2026-03-13 13:56:14 -07:00
..

Example: vtStream API for Parsing Terminal Streams

This example demonstrates how to use the vtStream API to parse and process VT sequences. The vtStream API is ideal for read-only terminal applications that need to parse terminal output without responding to queries, such as:

  • Replay tooling
  • CI log viewers
  • PaaS builder output
  • etc.

The stream processes VT escape sequences and updates terminal state, while ignoring sequences that require responses (like device status queries).

Requires the Zig version stated in the build.zig.zon file.

Usage

Run the program:

zig build run

The example will process various VT sequences including:

  • Plain text output
  • ANSI color codes
  • Cursor positioning
  • Line clearing
  • Multiple line handling

And display the final terminal state after processing all sequences.