backend

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 8 Imported by: ? 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 backend defines Kite's interface to a terminal or other output device. A Backend delivers raw input events and supplies a Surface for drawing each frame.

Index

Constants

View Source
const (
	ProgressBarHide          = terminal.ProgressBarHide
	ProgressBarNormal        = terminal.ProgressBarNormal
	ProgressBarError         = terminal.ProgressBarError
	ProgressBarIndeterminate = terminal.ProgressBarIndeterminate
	ProgressBarPaused        = terminal.ProgressBarPaused
)
View Source
const (
	ProgramStateIdle    = terminal.ProgramStateIdle
	ProgramStateWorking = terminal.ProgramStateWorking
	ProgramStateDone    = terminal.ProgramStateDone
	ProgramStateBlocked = terminal.ProgramStateBlocked
	ProgramStateError   = terminal.ProgramStateError
	ProgramStateClear   = terminal.ProgramStateClear
)
View Source
const (
	ProgramStatusKindPermission = terminal.ProgramStatusKindPermission
	ProgramStatusKindQuestion   = terminal.ProgramStatusKindQuestion
	ProgramStatusKindAuth       = terminal.ProgramStatusKindAuth
)

Variables

This section is empty.

Functions

func ReleaseRawMouseEvent

func ReleaseRawMouseEvent(e *RawMouseEvent)

Types

type Backend

type Backend interface {
	// Start initializes the terminal (e.g., enters alt-screen, enables raw mode).
	// It must be called by the engine before any other methods.
	Start() error

	// BeginFrame prepares a new frame and returns the Surface the paint
	// engine should draw into. BeginFrame must be called before EndFrame.
	BeginFrame() Surface

	// EndFrame commits the current frame to the output target. It returns
	// an error if the commit fails (e.g., a write error to the terminal).
	EndFrame() error

	// Caps returns the terminal capabilities detected at startup. The
	// returned value is immutable after the backend is started.
	Caps() Caps

	// Events returns a read-only channel of input events from the terminal. The
	// channel is closed when the backend stops.
	Events() <-chan RawEvent

	// Restore unconditionally restores the terminal to its state before the
	// backend was started (exit alt-screen, disable raw mode, show cursor).
	// Restore is safe to call from a signal handler or a deferred panic
	// recovery; it must not block.
	Restore()

	Resize(geom.Size)

	// Size returns the current dimensions of the backend's output area.
	Size() geom.Size

	// Writer returns the terminal's output writer. Used by terminal extensions
	// to send initialization or protocol-specific sequences.
	Writer() io.Writer

	// ShowCursor sets the cursor visibility.
	ShowCursor(bool)

	// SetCursorPos sets the cursor position.
	SetCursorPos(x, y int)

	// SetCursorShape sets the cursor visual shape.
	SetCursorShape(CursorShape)

	// SetCursorColor sets the terminal hardware cursor color.
	SetCursorColor(color.Color)

	// DumpState writes a debug dump of the backend state to a file.
	DumpState()

	// Clipboard returns the clipboard provider for this backend.
	Clipboard() Clipboard

	// SetTitle sets the terminal window title.
	SetTitle(string)

	// Title returns the current terminal window title.
	Title() string

	// Bell triggers the terminal hardware bell.
	Bell()

	// SetProgressBar updates the terminal window's native progress bar.
	SetProgressBar(state terminal.ProgressBarState, percentage int)

	// SetProgramStatus reports the program status to the terminal using OSC 7501.
	// Passing nil clears any current program status on the terminal.
	SetProgramStatus(status *terminal.ProgramStatus)

	// SetProgramResume reports the command to resume this process using OSC 7577.
	// Passing nil clears any previously registered resume command.
	SetProgramResume(resume *terminal.ProgramResume)

	// SetInline configures the backend to run in inline mode (non-alt-screen,
	// relative cursor, dynamic height) instead of fullscreen mode.
	SetInline(inline bool)

	// Clear clears the visible terminal and scrollback, and resets the inline
	// frame origin to the top of the terminal. Output is ordered before
	// subsequent InsertAbove and EndFrame calls.
	Clear()

	// InsertAbove inserts a rendered cell buffer permanently into the terminal
	// scrollback above the active inline frame.
	InsertAbove(buf *Buffer)
}

Backend is the interface that decouples the paint engine from the terminal output target. Implementations vend a Surface for the PaintEngine to draw onto and commit the result to the screen.

A Backend must be used from a single goroutine except where individual method docs note otherwise. The typical frame loop is:

