screen

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package screen keeps the visible terminal screen of a session in a VT emulator (charmbracelet/x/vt) and renders it for attached clients: a full ANSI snapshot to resynchronize a client, and per-client diffs that redraw only the rows changed since that client's previous frame.

Only the visible screen is kept in memory; scrollback lives on disk as raw bytes (package scrollback).

Index

Constants

View Source
const (
	MinCols, MaxCols = 2, 500
	MinRows, MaxRows = 2, 250
	DefaultCols      = 80
	DefaultRows      = 24
)

Size limits. Both screens (main and alternate) hold one cell struct per position, so an absurd size requested by a client must not become an absurd allocation.

Variables

This section is empty.

Functions

func ClampSize

func ClampSize(cols, rows int) (int, int)

ClampSize returns the size a screen (and the PTY) actually uses; zero or negative values mean the default.

Types

type Differ

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

Differ renders screen-mode frames for one client.

func (*Differ) Frame

func (d *Differ) Frame() []byte

Frame returns ANSI redrawing the rows changed since the previous frame (every row after a size change), each followed by an erase to the end of line, then the cursor position and visibility. It returns nil when nothing visible changed.

type Screen

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

Screen is a session's emulated terminal screen. All methods are safe for concurrent use.

func New

func New(cols, rows int, respond func([]byte)) *Screen

New returns a screen of the given size. respond receives the emulator's replies to terminal queries (DA, DSR/CPR, DECRQM, colour queries, ...); pass nil when a real terminal answers them (passthrough), otherwise forward them to the program (detached). respond must not block for long and must not call into the Screen.

func (*Screen) AppCursorKeys

func (s *Screen) AppCursorKeys() bool

AppCursorKeys reports whether the program enabled DECCKM (cursor keys send SS3 sequences).

func (*Screen) BracketedPaste

func (s *Screen) BracketedPaste() bool

BracketedPaste reports whether the program enabled DECSET 2004.

func (*Screen) Close

func (s *Screen) Close()

Close stops the reply drain. The screen stays readable.

func (*Screen) Lines added in v0.4.0

func (s *Screen) Lines() []string

Lines returns the text of the visible screen (the alternate one while it is active), one string per row, without attributes and trailing blanks. A wide character appears once; cells never written read as blanks.

func (*Screen) Resize

func (s *Screen) Resize(cols, rows int) (int, int)

Resize changes the screen size (clamped with ClampSize) and returns the size in effect.

func (*Screen) SetResponder added in v0.3.0

func (s *Screen) SetResponder(respond func([]byte))

SetResponder replaces the receiver of terminal query replies (see New); nil drops them. A passthrough session whose local terminal went away starts answering queries itself this way.

func (*Screen) Size

func (s *Screen) Size() (cols, rows int)

Size returns the current size.

func (*Screen) Snapshot

func (s *Screen) Snapshot() []byte

Snapshot returns ANSI that reproduces the current screen on a cleared terminal of the same size, and leaves that terminal in the state the program's next bytes expect: cursor position and visibility, current pen, scroll region, autowrap, and the input modes (inputModes) the program set or reset. When the alternate screen is active, the main screen is drawn first and the alternate screen entered on top of it, so a later switch back shows the right content. Used for raw-mode resets.

func (*Screen) SnapshotDiffer

func (s *Screen) SnapshotDiffer() ([]byte, *Differ)

SnapshotDiffer returns a full frame of the current screen (for a screen-mode client, sent with reset) and a Differ whose next Frame is relative to that snapshot. The frame carries content, cursor position and visibility only; screen-mode clients never receive pen or scroll-region state.

func (*Screen) Title

func (s *Screen) Title() string

Title is the window title last set with OSC 0 or 2.

func (*Screen) Win32InputMode added in v0.5.0

func (s *Screen) Win32InputMode() bool

Win32InputMode reports whether the program enabled win32-input-mode.

func (*Screen) Write

func (s *Screen) Write(p []byte)

Write feeds program output to the emulator.

Jump to

Keyboard shortcuts

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