term

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrWindowClosed = errors.New("window closed by user")

Functions

This section is empty.

Types

type BackgroundBuffer

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

BackgroundBuffer manages a persistent vertex buffer for terminal cell backgrounds. It supports efficient partial updates for dirty cells, reducing GPU draw calls from O(cells) to O(1).

func NewBackgroundBuffer

func NewBackgroundBuffer(win graphics.Window, tex graphics.Texture, cols, rows int) (*BackgroundBuffer, error)

NewBackgroundBuffer creates a new background buffer for the given grid dimensions.

func (*BackgroundBuffer) ClearFullRebuild

func (b *BackgroundBuffer) ClearFullRebuild()

ClearFullRebuild clears the full rebuild flag after a rebuild.

func (*BackgroundBuffer) NeedsFullRebuild

func (b *BackgroundBuffer) NeedsFullRebuild() bool

NeedsFullRebuild returns true if a full buffer rebuild is required.

func (*BackgroundBuffer) Render

func (b *BackgroundBuffer) Render(f graphics.Frame)

Render draws all backgrounds in a single draw call.

func (*BackgroundBuffer) Resize

func (b *BackgroundBuffer) Resize(cols, rows int)

Resize changes the buffer capacity to match new grid dimensions.

func (*BackgroundBuffer) SetLayout

func (b *BackgroundBuffer) SetLayout(originX, originY, padX, padY, cellW, cellH float32)

SetLayout updates the layout parameters used to calculate vertex positions.

func (*BackgroundBuffer) UpdateAll

func (b *BackgroundBuffer) UpdateAll(grid *Grid, bgDefault color.Color)

UpdateAll rebuilds all vertices and uploads to GPU. Call this after SetLayout or Resize.

func (*BackgroundBuffer) UpdateCell

func (b *BackgroundBuffer) UpdateCell(x, y, width int, bg color.Color)

UpdateCell updates the vertices for a single cell.

func (*BackgroundBuffer) UpdateCellTransparent

func (b *BackgroundBuffer) UpdateCellTransparent(x, y, width int)

UpdateCellTransparent sets a cell to fully transparent (alpha=0). Used for cells with the default background color.

func (*BackgroundBuffer) UpdateDirty

func (b *BackgroundBuffer) UpdateDirty(grid *Grid, bgDefault color.Color)

UpdateDirty updates vertices for all dirty cells in the grid.

type Cell

type Cell struct {
	Content string
	Width   int
	Fg      color.Color
	Bg      color.Color
	Attrs   uint8
}

Cell represents a single terminal cell with cached state for dirty tracking.

type ColorScheme added in v0.0.2

type ColorScheme struct {
	// Foreground is the default text color.
	Foreground color.RGBA
	// Background is the default background color.
	Background color.RGBA
	// Cursor is the cursor color.
	Cursor color.RGBA
	// Selection is the selection highlight color.
	Selection color.RGBA
	// Palette is the 16-color ANSI palette (0-7 normal, 8-15 bright).
	Palette []color.RGBA
}

ColorScheme defines the color palette for the terminal.

func DefaultColorScheme added in v0.0.2

func DefaultColorScheme() ColorScheme

DefaultColorScheme returns the default Tokyo Night color scheme.

func LightColorScheme added in v0.0.2

func LightColorScheme() ColorScheme

LightColorScheme returns a light color scheme with purple accents.

type DirtyRegion

type DirtyRegion struct {
	X, Y          int
	Width, Height int
}

DirtyRegion represents a rectangular region of dirty cells.

type EmulatorReader

type EmulatorReader interface {
	Width() int
	Height() int
	CellAt(x, y int) interface {
		GetContent() string
		GetWidth() int
		GetFg() color.Color
		GetBg() color.Color
		GetAttrs() uint8
	}
	CursorPosition() struct{ X, Y int }
}

EmulatorReader provides read access to VT emulator cell data.

type Grid

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

Grid manages a grid of terminal cells with dirty tracking for incremental updates.

func NewGrid

func NewGrid(cols, rows int) *Grid

NewGrid creates a new grid with the given dimensions.

func (*Grid) CellAt

func (g *Grid) CellAt(x, y int) *Cell

CellAt returns a pointer to the cell at (x, y), or nil if out of bounds.

func (*Grid) ClearDirty

func (g *Grid) ClearDirty()

ClearDirty clears all dirty flags.

func (*Grid) CursorPosition

func (g *Grid) CursorPosition() (x, y int)

CursorPosition returns the current cursor position.

func (*Grid) DirtyCount

func (g *Grid) DirtyCount() int

DirtyCount returns the number of dirty cells.

func (*Grid) GetDirtyRegions

func (g *Grid) GetDirtyRegions() []DirtyRegion

GetDirtyRegions returns a list of dirty regions for batch processing. Adjacent dirty cells are merged into larger regions to reduce draw calls.

func (*Grid) IsDirty

func (g *Grid) IsDirty(x, y int) bool

IsDirty returns true if the cell at (x, y) needs re-rendering.

func (*Grid) IterateAll

func (g *Grid) IterateAll(fn func(x, y int, cell *Cell))

IterateAll calls fn for each cell regardless of dirty state.

func (*Grid) IterateDirty

func (g *Grid) IterateDirty(fn func(x, y int, cell *Cell))

IterateDirty calls fn for each dirty cell with its coordinates. This is useful for incremental rendering.

func (*Grid) MarkAllDirty

func (g *Grid) MarkAllDirty()

MarkAllDirty marks all cells as dirty (for full redraw).

func (*Grid) MarkDirty

func (g *Grid) MarkDirty(x, y int)

MarkDirty marks a cell as needing re-rendering.

func (*Grid) ResetStats

func (g *Grid) ResetStats()

ResetStats resets the statistics counters.

func (*Grid) Resize

func (g *Grid) Resize(cols, rows int)

Resize changes the grid dimensions, preserving content where possible.

func (*Grid) SetCell

func (g *Grid) SetCell(x, y int, content string, width int, fg, bg color.Color, attrs uint8) bool

SetCell updates a cell and marks it dirty if it changed. Returns true if the cell was actually modified.

func (*Grid) Size

func (g *Grid) Size() (cols, rows int)

Size returns the grid dimensions.

func (*Grid) Stats

func (g *Grid) Stats() GridStats

Stats returns current grid statistics.

func (*Grid) UpdateCursor

func (g *Grid) UpdateCursor(newX, newY int)

UpdateCursor marks old and new cursor positions as dirty.

type GridStats

type GridStats struct {
	TotalCells  int
	DirtyCells  int
	SyncCalls   int
	FullRedraws int
}

GridStats tracks grid update statistics.

type Hooks

type Hooks struct {
	// OnResize is called when the terminal grid size changes.
	OnResize func(cols, rows int)
	// OnFrame is called once per rendered frame.
	OnFrame func() error
}

type Point

type Point struct {
	X, Y int
}

Point represents a cell position in the terminal grid.

type Terminal

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

Terminal is a convenience wrapper that owns its own window and renders a View into it.

func New

func New(title string, width, height int) (*Terminal, error)

func (*Terminal) Close

func (t *Terminal) Close() error

func (*Terminal) Read

func (t *Terminal) Read(p []byte) (int, error)

func (*Terminal) Run

func (t *Terminal) Run(ctx context.Context, hooks Hooks) error

func (*Terminal) Write

func (t *Terminal) Write(p []byte) (int, error)

type VTCell

type VTCell struct {
	Content string
	Width   int
	Style   struct {
		Fg    color.Color
		Bg    color.Color
		Attrs uint8
	}
}

VTCell wraps the charmbracelet/vt Cell type for our interface.

func (*VTCell) GetAttrs

func (c *VTCell) GetAttrs() uint8

func (*VTCell) GetBg

func (c *VTCell) GetBg() color.Color

func (*VTCell) GetContent

func (c *VTCell) GetContent() string

func (*VTCell) GetFg

func (c *VTCell) GetFg() color.Color

func (*VTCell) GetWidth

func (c *VTCell) GetWidth() int

type View

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

View is an embeddable terminal view that can be rendered inside an existing graphics.Window loop. It also implements io.Reader/io.Writer for wiring to a guest console.

func NewView

func NewView(win graphics.Window) (*View, error)

func (*View) ClearSelection

func (v *View) ClearSelection()

ClearSelection clears the current selection.

func (*View) Close

func (v *View) Close() error

func (*View) Grid

func (v *View) Grid() *Grid

Grid returns the internal grid for testing and introspection.

func (*View) Read

func (v *View) Read(p []byte) (int, error)

Read implements io.Reader. It exposes the VT-generated input stream.

func (*View) SetColorScheme added in v0.0.2

func (v *View) SetColorScheme(scheme ColorScheme)

SetColorScheme sets the terminal color scheme.

func (*View) SetInsets

func (v *View) SetInsets(left, top, right, bottom float32)

SetInsets configures pixel insets for rendering and sizing the terminal grid. The terminal will render within the content rect: [left, top] → [windowWidth-right, windowHeight-bottom].

func (*View) SetPendingEvents added in v0.0.2

func (v *View) SetPendingEvents(events []window.InputEvent)

SetPendingEvents sets events to process in the next Step() call. When set, Step() uses these events instead of calling DrainInputEvents(). The events are cleared after being processed.

func (*View) Step

func (v *View) Step(f graphics.Frame, hooks Hooks) error

Step processes one frame of input and renders the terminal cells into the provided graphics.Frame. This allows embedding the terminal view inside an existing window loop (e.g. CCApp).

func (*View) Write

func (v *View) Write(p []byte) (int, error)

Write implements io.Writer. It feeds bytes into the VT emulator (guest output).

Jump to

Keyboard shortcuts

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