Documentation
¶
Overview ¶
Package tuicast provides an idiomatic Go client for the TUICast driver.
Index ¶
- func IsTimeout(err error) bool
- type Attributes
- type Cell
- type Color
- type Connection
- type ConnectionConfig
- type Cursor
- type Driver
- type EventSubscription
- type IdleOption
- type Key
- type LaunchOption
- type Matcher
- type Modifier
- type Position
- type RPCError
- type SSH
- type Screen
- type ScreenSubscription
- type Session
- func (s *Session) Close(ctx context.Context) error
- func (s *Session) ID() uint64
- func (s *Session) Press(ctx context.Context, key Key, modifiers ...Modifier) error
- func (s *Session) Resize(ctx context.Context, width, height int) error
- func (s *Session) Screen(ctx context.Context) (Screen, error)
- func (s *Session) Send(ctx context.Context, data []byte) error
- func (s *Session) State(ctx context.Context) (SessionState, error)
- func (s *Session) Subscribe(ctx context.Context) (*ScreenSubscription, error)
- func (s *Session) SubscribeEvents(ctx context.Context) (*EventSubscription, error)
- func (s *Session) Type(ctx context.Context, text string) error
- func (s *Session) WaitFor(ctx context.Context, matcher Matcher, options ...WaitOption) (Screen, error)
- func (s *Session) WaitForEnd(ctx context.Context, options ...WaitOption) (SessionState, error)
- func (s *Session) WaitForIdle(ctx context.Context, options ...IdleOption) (Screen, error)
- func (s *Session) WaitForText(ctx context.Context, text string, options ...WaitOption) (Screen, error)
- func (s *Session) WaitForTextGone(ctx context.Context, text string, options ...WaitOption) (Screen, error)
- type SessionOption
- type SessionState
- type Telnet
- type TerminalEvent
- type TerminalEventType
- type TerminalProfile
- type WaitError
- type WaitOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 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 ¶
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.
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 LineEquals ¶
LineEquals matches one complete zero-based screen row, including trailing spaces.
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.
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) Find ¶
Find returns the first row-major position at which exact text begins. Text must begin and end within one row.
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.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session is an interactive terminal session managed by the driver.
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) 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 ¶
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 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.
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.