surface := backend.BeginFrame()
engine.Paint(root, surface)
if err := backend.EndFrame(); err != nil { … }

type Buffer

type Buffer struct {
	Cells  []Cell
	Width  int
	Height int
}

Buffer is a simple implementation of Surface that stores cells in a flat slice. It is useful for backends that need to buffer frames before rendering.

func NewBuffer

func NewBuffer(width, height int) *Buffer

func (*Buffer) Bounds

func (b *Buffer) Bounds() geom.Rect

func (*Buffer) CellAt

func (b *Buffer) CellAt(x, y int) Cell

func (*Buffer) Reset

func (b *Buffer) Reset()

func (*Buffer) Resize

func (b *Buffer) Resize(width, height int)

Resize changes the dimensions of the buffer, reallocating Cells if necessary.

func (*Buffer) Set

func (b *Buffer) Set(x, y int, c Cell)

func (*Buffer) Size

func (b *Buffer) Size() geom.Size

type Caps

type Caps struct {
	ColorScheme style.ColorScheme
	// TrueColor reports whether the terminal supports 24-bit RGB color. When
	// false, the paint engine down-samples to the highest supported palette.
	TrueColor bool

	// OSC8Hyperlinks reports whether the terminal understands OSC 8 hyperlink
	// sequences. Anchor widgets suppress link rendering when this is false.
	OSC8Hyperlinks bool

	// Mouse is the highest mouse-tracking mode available. The engine never
	// enables a mode higher than MouseMode config allows; Caps.Mouse reflects
	// what the terminal can do, not what is currently enabled.
	Mouse MouseSupport

	// BracketedPaste reports whether the terminal supports bracketed-paste
	// mode (surrounding pasted text with escape markers).
	BracketedPaste bool

	// Sixel reports whether the terminal can render Sixel pixel graphics.
	Sixel bool

	// KittyGraphics reports whether the terminal supports the Kitty terminal
	// graphics protocol.
	KittyGraphics bool

	// Title reports whether the terminal accepts window-title escape sequences
	// (OSC 0 / OSC 2). engine.SetTitle is a no-op when this is false.
	Title bool

	// Bell reports whether the terminal should respond to the BEL character.
	// engine.Bell is a no-op when this is false.
	Bell bool

	// ProgressBar reports whether the terminal supports native progress bar escape sequences.
	ProgressBar bool

	// ProgramStatus reports whether the terminal supports OSC 7501 Program Status Protocol.
	ProgramStatus bool

	// ProgramResume reports whether the terminal supports OSC 7577 Program Resume Protocol.
	ProgramResume bool

	// Clipboard is the list of supported clipboard protocols.
	Clipboard []ClipboardKind
}

Caps is a snapshot of the terminal capabilities detected at startup by the backend. Consumers (paint engine, widget implementations) should treat Caps as read-only after the engine starts.

type Cell

type Cell struct {
	Content string
	Fg      color.Color
	Bg      color.Color
	Width   int // number of columns this cell occupies (1 for normal chars, >1 for wide chars)

	// Style is a bitmask of text styles (bold, italic, etc.). The exact
	// styles and their bit values are defined by the backend.
	Style CellStyle
}

type CellStyle

type CellStyle uint16
const (
	CellBold CellStyle = 1 << iota
	CellFaint
	CellItalic
	CellUnderline
	CellBlink
	CellReverse
	CellConceal
	CellStrikethrough
)

type Clipboard

type Clipboard interface {
	// Set stores data into the system clipboard with the given MIME type.
	Set(mime string, data []byte)
	// Request asks the terminal to send the current system clipboard
	// content for the given MIME type. The response is typically
	// delivered asynchronously as a RawEvent.
	Request(mime string)
}

Clipboard is implemented by objects that provide system clipboard access.

type ClipboardKind

type ClipboardKind string

ClipboardKind identifies a supported clipboard protocol.

const (
	ClipboardOSC52  ClipboardKind = "osc52"
	ClipboardKitty  ClipboardKind = "kitty"
	ClipboardSystem ClipboardKind = "system"
)

type CursorShape

type CursorShape uint8
const (
	CursorBlock CursorShape = iota
	CursorUnderline
	CursorBar
)

type FrameInserter

type FrameInserter interface {
	InsertAboveForFrame(buf *Buffer)
}

FrameInserter is an optional backend capability for inserts generated while preparing a new frame. Unlike InsertAbove, it must not restore the previous active frame between inserts. The caller must commit a fresh frame afterward.

type MouseModeSetter

type MouseModeSetter interface {
	SetMouseMode(MouseSupport)
}

