tuicast

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 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

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