term

package
v0.2.19 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 14 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 term owns the terminal mode and the cell grid around the browser image. The image starts after two chrome rows and ends before the footer.

Index

Constants

View Source
const ChromeRows = 2

ChromeRows is the fixed tab/navigation chrome above the page image.

Variables

This section is empty.

Functions

func ParseKittyGraphicsReply added in v0.2.3

func ParseKittyGraphicsReply(s string) bool

ParseKittyGraphicsReply reports whether s contains an OK for the probe. Errors, including a file-medium refusal, are not support.

func QueryKittyGraphics added in v0.2.3

func QueryKittyGraphics(in *os.File, out interface{ Write([]byte) (int, error) }) bool

QueryKittyGraphics asks the terminal that draws this pane whether it accepts kitty graphics. It is a query, not an environment guess: a multiplexer can answer for the terminal actually attached to it, even when TERM names a plain xterm. Silence is a no; a late answer is ignored by ReadEvent as an APC.

Types

type CellPixels

type CellPixels struct {
	WidthPx  int
	HeightPx int
	CellW    int
	CellH    int
}

CellPixels is the result of the CSI 14t/16t query.

func FallbackCellPixels

func FallbackCellPixels(rows, cols int) CellPixels

FallbackCellPixels is the 8x16 estimate used when the terminal is not queried or does not answer.

func ParseCellPixels

func ParseCellPixels(s string) (CellPixels, bool)

ParseCellPixels parses one or both of CSI 4;height;width t (text area) and CSI 6;height;width t (cell size).

func QueryCellPixels

func QueryCellPixels(in *os.File, out interface{ Write([]byte) (int, error) }, rows, cols int) CellPixels

QueryCellPixels asks the terminal for its text-area and cell size. It is best-effort: a terminal that does not answer gets the 8x16 fallback.

func TerminalCellPixels added in v0.2.0

func TerminalCellPixels(in *os.File, rows, cols int) CellPixels

TerminalCellPixels obtains the kernel-reported terminal pixel extent when it is available. Pseudo terminals commonly leave it zero, in which case the conservative fallback is returned without reading stdin.

type Event

type Event struct {
	Kind   EventKind
	Rune   rune
	Mouse  MouseEvent
	Pixels CellPixels
}

Event is a key or terminal event.

func Parse

func Parse(data []byte) ([]Event, error)

Parse parses all complete events in data. It is used by tests and callers that already buffered a chunk of input.

func ReadEvent

func ReadEvent(r *bufio.Reader) (Event, error)

ReadEvent reads one key. Escape sequences are recognized; a lone ESC is returned after a short grace period so Alt+key and arrow keys still work.

type EventKind

type EventKind int

EventKind is one parsed terminal input event.

const (
	KeyText EventKind = iota
	KeyEnter
	KeyBackspace
	KeyEscape
	KeyUp
	KeyDown
	KeyLeft
	KeyRight
	KeyAltLeft
	KeyAltRight
	KeyAltF
	KeyCtrlL
	KeyCtrlR
	KeyCtrlC
	KeyCtrlQ
	KeyCtrlG
	KeyCtrlO
	KeyResize
	KeyMouse
	KeyCellPixels
	// KeyIgnored is terminal metadata that is not a key, such as an APC reply.
	KeyIgnored
	KeyTab
)

type Geometry

type Geometry struct {
	Cols, Rows      int
	CellWidth       int
	CellHeight      int
	ContentTopRow   int // 1-based terminal row where the page starts
	ContentRows     int // number of terminal rows occupied by the page image
	ContentWidthPx  int
	ContentHeightPx int
}

Geometry maps terminal cells to browser CSS pixels.

func GeometryFor

func GeometryFor(rows, cols int, p CellPixels) Geometry

GeometryFor builds the mapping for a terminal grid and optional pixel measurements.

func (Geometry) CellToPixel

func (g Geometry) CellToPixel(col, row int) (x, y float64, ok bool)

CellToPixel maps a 1-based terminal cell to the page viewport. Returns false when the point is outside the content area.

func (Geometry) CellToPixelClamped added in v0.2.0

func (g Geometry) CellToPixelClamped(col, row int) (x, y float64, ok bool)

CellToPixelClamped maps a 1-based terminal cell to the page viewport, clamping cells outside the content area to its nearest edge. A drag keeps producing motion after the pointer leaves the page area, and the page expects the pointer to keep tracking along the edge instead of freezing.

func (Geometry) String

func (g Geometry) String() string

type MouseEvent

type MouseEvent struct {
	Button int
	Col    int
	Row    int
	Press  bool
	Motion bool
	Wheel  int // -1 up, 1 down, 0 not a wheel
	WheelX int // -1 left, 1 right; never reinterpret sideways touchpad drift as vertical
}

MouseEvent is one SGR mouse report.

type Screen

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

Screen switches the terminal into raw mode and an alternate screen.

func Open

func Open(in *os.File, out io.Writer) (*Screen, error)

Open enters the alternate screen and raw mode.

func (*Screen) BodyRows

func (s *Screen) BodyRows() int

BodyRows is the number of rows available to the page image.

func (*Screen) Chrome added in v0.2.0

func (s *Screen) Chrome(lines []string)

Chrome draws exactly the two styled chrome lines. ANSI escapes are preserved verbatim; callers are responsible for keeping their visible width in bounds.

func (*Screen) ClearBody

func (s *Screen) ClearBody()

ClearBody clears the image area.

func (*Screen) Close

func (s *Screen) Close()

Close restores the cursor, the main screen and the terminal mode.

func (*Screen) Footer

func (s *Screen) Footer(text string)

Footer draws the status/help line on the last row.

func (*Screen) Header

func (s *Screen) Header(text string)

Header draws the one-line address/status bar.

func (*Screen) QueryPixels added in v0.2.0

func (s *Screen) QueryPixels()

QueryPixels asynchronously requests pane and cell pixel dimensions. Replies are consumed by ReadEvent, so this method never competes for stdin.

func (*Screen) Refresh

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

Refresh reads the terminal size again.

func (*Screen) Size

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

Size returns the last known terminal grid.

func (*Screen) Text

func (s *Screen) Text(lines []string)

Text clears the page area and writes plain text lines. The caller keeps the footer in sync.

func (*Screen) WriteBody

func (s *Screen) WriteBody(draw func(io.Writer) error) error

WriteBody positions the image without clearing the previous frame. Erasing here makes tuios remove the visible placement before the replacement arrives.

Jump to

Keyboard shortcuts

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