{"modulePath":"github.com/castingcode/tuicast","version":"v0.2.1","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package tuicast\n\n## Types\n\n```go\ntype AnswerbackTerminal interface {\n\tSetAnswerback(string) error\n}\n```\nAnswerbackTerminal configures the response sent when the host transmits ENQ.\n\n```go\ntype Attributes uint16\n```\nAttributes describes a cell's graphic rendition.\n\n```go\nconst (\n\tBold Attributes = 1 \u003c\u003c iota\n\tUnderline\n\tBlink\n\tReverse\n\tConceal\n)\n```\n\n```go\nfunc (a Attributes) Has(attributes Attributes) bool\n```\nHas reports whether all requested attributes are set.\n\n```go\ntype Cell struct {\n\tText       string\n\tWidth      int\n\tForeground Color\n\tBackground Color\n\tAttributes Attributes\n}\n```\nCell 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.\n\n```go\ntype Color int16\n```\nColor is a terminal palette index. DefaultColor selects the terminal's configured default foreground or background.\n\n```go\nconst (\n\tBlack Color = iota\n\tRed\n\tGreen\n\tYellow\n\tBlue\n\tMagenta\n\tCyan\n\tWhite\n)\n```\n\n```go\nconst (\n\tDefaultColor Color = -1\n)\n```\n\n```go\ntype Connection struct {\n\t// contains filtered or unexported fields\n}\n```\nConnection is a server-managed connection to a remote terminal server.\n\n```go\nfunc (c *Connection) Close() error\n```\nClose closes every session and then the underlying connection. It is idempotent.\n\n```go\nfunc (c *Connection) ID() uint64\n```\nID returns the connection's server-unique identifier.\n\n```go\nfunc (c *Connection) NewSession(ctx context.Context, terminal Terminal) (*Session, error)\n```\nNewSession opens and starts an interactive session on the connection.\n\n```go\ntype Connector interface {\n\tConnect(context.Context) (SessionOpener, error)\n}\n```\nConnector establishes a connection capable of opening terminal sessions.\n\n```go\ntype Cursor struct {\n\tColumn  int\n\tRow     int\n\tVisible bool\n}\n```\nCursor is a zero-based cursor position and its visibility state.\n\n```go\ntype CursorMatcherSpec struct {\n\tColumn int `json:\"column\"`\n\tRow    int `json:\"row\"`\n}\n```\nCursorMatcherSpec describes CursorAt.\n\n```go\ntype FlightRecord struct {\n\tType     FlightRecordType\n\tOffset   time.Duration\n\tData     []byte\n\tRevision uint64\n\tWidth    int\n\tHeight   int\n}\n```\nFlightRecord is one entry in a flight recording. Offset is measured from the session start. Output records carry Data and the screen Revision after the terminal applied it; resize records carry Width and Height.\n\n```go\ntype FlightRecordType string\n```\nFlightRecordType identifies an entry in a flight recording.\n\n```go\nconst (\n\t// FlightOutput is one read of host output, recorded exactly as received.\n\tFlightOutput FlightRecordType = \"output\"\n\t// FlightResize is a change of terminal dimensions.\n\tFlightResize FlightRecordType = \"resize\"\n)\n```\n\n```go\ntype FlightRecording struct {\n\tProfile      TerminalProfile\n\tStart        time.Time\n\tCaptured     time.Duration\n\tWidth        int\n\tHeight       int\n\tDroppedBytes uint64\n\tRecords      []FlightRecord\n\tUnsupported  []UnsupportedSequence\n}\n```\nFlightRecording is a detached copy of a session's most recent host output, up to 64 KiB, kept so a failed wait can be traced back to the bytes that produced its last screen. Width and Height are the dimensions in effect before the first record. DroppedBytes counts earlier output no longer retained, so a replay of a recording with dropped bytes starts mid-stream.\n\n```go\ntype Key string\n```\nKey identifies a named terminal key or one printable character.\n\n```go\nconst (\n\tKeyEnter     Key = \"Enter\"\n\tKeyTab       Key = \"Tab\"\n\tKeyBackspace Key = \"Backspace\"\n\tKeyEscape    Key = \"Escape\"\n\tKeyUp        Key = \"ArrowUp\"\n\tKeyDown      Key = \"ArrowDown\"\n\tKeyRight     Key = \"ArrowRight\"\n\tKeyLeft      Key = \"ArrowLeft\"\n\tKeyHome      Key = \"Home\"\n\tKeyEnd       Key = \"End\"\n\tKeyInsert    Key = \"Insert\"\n\tKeyDelete    Key = \"Delete\"\n\tKeyPageUp    Key = \"PageUp\"\n\tKeyPageDown  Key = \"PageDown\"\n\tKeyF1        Key = \"F1\"\n\tKeyF2        Key = \"F2\"\n\tKeyF3        Key = \"F3\"\n\tKeyF4        Key = \"F4\"\n\tKeyF5        Key = \"F5\"\n\tKeyF6        Key = \"F6\"\n\tKeyF7        Key = \"F7\"\n\tKeyF8        Key = \"F8\"\n\tKeyF9        Key = \"F9\"\n\tKeyF10       Key = \"F10\"\n\tKeyF11       Key = \"F11\"\n\tKeyF12       Key = \"F12\"\n)\n```\n\n```go\ntype KeyEncoder interface {\n\tEncodeKey(Key) ([]byte, error)\n}\n```\nKeyEncoder converts named keys to the byte sequence expected by a terminal profile. Terminal implementations may satisfy this in addition to Terminal.\n\n```go\ntype KeyModifier uint8\n```\nKeyModifier 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.\n\n```go\nconst (\n\tModifierShift KeyModifier = 1 \u003c\u003c iota\n\tModifierAlt\n\tModifierControl\n\n\tModifierMeta = ModifierAlt\n)\n```\n\n```go\ntype KeyPress struct {\n\tKey       Key\n\tModifiers KeyModifier\n}\n```\nKeyPress describes one key and its combined modifiers.\n\n```go\nfunc NewKeyPress(key Key, modifiers ...KeyModifier) (KeyPress, error)\n```\nNewKeyPress combines modifiers into one key press.\n\n```go\ntype LineMatcherSpec struct {\n\tRow  int    `json:\"row\"`\n\tText string `json:\"text\"`\n}\n```\nLineMatcherSpec describes ScreenLineEquals.\n\n```go\ntype MatcherSpec struct {\n\tContains *string            `json:\"contains,omitempty\"`\n\tLine     *LineMatcherSpec   `json:\"line,omitempty\"`\n\tCursor   *CursorMatcherSpec `json:\"cursor,omitempty\"`\n\tAll      []MatcherSpec      `json:\"all,omitempty\"`\n\tAny      []MatcherSpec      `json:\"any,omitempty\"`\n\tNot      *MatcherSpec       `json:\"not,omitempty\"`\n}\n```\nMatcherSpec is a serializable screen expectation used by the driver protocol, MCP tools, and recorded workflows. Exactly one field must be set.\n\n```go\nfunc (s MatcherSpec) ScreenMatcher() (ScreenMatcher, error)\n```\nScreenMatcher builds the matcher described by s.\n\n```go\ntype ModifiedKeyEncoder interface {\n\tEncodeKeyPress(KeyPress) ([]byte, error)\n}\n```\nModifiedKeyEncoder converts key presses with modifiers to the byte sequence expected by a terminal profile.\n\n```go\ntype Screen struct {\n\tWidth    int\n\tHeight   int\n\tCells    []Cell\n\tCursor   Cursor\n\tRevision uint64\n\t// Title is the window title most recently set by the host. It is empty\n\t// when the host has not set one or the terminal profile has no titles.\n\tTitle string\n}\n```\nScreen is a detached, row-major terminal snapshot. The Cells slice belongs to the snapshot and is never reused by the terminal that produced it.\n\n```go\nfunc (s Screen) CellAt(column, row int) (Cell, bool)\n```\nCellAt returns the cell at a zero-based position.\n\n```go\nfunc (s Screen) Line(row int) string\n```\nLine returns one row's text, including trailing spaces.\n\n```go\nfunc (s Screen) Text() string\n```\nText returns every row joined by a newline. It preserves trailing spaces and does not append a newline after the final row.\n\n```go\ntype ScreenMatcher interface {\n\tMatch(Screen) bool\n}\n```\nScreenMatcher determines whether a screen has reached an expected state.\n\n```go\nfunc AllOf(matchers ...ScreenMatcher) ScreenMatcher\n```\nAllOf matches when every matcher succeeds. An empty AllOf matches every screen.\n\n```go\nfunc AnyOf(matchers ...ScreenMatcher) ScreenMatcher\n```\nAnyOf matches when at least one matcher succeeds. An empty AnyOf never matches.\n\n```go\nfunc CursorAt(column, row int) ScreenMatcher\n```\nCursorAt matches the cursor's zero-based position.\n\n```go\nfunc Not(matcher ScreenMatcher) ScreenMatcher\n```\nNot matches when matcher does not succeed.\n\n```go\nfunc ScreenContains(text string) ScreenMatcher\n```\nScreenContains matches when the exact screen text contains text.\n\n```go\nfunc ScreenLineEquals(row int, text string) ScreenMatcher\n```\nScreenLineEquals matches when row contains exactly text, including trailing spaces. Rows are zero-based.\n\n```go\ntype ScreenMatcherFunc func(Screen) bool\n```\nScreenMatcherFunc adapts a function into a ScreenMatcher.\n\n```go\nfunc (f ScreenMatcherFunc) Match(screen Screen) bool\n```\nMatch calls the adapted function.\n\n```go\ntype Server struct {\n\t// contains filtered or unexported fields\n}\n```\nServer owns terminal connection and session lifecycles.\n\n```go\nfunc NewServer(logger *slog.Logger) (*Server, error)\n```\nNewServer creates a terminal server using logger for lifecycle events.\n\n```go\nfunc (s *Server) Close() error\n```\nClose closes all tracked sessions and connections. It is idempotent.\n\n```go\nfunc (s *Server) Connect(ctx context.Context, connector Connector) (*Connection, error)\n```\nConnect establishes and tracks a transport connection.\n\n```go\ntype Session struct {\n\t// contains filtered or unexported fields\n}\n```\nSession coordinates one transport stream with one terminal.\n\n```go\nfunc (s *Session) Close() error\n```\nClose closes the stream and waits for its read loop to stop. It is idempotent.\n\n```go\nfunc (s *Session) Done() \u003c-chan struct{}\n```\nDone is closed when the remote session ends or Close completes.\n\n```go\nfunc (s *Session) Err() error\n```\nErr returns the error that ended the session, if any.\n\n```go\nfunc (s *Session) Events(ctx context.Context) \u003c-chan TerminalEvent\n```\nEvents 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.\n\n```go\nfunc (s *Session) EventsAfter(sequence uint64) []TerminalEvent\n```\nEventsAfter returns the session's retained events whose sequence numbers are greater than sequence, oldest first. A session retains its most recent 256 events, including events published before any Events subscriber existed or that a slow subscriber missed. Sequence numbers are contiguous, so a gap before the first returned event shows how many are no longer retained.\n\n```go\nfunc (s *Session) FlightRecording() FlightRecording\n```\nFlightRecording returns a detached copy of the session's most recent host output, up to 64 KiB, with the resizes between reads and the session's unsupported-sequence counts. Wait errors include one automatically.\n\n```go\nfunc (s *Session) ID() uint64\n```\nID returns the session's server-unique identifier.\n\n```go\nfunc (s *Session) Press(key Key, modifiers ...KeyModifier) error\n```\nPress sends the terminal-profile sequence for a named or printable key with optional modifiers.\n\n```go\nfunc (s *Session) Resize(width, height int) error\n```\nResize changes both the local terminal and the remote session dimensions.\n\n```go\nfunc (s *Session) Screen() Screen\n```\nScreen returns the terminal's current detached snapshot.\n\n```go\nfunc (s *Session) Screens(ctx context.Context) \u003c-chan Screen\n```\nScreens 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.\n\n```go\nfunc (s *Session) Send(data []byte) error\n```\nSend writes input to the remote terminal session. Concurrent sends are serialized so their byte streams cannot interleave.\n\n```go\nfunc (s *Session) UnsupportedSequences() []UnsupportedSequence\n```\nUnsupportedSequences returns the sequences the terminal has ignored in the order they first appeared, with the number of times each was received. A session counts at most 256 distinct sequences; later new sequences are neither counted nor reported.\n\n```go\nfunc (s *Session) WaitFor(ctx context.Context, matcher ScreenMatcher) (Screen, error)\n```\nWaitFor waits until matcher accepts a screen, the context expires, or the session ends.\n\n```go\nfunc (s *Session) WaitForIdle(ctx context.Context, quietPeriod time.Duration) (Screen, error)\n```\nWaitForIdle waits until no host output arrives for quietPeriod. Host bytes that do not visibly change the screen still reset the quiet period.\n\n```go\nfunc (s *Session) WaitForStable(ctx context.Context, matcher ScreenMatcher, quietPeriod time.Duration) (Screen, error)\n```\nWaitForStable waits until matcher succeeds and no host output arrives for quietPeriod. The matcher is checked again after the quiet period.\n\n```go\ntype SessionOpener interface {\n\tOpenSession(context.Context, SessionRequest) (SessionStream, error)\n\tClose() error\n}\n```\nSessionOpener is the transport-specific side of a Connection.\n\n```go\ntype SessionRequest struct {\n\tTerminalType string\n\tWidth        int\n\tHeight       int\n}\n```\nSessionRequest describes the terminal requested from a remote server.\n\n```go\ntype SessionStream interface {\n\tio.ReadWriteCloser\n\tResize(width, height int) error\n}\n```\nSessionStream carries one interactive terminal session. Close must unblock any pending Read so session shutdown can complete.\n\n```go\ntype Terminal interface {\n\tio.Writer\n\tProfile() TerminalProfile\n\tResize(width, height int) error\n\tSnapshot() Screen\n}\n```\nTerminal consumes bytes received from a host and maintains terminal state. Implementations return detached snapshots that remain stable as more bytes are processed.\n\n```go\ntype TerminalEvent struct {\n\tSequence uint64\n\tType     TerminalEventType\n\tData     string\n}\n```\nTerminalEvent reports a terminal control event. Sequence is assigned by the session. Data contains the configured answerback for an enquiry and the ignored sequence, such as \"CSI ? 2004 h\", for an unsupported event.\n\n```go\ntype TerminalEventDrainer interface {\n\tDrainEvents() []TerminalEvent\n}\n```\nTerminalEventDrainer exposes events produced synchronously by Terminal.Write. The session drains events after each host-output write.\n\n```go\ntype TerminalEventType string\n```\nTerminalEventType identifies a non-screen event emitted while processing host output.\n\n```go\nconst (\n\tEventBell    TerminalEventType = \"bell\"\n\tEventEnquiry TerminalEventType = \"enquiry\"\n\t// EventUnsupported reports host output that the terminal profile does not\n\t// implement and therefore ignored. A terminal emits one for every\n\t// occurrence; a session publishes only the first of each distinct\n\t// sequence and counts the rest (see Session.UnsupportedSequences).\n\tEventUnsupported TerminalEventType = \"unsupported\"\n)\n```\n\n```go\ntype TerminalProfile string\n```\nTerminalProfile identifies the behavior emulated by a terminal.\n\n```go\nconst (\n\t// ProfileVT220 identifies the DEC VT220 terminal profile.\n\tProfileVT220 TerminalProfile = \"vt220\"\n\t// ProfileXTerm identifies the xterm terminal profile with 256-color support.\n\tProfileXTerm TerminalProfile = \"xterm-256color\"\n)\n```\n\n```go\ntype UnsupportedSequence struct {\n\tSequence string\n\tCount    uint64\n}\n```\nUnsupportedSequence counts how often the host sent a sequence the terminal ignored. Sequence uses the notation of EventUnsupported data.\n\n```go\ntype WaitError struct {\n\tExpected   string\n\tLastScreen Screen\n\tCause      error\n\tRecording  *FlightRecording\n}\n```\nWaitError reports why a screen wait ended and retains the last observed snapshot for assertion diagnostics. Recording, when present, holds the host output that preceded the failure.\n\n```go\nfunc (e *WaitError) Error() string\n```\n\n```go\nfunc (e *WaitError) Unwrap() error\n```\nUnwrap returns the context or session error that ended the wait.\n\n","path":"github.com/castingcode/tuicast","name":"tuicast","synopsis":"","isRedistributable":true}
