vt

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package vt defines Loom's pane-display abstraction. An Emulator consumes raw PTY bytes from the tmux-client stream and renders the current visible screen as a string the UI prints verbatim. tmux remains the session owner; this is display only.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAltScreenFilter added in v0.13.0

func NewAltScreenFilter(dst io.Writer) io.Writer

NewAltScreenFilter wraps dst, stripping alternate-screen mode switches from the byte stream. Install between the tmux output pump and the emulator.

Types

type Cursor

type Cursor struct {
	X, Y    int
	Visible bool
	Shape   CursorShape
	Blink   bool
}

Cursor is the visible cursor state in cells, 0-based, origin top-left. Visible reflects DECTCEM (apps hide the cursor while painting); Shape and Blink reflect DECSCUSR. The defaults — visible blinking block — match a fresh terminal.

type CursorShape added in v0.8.0

type CursorShape int

CursorShape is the visual form of the cursor, as set by DECSCUSR.

const (
	CursorShapeBlock CursorShape = iota
	CursorShapeUnderline
	CursorShapeBar
)

type Emulator

type Emulator interface {
	// Write feeds raw PTY bytes (ANSI/CSI/OSC/DCS) into the emulator. It
	// mirrors io.Writer so it can be the output pump's destination directly.
	Write(p []byte) (n int, err error)

	// Resize sets the emulator's screen geometry in cells.
	Resize(cols, rows int)

	// Render returns the current VISIBLE screen as a string with embedded
	// ANSI SGR sequences, sized to the last Resize. The UI prints this verbatim.
	Render() string

	// Cursor returns the current cursor position and visibility.
	Cursor() Cursor

	// Title returns the window title most recently set by the inner app via
	// OSC 0/2, or "" if never set.
	Title() string

	// SetBellFunc installs a handler invoked when the inner app rings BEL.
	// The handler runs inside Write on the pump goroutine — it must be
	// cheap, must not call back into the Emulator, and must be safe to
	// invoke concurrently with readers (tea.Program.Send qualifies).
	SetBellFunc(f func())

	// FocusReportingEnabled reports whether the inner app enabled focus
	// reporting (DEC private mode 1004). Focus in/out sequences must only
	// be forwarded while true — unsolicited CSI I/O is garbage input to
	// apps that never asked for it.
	FocusReportingEnabled() bool

	// Close releases emulator resources. Safe to call multiple times.
	Close() error

	// ScrollbackLen returns the number of lines scrolled off the top of the
	// primary screen. Alt-screen output never accumulates (x/vt returns the
	// main screen's buffer regardless of the active screen).
	ScrollbackLen() int

	// RenderWindow returns exactly `rows` lines ending `offset` lines above
	// the live bottom, composed from scrollback + the visible screen, with
	// ANSI styles. offset 0 with rows == screen height is equivalent to
	// Render(). offset < 0 is treated as 0; rows < 1 returns "". Positions
	// above the top of the buffer render as blank lines.
	RenderWindow(offset, rows int) string

	// SetScrollbackSize caps scrollback retention in lines.
	SetScrollbackSize(n int)
}

Emulator is the display surface for one pane. Implementations must be safe for one writer goroutine (the tmux output pump calling Write) concurrent with reader calls (Render/Cursor) from the Bubble Tea Update goroutine.

func NewXVT

func NewXVT(cols, rows int) Emulator

NewXVT constructs a real terminal emulator sized to cols x rows.

Jump to

Keyboard shortcuts

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