tuicast

package module
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 2, 2026 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

tuicast

tuicast

Table of Contents

Background

  • Goal
    • To create a TUI automation framework, allowing you to control a terminal based application programatically. Use cases for such a framework include:
      • End-to-end (E2E) testing - simulate a real user flow and assert the app behaves correctly
      • Automation - expose a surface for terminal applications to be integrated into automated workflows

TUICast makes terminal-based applications testable and automatable through reliable, programmatic control of interactive terminal sessions. It abstracts connection protocols and terminal behavior so engineers can interact with legacy TUIs using deterministic, modern automation APIs.

  • Background and problem

    • Some enterprise systems still use interactive terminal interfaces over SSH or Telnet. Automating them can be challenging because they are stateful screen applications rather than command-line programs:
      • Output arrives incrementally.
      • Escape sequences update an existing screen.
      • Input includes special keys, not just text.
      • Applications often provide no explicit "ready" signal.
      • Tests may need hundreds of isolated, concurrent sessions.
    • TUICast provides one abstraction over those concerns.
  • Intended users

    • Engineers testing legacy enterprise TUI applications
    • Teams integrating terminal-only systems into automated workflows
    • Test-tool and SDK authors
    • AI agents or orchestration systems that need controlled TUI access
  • Primary use cases

    • End-to-end testing: Perform realistic user workflows and assert screen contents, cursor position, or other terminal state.
    • Business-process automation: Integrate terminal-only applications into larger workflows.
    • Concurrency and load scenarios: Run many independent users or sessions simultaneously.
    • Observability and diagnostics: Capture terminal state and failures in a form test tools can report.
    • Language-neutral integration: Control TUICast through its driver and language SDKs.
    • AI-assisted operation: Expose a constrained terminal automation surface through MCP
  • Glossary

Installation

SDK

The SDK launches tuicast-driver, so install that separately and make sure it is available on your PATH.

Go

To install the SDK for Go, use go get.

go get github.com/castingcode/tuicast/sdk/go@latest

Then in your code, import the SDK as:

import tuicast "github.com/castingcode/tuicast/sdk/go"
Driver and Other Binaries (reference tui application)
Homebrew
brew install --cask castingcode/tap/tuicast
WinGet
winget install --exact --id CastingCode.TUICast
Scoop
scoop bucket add castingcode https://github.com/castingcode/scoop-bucket.git
scoop install castingcode/tuicast

These packages install tuicast-driver, tuicast-mcp, and reference-tui.

Using the install script

The default destination is ./bin. Add the selected directory to PATH if necessary.

macOS and Linux

Install the driver into ./bin:

curl --proto '=https' --tlsv1.2 -LsSf \
  https://github.com/castingcode/tuicast/releases/latest/download/install.sh | sh

Install the reference TUI:

curl --proto '=https' --tlsv1.2 -LsSf \
  https://github.com/castingcode/tuicast/releases/latest/download/install.sh |
  sh -s -- --component reference-tui

Install everything into ~/.local/bin:

curl --proto '=https' --tlsv1.2 -LsSf \
  https://github.com/castingcode/tuicast/releases/latest/download/install.sh |
  sh -s -- --component all --bin-dir "$HOME/.local/bin"

Install a specific version:

curl --proto '=https' --tlsv1.2 -LsSf \
  https://github.com/castingcode/tuicast/releases/latest/download/install.sh |
  sh -s -- --component driver v0.0.1
Windows PowerShell

Install the driver:

$install = [scriptblock]::Create((irm `
  https://github.com/castingcode/tuicast/releases/latest/download/install.ps1))

& $install -Component driver

Reference TUI:

& $install -Component reference-tui

Everything in a chosen directory:

& $install -Component all -BinDir "$HOME\bin"

Specific version:

& $install -Component driver -Version v0.0.1
Using npm

Install the driver and reference TUI globally on macOS, Linux, or Windows:

npm install --global @castingcode/tuicast-cli

The installer selects the release for the current operating system and CPU, downloads tuicast-driver and reference-tui, and verifies their SHA-256 checksums. This package is separate from the @castingcode/tuicast TypeScript SDK.

Linux packages

Each GitHub release includes deb, rpm, and apk packages containing tuicast-driver, tuicast-mcp, and reference-tui. Download the package for your CPU architecture from the release and install it with the platform package manager, for example:

sudo apt install ./tuicast_VERSION_linux_amd64.deb
Using Go install

Alternatively, you can use go install to install the binaries. Ensure $GOBIN or $GOPATH/bin is on PATH, as the SDK will launch the driver.

To install, run:

go install github.com/castingcode/tuicast/cmd/tuicast-driver@latest

The reference TUI and MCP server also support go install:

go install github.com/castingcode/tuicast/cmd/reference-tui@latest
go install github.com/castingcode/tuicast/cmd/tuicast-mcp@latest

Running the Reference TUI

The reference TUI is a deterministic terminal application for demonstrations, integration tests, and exercising TUICast automation.

Run interactively
reference-tui

Use Ctrl-C to exit.

Serve over SSH
reference-tui --ssh-address 127.0.0.1:2222

Connect from another terminal:

ssh -tt \
  -o PreferredAuthentications=password \
  -o PubkeyAuthentication=no \
  operator@127.0.0.1 -p 2222

Default credentials:

Username: operator
Password: casting

Custom credentials can be provided when starting the server:

reference-tui \
  -ssh-address 127.0.0.1:2222 \
  -ssh-username warehouse \
  -ssh-password secret

Or by using the -ssh-users-file and supplying a path to a json file containing key value pairs of user:password, such as {"operator":"casting","supervisor":"warehouse"}.

To use a stable SSH host key:

reference-tui \
  -ssh-address 127.0.0.1:2222 \
  -ssh-host-key ./host-key

These credentials are intended for local demonstrations and testing, not production use.

Serve over Telnet
reference-tui -telnet-address 127.0.0.1:2323

Connect from another terminal:

telnet 127.0.0.1 2323

The SSH and Telnet address options are mutually exclusive. Start separate processes when both protocols are needed.

Run VTTEST scenarios

The reference application can launch the external vttest utility from its menu. Install it separately and ensure it is on PATH:

brew install vttest

On Linux, install vttest through your distribution’s package manager.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnswerbackTerminal

type AnswerbackTerminal interface {
	SetAnswerback(string) error
}

AnswerbackTerminal configures the response sent when the host transmits ENQ.

type Attributes

type Attributes uint16

Attributes describes a cell's graphic rendition.

const (
	Bold Attributes = 1 << iota
	Underline
	Blink
	Reverse
	Conceal
)

func (Attributes) Has

func (a Attributes) Has(attributes Attributes) bool

Has reports whether all requested attributes are set.

type Cell

type Cell struct {
	Text       string
	Width      int
	Foreground Color
	Background Color
	Attributes Attributes
}

Cell is one terminal screen cell. Text is normally one character. Width is one for a normal cell, two for a wide character, and zero for its continuation.

type Color

type Color int16

Color is a terminal palette index. DefaultColor selects the terminal's configured default foreground or background.

const (
	Black Color = iota
	Red
	Green
	Yellow
	Blue
	Magenta
	Cyan
	White
)
const (
	DefaultColor Color = -1
)

type Connection

type Connection struct {
	// contains filtered or unexported fields
}

Connection is a server-managed connection to a remote terminal server.

func (*Connection) Close

func (c *Connection) Close() error

Close closes every session and then the underlying connection. It is idempotent.

func (*Connection) ID

func (c *Connection) ID() uint64

ID returns the connection's server-unique identifier.

func (*Connection) NewSession

func (c *Connection) NewSession(ctx context.Context, terminal Terminal) (*Session, error)

NewSession opens and starts an interactive session on the connection.

type Connector

type Connector interface {
	Connect(context.Context) (SessionOpener, error)
}

Connector establishes a connection capable of opening terminal sessions.

type Cursor

type Cursor struct {
	Column  int
	Row     int
	Visible bool
}

Cursor is a zero-based cursor position and its visibility state.

type Key

type Key string

Key identifies a named terminal key or one printable character.

const (
	KeyEnter     Key = "Enter"
	KeyTab       Key = "Tab"
	KeyBackspace Key = "Backspace"
	KeyEscape    Key = "Escape"
	KeyUp        Key = "ArrowUp"
	KeyDown      Key = "ArrowDown"
	KeyRight     Key = "ArrowRight"
	KeyLeft      Key = "ArrowLeft"
	KeyHome      Key = "Home"
	KeyEnd       Key = "End"
	KeyInsert    Key = "Insert"
	KeyDelete    Key = "Delete"
	KeyPageUp    Key = "PageUp"
	KeyPageDown  Key = "PageDown"
	KeyF1        Key = "F1"
	KeyF2        Key = "F2"
	KeyF3        Key = "F3"
	KeyF4        Key = "F4"
	KeyF5        Key = "F5"
	KeyF6        Key = "F6"
	KeyF7        Key = "F7"
	KeyF8        Key = "F8"
	KeyF9        Key = "F9"
	KeyF10       Key = "F10"
	KeyF11       Key = "F11"
	KeyF12       Key = "F12"
)

type KeyEncoder

type KeyEncoder interface {
	EncodeKey(Key) ([]byte, error)
}

KeyEncoder converts named keys to the byte sequence expected by a terminal profile. Terminal implementations may satisfy this in addition to Terminal.

type KeyModifier

type KeyModifier uint8

KeyModifier identifies modifiers applied to a key press. Alt and Meta are aliases because ANSI terminals conventionally encode both as an Escape prefix or the same CSI modifier bit.

const (
	ModifierShift KeyModifier = 1 << iota
	ModifierAlt
	ModifierControl

	ModifierMeta = ModifierAlt
)

type KeyPress

type KeyPress struct {
	Key       Key
	Modifiers KeyModifier
}

KeyPress describes one key and its combined modifiers.

func NewKeyPress

func NewKeyPress(key Key, modifiers ...KeyModifier) (KeyPress, error)

NewKeyPress combines modifiers into one key press.

type ModifiedKeyEncoder

type ModifiedKeyEncoder interface {
	EncodeKeyPress(KeyPress) ([]byte, error)
}

ModifiedKeyEncoder converts key presses with modifiers to the byte sequence expected by a terminal profile.

type Screen

type Screen struct {
	Width    int
	Height   int
	Cells    []Cell
	Cursor   Cursor
	Revision uint64
}

Screen is a detached, row-major terminal snapshot. The Cells slice belongs to the snapshot and is never reused by the terminal that produced it.

func (Screen) CellAt

func (s Screen) CellAt(column, row int) (Cell, bool)

CellAt returns the cell at a zero-based position.

func (Screen) Line

func (s Screen) Line(row int) string

Line returns one row's text, including trailing spaces.

func (Screen) Text

func (s Screen) Text() string

Text returns every row joined by a newline. It preserves trailing spaces and does not append a newline after the final row.

type ScreenMatcher

type ScreenMatcher interface {
	Match(Screen) bool
}

ScreenMatcher determines whether a screen has reached an expected state.

func AllOf

func AllOf(matchers ...ScreenMatcher) ScreenMatcher

AllOf matches when every matcher succeeds. An empty AllOf matches every screen.

func AnyOf

func AnyOf(matchers ...ScreenMatcher) ScreenMatcher

AnyOf matches when at least one matcher succeeds. An empty AnyOf never matches.

func CursorAt

func CursorAt(column, row int) ScreenMatcher

CursorAt matches the cursor's zero-based position.

func Not

func Not(matcher ScreenMatcher) ScreenMatcher

Not matches when matcher does not succeed.

func ScreenContains

func ScreenContains(text string) ScreenMatcher

ScreenContains matches when the exact screen text contains text.

func ScreenLineEquals

func ScreenLineEquals(row int, text string) ScreenMatcher

ScreenLineEquals matches when row contains exactly text, including trailing spaces. Rows are zero-based.

type ScreenMatcherFunc

type ScreenMatcherFunc func(Screen) bool

ScreenMatcherFunc adapts a function into a ScreenMatcher.

func (ScreenMatcherFunc) Match

func (f ScreenMatcherFunc) Match(screen Screen) bool

Match calls the adapted function.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server owns terminal connection and session lifecycles.

func NewServer

func NewServer(logger *slog.Logger) (*Server, error)

NewServer creates a terminal server using logger for lifecycle events.

func (*Server) Close

func (s *Server) Close() error

Close closes all tracked sessions and connections. It is idempotent.

func (*Server) Connect

func (s *Server) Connect(ctx context.Context, connector Connector) (*Connection, error)

Connect establishes and tracks a transport connection.

type Session

type Session struct {
	// contains filtered or unexported fields
}

Session coordinates one transport stream with one terminal.

func (*Session) Close

func (s *Session) Close() error

Close closes the stream and waits for its read loop to stop. It is idempotent.

func (*Session) Done

func (s *Session) Done() <-chan struct{}

Done is closed when the remote session ends or Close completes.

func (*Session) Err

func (s *Session) Err() error

Err returns the error that ended the session, if any.

func (*Session) Events

func (s *Session) Events(ctx context.Context) <-chan TerminalEvent

Events observes BELL, ENQ, and future non-screen terminal events. Each event has a session-monotonic sequence. A subscriber that cannot keep up is closed rather than blocking terminal processing.

func (*Session) ID

func (s *Session) ID() uint64

ID returns the session's server-unique identifier.

func (*Session) Press

func (s *Session) Press(key Key, modifiers ...KeyModifier) error

Press sends the terminal-profile sequence for a named or printable key with optional modifiers.

func (*Session) Resize

func (s *Session) Resize(width, height int) error

Resize changes both the local terminal and the remote session dimensions.

func (*Session) Screen

func (s *Session) Screen() Screen

Screen returns the terminal's current detached snapshot.

func (*Session) Screens

func (s *Session) Screens(ctx context.Context) <-chan Screen

Screens observes detached snapshots. It sends the current snapshot first, then the latest snapshot after each visible screen revision. A slow observer may skip intermediate revisions. The channel closes when ctx or the session ends.

func (*Session) Send

func (s *Session) Send(data []byte) error

Send writes input to the remote terminal session. Concurrent sends are serialized so their byte streams cannot interleave.

func (*Session) WaitFor

func (s *Session) WaitFor(ctx context.Context, matcher ScreenMatcher) (Screen, error)

WaitFor waits until matcher accepts a screen, the context expires, or the session ends.

func (*Session) WaitForIdle

func (s *Session) WaitForIdle(ctx context.Context, quietPeriod time.Duration) (Screen, error)

WaitForIdle waits until no host output arrives for quietPeriod. Host bytes that do not visibly change the screen still reset the quiet period.

func (*Session) WaitForStable

func (s *Session) WaitForStable(ctx context.Context, matcher ScreenMatcher, quietPeriod time.Duration) (Screen, error)

WaitForStable waits until matcher succeeds and no host output arrives for quietPeriod. The matcher is checked again after the quiet period.

type SessionOpener

type SessionOpener interface {
	OpenSession(context.Context, SessionRequest) (SessionStream, error)
	Close() error
}

SessionOpener is the transport-specific side of a Connection.

type SessionRequest

type SessionRequest struct {
	TerminalType string
	Width        int
	Height       int
}

SessionRequest describes the terminal requested from a remote server.

type SessionStream

type SessionStream interface {
	io.ReadWriteCloser
	Resize(width, height int) error
}

SessionStream carries one interactive terminal session. Close must unblock any pending Read so session shutdown can complete.

type Terminal

type Terminal interface {
	io.Writer
	Profile() TerminalProfile
	Resize(width, height int) error
	Snapshot() Screen
}

Terminal consumes bytes received from a host and maintains terminal state. Implementations return detached snapshots that remain stable as more bytes are processed.

type TerminalEvent

type TerminalEvent struct {
	Sequence uint64
	Type     TerminalEventType
	Data     string
}

TerminalEvent reports a terminal control event. Sequence is assigned by the session; Data contains the configured answerback for an enquiry.

type TerminalEventDrainer

type TerminalEventDrainer interface {
	DrainEvents() []TerminalEvent
}

TerminalEventDrainer exposes events produced synchronously by Terminal.Write. The session drains events after each host-output write.

type TerminalEventType

type TerminalEventType string

TerminalEventType identifies a non-screen event emitted while processing host output.

const (
	EventBell    TerminalEventType = "bell"
	EventEnquiry TerminalEventType = "enquiry"
)

type TerminalProfile

type TerminalProfile string

TerminalProfile identifies the behavior emulated by a terminal.

const (
	// ProfileVT220 identifies the DEC VT220 terminal profile.
	ProfileVT220 TerminalProfile = "vt220"
	// ProfileXTerm identifies the xterm terminal profile with 256-color support.
	ProfileXTerm TerminalProfile = "xterm-256color"
)

type WaitError

type WaitError struct {
	Expected   string
	LastScreen Screen
	Cause      error
}

WaitError reports why a screen wait ended and retains the last observed snapshot for assertion diagnostics.

func (*WaitError) Error

func (e *WaitError) Error() string

func (*WaitError) Unwrap

func (e *WaitError) Unwrap() error

Unwrap returns the context or session error that ended the wait.

Directories

Path Synopsis
Package ansi provides shared ANSI/DEC terminal emulation for concrete terminal profiles.
Package ansi provides shared ANSI/DEC terminal emulation for concrete terminal profiles.
cmd
reference-tui command
tuicast-driver command
tuicast-mcp command
Package driver exposes TUICast through a language-neutral JSON-RPC protocol.
Package driver exposes TUICast through a language-neutral JSON-RPC protocol.
Package driverui provides the read-only TUICast Inspector HTTP application.
Package driverui provides the read-only TUICast Inspector HTTP application.
Package mcpserver exposes TUICast terminal automation as MCP tools.
Package mcpserver exposes TUICast terminal automation as MCP tools.
Package memory provides an in-memory transport for automation and tests.
Package memory provides an in-memory transport for automation and tests.
Package parsing converts a terminal byte stream into ANSI/DEC parser events.
Package parsing converts a terminal byte stream into ANSI/DEC parser events.
Package reference implements the deterministic TUI used to exercise TUICast automation and terminal emulation.
Package reference implements the deterministic TUI used to exercise TUICast automation and terminal emulation.
ssh
Package ssh serves the reference TUI over SSH.
Package ssh serves the reference TUI over SSH.
telnet
Package telnet serves the reference TUI over Telnet.
Package telnet serves the reference TUI over Telnet.
sdk
go module
Package ssh implements SSH transport using golang.org/x/crypto/ssh.
Package ssh implements SSH transport using golang.org/x/crypto/ssh.
Package telnet implements Telnet transport and option negotiation.
Package telnet implements Telnet transport and option negotiation.
Package vt220 implements the TUICast DEC VT220 terminal profile.
Package vt220 implements the TUICast DEC VT220 terminal profile.
Package workbench records and replays language-neutral terminal workflows.
Package workbench records and replays language-neutral terminal workflows.
Package xterm implements the TUICast xterm terminal profile.
Package xterm implements the TUICast xterm terminal profile.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL