tuicast

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 11 Imported by: 0 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.

Documentation

Overview

Package tuicast provides an idiomatic Go client for the TUICast driver.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsTimeout

func IsTimeout(err error) bool

IsTimeout reports whether err is a driver or client-side wait timeout.

Types

type Attributes

type Attributes uint16

Attributes is the terminal cell attribute bitmask.

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

func (Attributes) Has

func (attributes Attributes) Has(requested Attributes) bool

Has reports whether all requested attributes are set.

type Cell

type Cell struct {
	Text       string     `json:"text"`
	Width      int        `json:"width"`
	Foreground Color      `json:"foreground"`
	Background Color      `json:"background"`
	Attributes Attributes `json:"attributes"`
}

Cell is one terminal screen cell.

type Color

type Color int16

Color is a terminal palette index. Minus one selects the terminal default.

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 driver-managed transport connection.

func (*Connection) Close

func (c *Connection) Close(ctx context.Context) error

Close closes the connection and every session opened from it. It is idempotent.

func (*Connection) ID

func (c *Connection) ID() uint64

ID returns the driver's connection identifier.

func (*Connection) OpenSession

func (c *Connection) OpenSession(ctx context.Context, options ...SessionOption) (*Session, error)

OpenSession opens a VT220 80x24 session unless options override the defaults.

type ConnectionConfig

type ConnectionConfig interface {
	// contains filtered or unexported methods
}

ConnectionConfig describes one supported transport connection.

type Cursor

type Cursor struct {
	Column  int  `json:"column"`
	Row     int  `json:"row"`
	Visible bool `json:"visible"`
}

Cursor is a zero-based terminal cursor position.

type Driver

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

Driver owns one driver process and its connections.

func Launch

func Launch(ctx context.Context, options ...LaunchOption) (*Driver, error)

Launch starts a driver, verifies its protocol version, and returns a client.

func (*Driver) Close

func (c *Driver) Close() error

Close shuts down the driver and waits for its process to exit. It is idempotent.

func (*Driver) Connect

func (c *Driver) Connect(ctx context.Context, config ConnectionConfig) (*Connection, error)

Connect opens a typed SSH or Telnet connection.

type EventSubscription

type EventSubscription struct {
	Events <-chan TerminalEvent
	// contains filtered or unexported fields
}

EventSubscription delivers terminal events in order on Events. To avoid blocking the JSON-RPC reader, Events is closed if its buffer fills. It is also closed by Close or when the driver stops.

func (*EventSubscription) Close

func (s *EventSubscription) Close(ctx context.Context) error

Close unsubscribes and closes Events. It is idempotent.

type IdleOption

type IdleOption func(*idleConfig) error

IdleOption configures an idle wait.

func IdleFor

func IdleFor(duration time.Duration) IdleOption

IdleFor overrides the default 100 millisecond host-output quiet period.

func IdleTimeout

func IdleTimeout(timeout time.Duration) IdleOption

IdleTimeout overrides the client's default timeout for one idle wait.

type Key

type Key string

Key identifies a named terminal key or one printable character.

const (
	Enter      Key = "Enter"
	Tab        Key = "Tab"
	Backspace  Key = "Backspace"
	Escape     Key = "Escape"
	ArrowUp    Key = "ArrowUp"
	ArrowDown  Key = "ArrowDown"
	ArrowRight Key = "ArrowRight"
	ArrowLeft  Key = "ArrowLeft"
	Home       Key = "Home"
	End        Key = "End"
	Insert     Key = "Insert"
	Delete     Key = "Delete"
	PageUp     Key = "PageUp"
	PageDown   Key = "PageDown"
	F1         Key = "F1"
	F2         Key = "F2"
	F3         Key = "F3"
	F4         Key = "F4"
	F5         Key = "F5"
	F6         Key = "F6"
	F7         Key = "F7"
	F8         Key = "F8"
	F9         Key = "F9"
	F10        Key = "F10"
	F11        Key = "F11"
	F12        Key = "F12"
)

type LaunchOption

type LaunchOption func(*launchConfig) error

LaunchOption configures a driver process.

func WithDefaultTimeout

func WithDefaultTimeout(timeout time.Duration) LaunchOption

WithDefaultTimeout sets the maximum duration for operations whose context has no earlier deadline.

func WithDriverArgs

func WithDriverArgs(arguments ...string) LaunchOption

WithDriverArgs appends command-line arguments when launching the driver.

func WithDriverEnvironment

func WithDriverEnvironment(environment ...string) LaunchOption

WithDriverEnvironment adds environment entries in KEY=value form. Entries override inherited values with the same key.

func WithDriverPath

func WithDriverPath(path string) LaunchOption

WithDriverPath selects the tuicast-driver executable. The default resolves tuicast-driver through PATH.

func WithDriverStderr

func WithDriverStderr(stderr io.Writer) LaunchOption

WithDriverStderr selects where driver diagnostics are written. The default is the parent process's standard error.

type Matcher

type Matcher interface {
	// contains filtered or unexported methods
}

Matcher is a screen condition evaluated by the driver while waiting.

func All

func All(matchers ...Matcher) Matcher

All matches when every child matcher succeeds.

func Any

func Any(matchers ...Matcher) Matcher

Any matches when at least one child matcher succeeds.

func Contains

func Contains(text string) Matcher

Contains matches exact text anywhere in the complete screen text.

func CursorAt

func CursorAt(column, row int) Matcher

CursorAt matches a zero-based cursor position.

func LineEquals

func LineEquals(row int, text string) Matcher

LineEquals matches one complete zero-based screen row, including trailing spaces.

func Not

func Not(child Matcher) Matcher

Not matches when its child matcher does not succeed.

type Modifier

type Modifier string

Modifier identifies a terminal key modifier.

const (
	Shift   Modifier = "Shift"
	Control Modifier = "Control"
	Alt     Modifier = "Alt"
	Meta    Modifier = "Meta"
)

type Position

type Position struct {
	Column int
	Row    int
}

Position is a zero-based position on a screen.

type RPCError

type RPCError struct {
	Code    int             `json:"code"`
	Message string          `json:"message"`
	Data    json.RawMessage `json:"data,omitempty"`
}

RPCError is an error returned by the JSON-RPC driver.

func (*RPCError) Error

func (e *RPCError) Error() string

type SSH

type SSH struct {
	Address                  string
	Username                 string
	Password                 string
	PrivateKey               string
	PrivateKeyPassphrase     string
	KnownHostsFile           string
	HostKeyFingerprint       string
	InsecureSkipHostKeyCheck bool
	Timeout                  time.Duration
}

SSH configures an SSH connection. Password or PrivateKey is required, along with exactly one host-key verification option.

type Screen

type Screen struct {
	Width    int    `json:"width"`
	Height   int    `json:"height"`
	Cells    []Cell `json:"cells"`
	Cursor   Cursor `json:"cursor"`
	Revision uint64 `json:"revision"`
	Content  string `json:"text"`
	// Title is the window title most recently set by the host. It is empty
	// when the host has not set one or the terminal profile has no titles.
	Title string `json:"title"`
}

Screen is a detached terminal snapshot returned by the driver.

func (Screen) CellAt

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

CellAt returns a cell at a zero-based position.

func (Screen) Contains

func (s Screen) Contains(text string) bool

Contains reports whether exact text appears in the complete screen text.

func (Screen) Find

func (s Screen) Find(text string) (Position, bool)

Find returns the first row-major position at which exact text begins. Text must begin and end within one row.

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 the complete screen text, preserving rows and trailing spaces.

type ScreenSubscription

type ScreenSubscription struct {
	Screens <-chan Screen
	// contains filtered or unexported fields
}

ScreenSubscription delivers detached snapshots on Screens. Delivery is coalesced: when the consumer is slow, an unread snapshot is replaced by the newest one. Screens is closed by Close or when the driver stops.

func (*ScreenSubscription) Close

func (s *ScreenSubscription) Close(ctx context.Context) error

Close unsubscribes and closes Screens. It is idempotent.

type Session

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

Session is an interactive terminal session managed by the driver.

func (*Session) Close

func (s *Session) Close(ctx context.Context) error

Close closes the session. It is idempotent.

func (*Session) ID

func (s *Session) ID() uint64

ID returns the driver's session identifier.

func (*Session) Press

func (s *Session) Press(ctx context.Context, key Key, modifiers ...Modifier) error

Press sends a named or printable key with optional modifiers.

func (*Session) Resize

func (s *Session) Resize(ctx context.Context, width, height int) error

Resize changes the remote and emulated terminal dimensions.

func (*Session) Screen

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

Screen returns the current detached screen snapshot.

func (*Session) Send

func (s *Session) Send(ctx context.Context, data []byte) error

Send sends arbitrary bytes to the terminal session.

func (*Session) State added in v0.2.0

func (s *Session) State(ctx context.Context) (SessionState, error)

State reports whether the session is active or has ended, without waiting.

func (*Session) Subscribe

func (s *Session) Subscribe(ctx context.Context) (*ScreenSubscription, error)

Subscribe subscribes to coalesced screen snapshots, beginning with the current screen.

func (*Session) SubscribeEvents

func (s *Session) SubscribeEvents(ctx context.Context) (*EventSubscription, error)

SubscribeEvents subscribes to BELL, ENQ, and unsupported-sequence events. The subscription starts with up to the 64 most recent events the session retains, then delivers live events. Events are buffered in order. If the consumer cannot keep up, Events is closed rather than blocking unrelated driver responses; callers should continue reading it promptly.

func (*Session) Type

func (s *Session) Type(ctx context.Context, text string) error

Type sends UTF-8 text to the terminal session.

func (*Session) WaitFor

func (s *Session) WaitFor(ctx context.Context, matcher Matcher, options ...WaitOption) (Screen, error)

WaitFor waits until a serializable matcher succeeds.

func (*Session) WaitForEnd added in v0.2.0

func (s *Session) WaitForEnd(ctx context.Context, options ...WaitOption) (SessionState, error)

WaitForEnd waits until the host ends the session, such as after a sign-out. WaitTimeout overrides the client's default timeout; StableFor does not apply. A timeout returns a *WaitError with the last screen.

func (*Session) WaitForIdle

func (s *Session) WaitForIdle(ctx context.Context, options ...IdleOption) (Screen, error)

WaitForIdle waits until no host bytes arrive for the configured quiet period.

func (*Session) WaitForText

func (s *Session) WaitForText(ctx context.Context, text string, options ...WaitOption) (Screen, error)

WaitForText waits until exact text appears anywhere on the screen.

func (*Session) WaitForTextGone

func (s *Session) WaitForTextGone(ctx context.Context, text string, options ...WaitOption) (Screen, error)

WaitForTextGone waits until exact text no longer appears on the screen.

type SessionOption

type SessionOption func(*sessionConfig) error

SessionOption configures a terminal session.

func WithAnswerback

func WithAnswerback(answerback string) SessionOption

WithAnswerback configures printable ASCII sent automatically for ENQ.

func WithSize

func WithSize(width, height int) SessionOption

WithSize selects terminal dimensions. The default is 80 by 24.

func WithTerminal

func WithTerminal(profile TerminalProfile) SessionOption

WithTerminal selects the terminal profile. The default is VT220.

type SessionState added in v0.2.0

type SessionState struct {
	// Ended reports whether the session has stopped. An ended session's final
	// screen remains readable until the session is closed.
	Ended bool
	// Error describes the transport or terminal failure that ended the
	// session. It is empty while the session is active and after a normal end.
	Error string
}

SessionState reports whether the host has ended a session.

type Telnet

type Telnet struct {
	Address string
	Timeout time.Duration
}

Telnet configures a Telnet connection.

type TerminalEvent

type TerminalEvent struct {
	Sequence uint64            `json:"sequence"`
	Type     TerminalEventType `json:"type"`
	Data     string            `json:"data,omitempty"`
}

TerminalEvent is a BELL, ENQ, or unsupported-sequence event. Data is the configured answerback for ENQ and the ignored sequence, such as "CSI ? 2004 h", for an unsupported event.

type TerminalEventType

type TerminalEventType string

TerminalEventType identifies a terminal event.

const (
	EventBell    TerminalEventType = "bell"
	EventEnquiry TerminalEventType = "enquiry"
	// EventUnsupported reports host output the terminal profile ignored. Each
	// distinct sequence is reported once per session.
	EventUnsupported TerminalEventType = "unsupported"
)

type TerminalProfile

type TerminalProfile string

TerminalProfile identifies a terminal emulation profile.

const (
	VT220         TerminalProfile = "vt220"
	XTerm256Color TerminalProfile = "xterm-256color"
)

type WaitError

type WaitError struct {
	Kind       string
	Expected   string
	LastScreen Screen
	// Dump is the driver's flight-recorder dump for the failure in JSON-lines
	// trace format: the most recent host output (up to 64 KiB) with timing
	// and screen revisions, unsupported-sequence counts, and the failure.
	// Save it with a test report to diagnose the failure later.
	Dump string
	// DumpPath is the file holding the same dump when the driver runs with
	// -dump-dir.
	DumpPath string
	Cause    error
}

WaitError describes a failed driver-side wait and retains the last screen.

func (*WaitError) Error

func (e *WaitError) Error() string

func (*WaitError) Unwrap

func (e *WaitError) Unwrap() error

Unwrap returns the underlying JSON-RPC error.

type WaitOption

type WaitOption func(*waitConfig) error

WaitOption configures a screen wait.

func StableFor

func StableFor(duration time.Duration) WaitOption

StableFor requires matching state followed by a host-output quiet period.

func WaitTimeout

func WaitTimeout(timeout time.Duration) WaitOption

WaitTimeout overrides the client's default timeout for one wait.

Jump to

Keyboard shortcuts

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