Skip to content

Terminal

Published version: thekevinscott.github.io/curtaincall/api/terminal/

curtaincall.terminal.Terminal

A terminal session backed by a real PTY and VT100 emulator.

Spawns the given command in a pseudo-terminal, reads its output in a background thread, and feeds it through pyte for accurate screen state.

Uses pyte.HistoryScreen for scrollback buffer support so that content scrolled off the visible viewport is still searchable by locators.

pid property

The child process id, or None if the terminal has not been started.

With suppress_stderr=True the child is the bash -c wrapper, not the command.

is_alive property

Whether the child process is still running.

exit_code property

The exit code of the child process, or None if still running.

start()

Spawn the child process and start reading its output.

write(text)

Send raw text to the PTY.

submit(text)

Send text followed by Enter.

click(row, col)

Left-click a viewport cell by sending an SGR mouse press then release.

row and col are 0-based viewport coordinates (the same convention as get_cursor()). The program under test must have enabled mouse tracking (e.g. \x1b[?1000h\x1b[?1006h) to receive the events.

get_by_text(text, *, full=False, scrollback=True)

Create a locator that matches text on the screen.

Parameters:

Name Type Description Default
text str | Pattern[str]

String or compiled regex to search for.

required
full bool

If True, match the entire line (stripped) instead of substring.

False
scrollback bool

If False, match only the visible viewport, not lines that have scrolled off the top.

True

Returns:

Type Description
Locator

A Locator instance (lazy -- doesn't search until used).

get_cursor()

Return the current cursor position.

get_buffer()

Return the full buffer (scrollback + viewport) as a 2D list of characters.

Scrollback lines come first (oldest at index 0), followed by the visible viewport rows. This means get_by_text() and other locator searches will find text that has scrolled off the top of the screen.

get_viewable_buffer()

Return the visible viewport only (no scrollback).

signal(sig)

Send a signal (e.g. signal.SIGSTOP) to the child process.

The signal goes to pid only, not its process group. It is a no-op once the child has exited.

wait(*, timeout=10.0)

Block until the child process exits and return its exit code.

Raises TimeoutError if the process doesn't exit within timeout seconds.

set_size(*, rows, cols)

Resize the terminal.

kill()

Terminate the child process and stop the reader thread.

to_snapshot()

Render the current screen as a box-drawn snapshot string.

screen_text()

Return the visible viewport as text, one line per row, trailing spaces stripped.

Scrollback is excluded. Use get_buffer() for the full history.