termsim

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package termsim is a headless ANSI terminal simulator for byte-level parity testing. It accepts an ANSI byte stream (CSI/SGR/OSC/cursor moves) and reconstructs the final terminal state as a 2D cell grid.

Mirrors only the subset of escape sequences the pi-tui renderer actually emits. New sequences MUST be added as upstream pi-tui starts emitting them.

Reference: .upstream/current/packages/tui/src/tui.ts (renderer) for the emitter side; this is the consumer side.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cell

type Cell struct {
	Rune         rune
	Continuation bool
	Style        Style
	Link         string // OSC 8 hyperlink target
}

Cell is one terminal column. Wide chars occupy two cells; the second has Continuation=true and Rune=0. Empty cells have Rune=' '.

type Color

type Color struct {
	Mode    ColorMode
	N       uint8 // for 16/256
	R, G, B uint8 // for truecolor
}

Color represents a foreground or background color. Mode discriminates.

type ColorMode

type ColorMode uint8
const (
	ColorDefault   ColorMode = 0
	Color16        ColorMode = 1
	Color256       ColorMode = 2
	ColorTrueColor ColorMode = 3
)

type Grid

type Grid struct {
	Rows, Cols int
	// contains filtered or unexported fields
}

Grid is the simulated terminal state.

func New

func New(rows, cols int) *Grid

New creates a fresh Grid of the given dimensions.

func (*Grid) CellAt

func (g *Grid) CellAt(row, col int) Cell

CellAt returns the cell at (row, col). Out-of-range returns an empty cell.

func (*Grid) Cursor

func (g *Grid) Cursor() (int, int)

Cursor returns the current (row, col) position.

func (*Grid) Scrollback

func (g *Grid) Scrollback() []string

Scrollback returns rows that have scrolled past the top of the grid.

func (*Grid) String

func (g *Grid) String() string

String returns the visible content as a newline-joined string with trailing spaces trimmed per row.

func (*Grid) Style

func (g *Grid) Style() Style

StyleAt returns the style at the cursor position.

func (*Grid) SyncDepth

func (g *Grid) SyncDepth() int

SyncDepth reports the current mode 2026 nesting (0 = not inside sync block).

func (*Grid) Write

func (g *Grid) Write(b []byte)

Write feeds bytes into the simulator.

func (*Grid) WriteString

func (g *Grid) WriteString(s string)

WriteString is the string variant of Write.

type Style

type Style struct {
	FG, BG    Color
	Bold      bool
	Italic    bool
	Underline bool
	Inverse   bool
	Strike    bool
	Dim       bool
}

Style is the SGR attributes applied to a cell.

Jump to

Keyboard shortcuts

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