term

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainsText

func ContainsText(snap ScreenSnapshot, needle string) bool

ContainsText reports whether needle appears in any visible line.

func IsTerminalResponse added in v0.2.0

func IsTerminalResponse(data []byte) bool

IsTerminalResponse reports whether data is an auto-generated terminal reply (OSC/CSI/DCS), not interactive user input.

func JoinTailText

func JoinTailText(lines []TailLine) string

JoinTailText joins tail lines into a single newline-delimited string.

func StripANSI

func StripANSI(s string) string

StripANSI removes common CSI escape sequences from terminal text.

func TailFingerprint

func TailFingerprint(snap ScreenSnapshot, maxLines int) string

TailFingerprint fingerprints the last maxLines non-empty rows for activity detection.

func VisibleText

func VisibleText(snap ScreenSnapshot) string

VisibleText returns non-empty lines trimmed and joined (full viewport).

Types

type CellSnapshot

type CellSnapshot struct {
	Ch   string   `json:"ch"`
	Fg   string   `json:"fg,omitempty"`
	Bg   string   `json:"bg,omitempty"`
	Attr []string `json:"attr,omitempty"`
}

CellSnapshot is one grid cell for the headless API.

type Emulator

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

Emulator wraps xterm-go for Tuile's shared PTY parsing layer.

func New

func New(cols, rows int) *Emulator

New creates a terminal emulator with the given dimensions.

func (*Emulator) AltBufferActive

func (e *Emulator) AltBufferActive() bool

AltBufferActive reports whether the alternate screen is active.

func (*Emulator) Close

func (e *Emulator) Close()

Close releases emulator resources.

func (*Emulator) Cols

func (e *Emulator) Cols() int

Cols returns terminal width in cells.

func (*Emulator) Cursor

func (e *Emulator) Cursor() (x, y int)

Cursor returns zero-based column and row.

func (*Emulator) Line

func (e *Emulator) Line(y int) string

Line returns visible text for row y (without trailing spaces trimmed by caller).

func (*Emulator) ReplayANSI

func (e *Emulator) ReplayANSI() []byte

ReplayANSI serializes the buffer as escape sequences for browser replay (U6).

func (*Emulator) Resize

func (e *Emulator) Resize(cols, rows int)

Resize updates terminal dimensions and reflows buffer state.

func (*Emulator) Rows

func (e *Emulator) Rows() int

Rows returns terminal height in cells.

func (*Emulator) SetOnData added in v0.2.0

func (e *Emulator) SetOnData(fn func(string))

SetOnData registers a callback for terminal-generated replies (OSC/CSI/DCS).

func (*Emulator) Snapshot

func (e *Emulator) Snapshot() ScreenSnapshot

Snapshot captures structured screen state for agent reads.

func (*Emulator) SnapshotWith

func (e *Emulator) SnapshotWith(opts SnapshotOptions) ScreenSnapshot

SnapshotWith captures structured screen state with optional per-cell detail.

func (*Emulator) String

func (e *Emulator) String() string

String returns the full visible screen as plain text lines.

func (*Emulator) Write

func (e *Emulator) Write(p []byte) (int, error)

Write feeds PTY output bytes into the emulator.

type LineChange

type LineChange struct {
	Y    int    `json:"y"`
	Text string `json:"text"`
}

LineChange is one row update in an incremental screen diff.

type ParseError

type ParseError struct {
	Detail string
}

ParseError wraps invalid emulator input for callers.

func (*ParseError) Error

func (e *ParseError) Error() string

type RowSnapshot

type RowSnapshot struct {
	Y     int            `json:"y"`
	Text  string         `json:"text"`
	Cells []CellSnapshot `json:"cells,omitempty"`
}

RowSnapshot is one viewport row with optional per-cell detail.

type ScreenDiff

type ScreenDiff struct {
	Cursor *struct {
		X int `json:"x"`
		Y int `json:"y"`
	} `json:"cursor,omitempty"`
	Scroll       *ScrollRegion `json:"scroll,omitempty"`
	ChangedLines []LineChange  `json:"changed_lines,omitempty"`
}

ScreenDiff captures incremental updates between two screen versions.

func DiffSnapshots

func DiffSnapshots(before, after ScreenSnapshot) ScreenDiff

DiffSnapshots returns line-level changes between two line snapshots.

type ScreenSnapshot

type ScreenSnapshot struct {
	Cols   int `json:"cols"`
	Rows   int `json:"rows"`
	Cursor struct {
		X int `json:"x"`
		Y int `json:"y"`
	} `json:"cursor"`
	Lines  []string      `json:"lines"`
	Alt    bool          `json:"alt_buffer"`
	Scroll *ScrollRegion `json:"scroll,omitempty"`
	Grid   []RowSnapshot `json:"grid,omitempty"`
}

ScreenSnapshot is a JSON-serializable grid for the headless API (U3).

type ScrollRegion

type ScrollRegion struct {
	Top    int `json:"top"`
	Bottom int `json:"bottom"`
}

ScrollRegion describes the active terminal scroll margins.

type SnapshotOptions

type SnapshotOptions struct {
	IncludeCells bool
}

SnapshotOptions controls structured screen capture.

type TailLine

type TailLine struct {
	Y    int    `json:"y"`
	Text string `json:"text"`
}

TailLine is one non-empty row in tail output.

func RegionLines

func RegionLines(snap ScreenSnapshot, y1, y2 int) []TailLine

RegionLines returns rows in [y1, y2] inclusive, clamped to the viewport.

func TailLines

func TailLines(snap ScreenSnapshot, maxLines int) []TailLine

TailLines returns the last maxLines non-empty rows (bottom-up), preserving order.

Jump to

Keyboard shortcuts

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