Files
ghostty/example/zig-formatter
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: stdin to HTML using vtStream and TerminalFormatter

This example demonstrates how to read VT sequences from stdin, parse them using vtStream, and output styled HTML using TerminalFormatter. The purpose of this example is primarily to show how to use formatters with terminals.

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

Usage

Basic usage:

echo -e "Hello \033[1;32mGreen\033[0m World" | zig build run

This will output HTML with inline styles and CSS palette variables.

You can also pipe complex terminal output:

ls --color=always | zig build run > output.html