ExUnit helpers for terminal-oriented tests.
These helpers keep Ghostty.Terminal focused on the core emulator API while
making test code concise for common tasks: render iodata, inspect plain/HTML
snapshots, assert visible text, and encode keyboard input.
Import this module in tests:
import Ghostty.Test
{:ok, term} = term(cols: 80, rows: 24)
write(term, ["Hello", ""])
assert_text(term, "Hello")
Summary
Functions
Asserts a cell's grapheme and optional style properties.
Asserts against an HTML snapshot.
Asserts a snapshot against a fixture file.
Asserts that a terminal/text snapshot includes a string or matches a regex.
Asserts against a VT snapshot.
Returns the cell at {x, y} using zero-based coordinates.
Returns terminal cells.
Builds a Ghostty.KeyEvent with defaults for tests.
Shortcut for an HTML snapshot.
Encodes a key event through Ghostty's terminal encoder.
Encodes a key event using a short-lived terminal.
Writes lines separated with CRLF and returns the terminal.
Shortcut for a plain-text snapshot.
Refutes against an HTML snapshot.
Refutes that a terminal/text snapshot includes a string or matches a regex.
Refutes against a VT snapshot.
Returns a terminal snapshot. Defaults to :plain.
Starts a Ghostty.Terminal for tests.
Shortcut for a VT snapshot.
Writes iodata to the terminal and returns the terminal.
Encodes a key and writes the resulting bytes to the terminal.
Types
@type terminal() :: GenServer.server()
Functions
@spec assert_cell( terminal(), {non_neg_integer(), non_neg_integer()}, binary(), keyword() ) :: terminal()
Asserts a cell's grapheme and optional style properties.
Asserts against an HTML snapshot.
@spec assert_snap(snapshot_source(), Path.t(), keyword()) :: snapshot_source()
Asserts a snapshot against a fixture file.
Set UPDATE_GHOSTTY_SNAPSHOTS=1 to rewrite fixtures.
@spec assert_text(snapshot_source(), String.t() | Regex.t()) :: snapshot_source()
Asserts that a terminal/text snapshot includes a string or matches a regex.
Asserts against a VT snapshot.
@spec cell( terminal(), {non_neg_integer(), non_neg_integer()} ) :: Ghostty.Terminal.cell()
Returns the cell at {x, y} using zero-based coordinates.
@spec cells(terminal()) :: [[Ghostty.Terminal.cell()]]
Returns terminal cells.
@spec event( Ghostty.KeyEvent.key(), keyword() ) :: Ghostty.KeyEvent.t()
Builds a Ghostty.KeyEvent with defaults for tests.
Shortcut for an HTML snapshot.
@spec key(terminal(), Ghostty.KeyEvent.key() | Ghostty.KeyEvent.t(), keyword()) :: {:ok, binary()} | :none
Encodes a key event through Ghostty's terminal encoder.
@spec key_bytes( Ghostty.KeyEvent.key() | Ghostty.KeyEvent.t(), keyword() ) :: binary() | :none
Encodes a key event using a short-lived terminal.
Writes lines separated with CRLF and returns the terminal.
Shortcut for a plain-text snapshot.
Refutes against an HTML snapshot.
@spec refute_text(snapshot_source(), String.t() | Regex.t()) :: snapshot_source()
Refutes that a terminal/text snapshot includes a string or matches a regex.
Refutes against a VT snapshot.
@spec snap(terminal(), Ghostty.Terminal.format()) :: binary()
Returns a terminal snapshot. Defaults to :plain.
@spec term(keyword()) :: GenServer.on_start()
Starts a Ghostty.Terminal for tests.
Shortcut for a VT snapshot.
Writes iodata to the terminal and returns the terminal.
@spec write_key(terminal(), Ghostty.KeyEvent.key() | Ghostty.KeyEvent.t(), keyword()) :: terminal()
Encodes a key and writes the resulting bytes to the terminal.