MouseModeSetter is an optional backend capability for selecting which mouse events the terminal reports, independently of its maximum supported mode.

type MouseSupport

type MouseSupport uint8

MouseSupport describes the level of mouse event support available from the terminal.

const (
	// MouseSupportNone means the terminal does not support mouse events.
	MouseSupportNone MouseSupport = iota

	// MouseSupportClick means the terminal supports button-press events only.
	MouseSupportClick

	// MouseSupportDrag means the terminal supports drag events (motion while
	// button held) in addition to click events.
	MouseSupportDrag

	// MouseSupportTrack means the terminal supports full motion tracking
	// (mouse-move events even without a button pressed).
	MouseSupportTrack
)

type ProcessStreams

type ProcessStreams interface {
	ExecIO() (io.Reader, io.Writer, io.Writer)
}

ProcessStreams is an optional backend capability exposing the underlying input/output streams to inherit when launching a subprocess via ExecProcess.

type ProgramResume

type ProgramResume = terminal.ProgramResume

type ProgramState

type ProgramState = terminal.ProgramState

type ProgramStatus

type ProgramStatus = terminal.ProgramStatus

type ProgramStatusKind

type ProgramStatusKind = terminal.ProgramStatusKind

type ProgressBarState

type ProgressBarState = terminal.ProgressBarState

type RawBracketedPaste

type RawBracketedPaste struct {
	Text string
}

RawBracketedPaste is the backend representation of a bracketed-paste sequence (ESC[200~ … ESC[201~).

type RawClipboardEvent

type RawClipboardEvent struct {
	Selection rune // e.g. 0 = primary, 1 = secondary, 2 = clipboard
	Content   string
}

type RawColorSchemeEvent

type RawColorSchemeEvent struct{ Scheme style.ColorScheme }

type RawEvent

type RawEvent interface {
	// contains filtered or unexported methods
}

RawEvent is the interface implemented by all raw backend-level input event. It is processed by the Synthesizer to produce high-level structured event.

type RawFocusInEvent

type RawFocusInEvent struct{}

RawFocusInEvent is the backend representation of terminal focus gained.

type RawFocusOutEvent

type RawFocusOutEvent struct{}

RawFocusOutEvent is the backend representation of terminal focus lost.

type RawKeyEvent

type RawKeyEvent struct {
	key.Key
	Up bool // true for key-release
}

RawKeyEvent is the backend representation of a key press or release.

type RawMouseEvent

type RawMouseEvent struct {
	X, Y   int
	Button event.MouseButton
	Up     bool // true for button-release
	Move   bool // true when no button change (motion)
	DeltaX int  // wheel
	DeltaY int  // wheel
	Mod    event.Modifiers
}

RawMouseEvent is the backend representation of a mouse action.

func AcquireRawMouseEvent

func AcquireRawMouseEvent() *RawMouseEvent

type RawOscEvent

type RawOscEvent struct {
	Code int
	Data string
}

RawOscEvent is a raw OSC sequence.

type RawProgramStatusSupportEvent

type RawProgramStatusSupportEvent struct{}

RawProgramStatusSupportEvent is the backend representation of a confirmation that the terminal supports the Program Status Protocol (OSC 7501).

type RawResizeEvent

type RawResizeEvent struct {
	Width, Height int
}

RawResizeEvent is the backend representation of a terminal resize.

type RawUnknownEvent

type RawUnknownEvent struct {
	Payload any
}

RawUnknownEvent is a catch-all for backend event that the engine does not recognize or handle explicitly.

type Surface

type Surface interface {
	// Set writes cell c into position (x, y).
	Set(x, y int, c Cell)

	// CellAt returns the cell at absolute position (x, y).
	CellAt(x, y int) Cell
}

type Suspender

type Suspender interface {
	Suspend() error
	Resume() error
}

Suspender is an optional backend capability for temporarily releasing the terminal to an interactive subprocess (such as an external editor) and restoring UI rendering afterward without closing Events.

Directories

Path Synopsis
Package mock provides a headless Kite backend that records frames and accepts synthetic input so tests can exercise a UI without a terminal.
Package mock provides a headless Kite backend that records frames and accepts synthetic input so tests can exercise a UI without a terminal.
Package uv implements Kite's terminal backend using Ultraviolet to render frames and receive input from a terminal.
Package uv implements Kite's terminal backend using Ultraviolet to render frames and receive input from a terminal.
Package wasm embeds Kite and Kitex applications in an HTML canvas.
Package wasm embeds Kite and Kitex applications in an HTML canvas.

Jump to

Keyboard shortcuts

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