Documentation
¶
Overview ¶
Package backend defines the terminal backend interface for the TUI. This abstraction allows swapping between tcell (real terminals) and simulation backends (testing), enabling golden-frame tests.
Index ¶
- type AttrMask
- type Backend
- type Cell
- type Color
- type CursorShape
- type CursorShapeSetter
- type FrameWriter
- type Image
- type ImageFormat
- type ImageProtocol
- type ImageTarget
- type ImageWriter
- type InlineHeightSetter
- type InlineModeSetter
- type RectWriter
- type RenderTarget
- type RowWriter
- type Style
- func (s Style) Attributes() AttrMask
- func (s Style) BG() Color
- func (s Style) Background(c Color) Style
- func (s Style) BackgroundColor() Color
- func (s Style) Blink(on bool) Style
- func (s Style) Bold(on bool) Style
- func (s Style) Decompose() (fg, bg Color, attrs AttrMask)
- func (s Style) Dim(on bool) Style
- func (s Style) FG() Color
- func (s Style) Foreground(c Color) Style
- func (s Style) ForegroundColor() Color
- func (s Style) Hyperlink(url string) Style
- func (s Style) HyperlinkURL() string
- func (s Style) Italic(on bool) Style
- func (s Style) Reverse(on bool) Style
- func (s Style) StrikeThrough(on bool) Style
- func (s Style) Underline(on bool) Style
- type SubTarget
- type SyncOutputWriter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backend ¶
type Backend interface {
// Init initializes the backend (enters alt screen, raw mode, etc).
Init() error
// Fini cleans up the backend (restores terminal state).
Fini()
// Size returns the current terminal dimensions.
Size() (width, height int)
// SetContent sets a cell at position (x, y) with the given rune and style.
// The comb parameter contains combining characters (can be nil).
SetContent(x, y int, mainc rune, comb []rune, style Style)
// Show synchronizes the internal buffer to the terminal.
// This is where actual output happens.
Show()
// Clear clears the screen.
Clear()
// HideCursor hides the terminal cursor.
HideCursor()
// ShowCursor shows the terminal cursor.
ShowCursor()
// SetCursorPos sets the cursor position.
SetCursorPos(x, y int)
// PollEvent blocks until an event is available and returns it.
// Returns nil if the backend is shutting down.
PollEvent() terminal.Event
// PostEvent injects an event into the event queue.
// Useful for testing and for posting timer/internal events.
PostEvent(ev terminal.Event) error
// Beep emits an audible bell.
Beep()
// Sync forces a full redraw on next Show().
Sync()
}
Backend is the terminal abstraction layer. Implementations handle terminal I/O, input events, and screen rendering.
type Color ¶
type Color int32
Color represents a terminal color. Values 0-255 are palette colors, values >= 256 are true colors.
const ( ColorDefault Color = -1 ColorBlack Color = 0 ColorRed Color = 1 ColorGreen Color = 2 ColorYellow Color = 3 ColorBlue Color = 4 ColorMagenta Color = 5 ColorCyan Color = 6 ColorWhite Color = 7 // Bright variants ColorBrightBlack Color = 8 ColorBrightRed Color = 9 ColorBrightGreen Color = 10 ColorBrightYellow Color = 11 ColorBrightBlue Color = 12 ColorBrightMagenta Color = 13 ColorBrightCyan Color = 14 ColorBrightWhite Color = 15 )
Color constants
type CursorShape ¶
type CursorShape int
CursorShape controls the terminal cursor appearance.
const ( CursorDefault CursorShape = iota // Terminal default CursorBlock // Block cursor CursorUnderline // Underline cursor CursorBeam // Beam/bar cursor )
type CursorShapeSetter ¶
type CursorShapeSetter interface {
SetCursorShape(shape CursorShape)
}
CursorShapeSetter allows backends to control cursor appearance. This is optional — backends that don't support it will be skipped.
type FrameWriter ¶
type FrameWriter interface {
WriteFrame(encoded []byte)
}
FrameWriter writes raw frame bytes to the backend.
type Image ¶
type Image struct {
Width int
Height int
CellWidth int
CellHeight int
Format ImageFormat
Protocol ImageProtocol
Pixels []byte
}
Image describes a pixel image to be rendered.
type ImageFormat ¶
type ImageFormat int
ImageFormat identifies the pixel format.
const (
ImageFormatRGBA ImageFormat = iota
)
type ImageProtocol ¶
type ImageProtocol int
ImageProtocol identifies the terminal image protocol.
const ( ImageProtocolKitty ImageProtocol = iota ImageProtocolSixel )
type ImageTarget ¶
ImageTarget captures image operations during rendering.
type ImageWriter ¶
ImageWriter renders images to the terminal backend.
type InlineHeightSetter ¶
type InlineHeightSetter interface {
SetInlineHeight(lines int)
}
InlineHeightSetter allows backends to constrain inline rendering to a fixed number of terminal rows.
type InlineModeSetter ¶
type InlineModeSetter interface {
SetInlineMode(enabled bool)
}
InlineModeSetter allows backends to opt into inline rendering mode. Inline mode should avoid switching to the alternate screen when possible.
type RectWriter ¶
RectWriter is an optional optimization for bulk rectangle updates. The cells slice is row-major and must have width*height entries.
type RenderTarget ¶
type RenderTarget interface {
Size() (width, height int)
SetContent(x, y int, mainc rune, comb []rune, style Style)
}
RenderTarget is a subset of Backend for rendering operations only. Widgets render to this interface, not the full Backend.
type Style ¶
type Style struct {
// contains filtered or unexported fields
}
Style combines foreground, background colors and attributes.
func DefaultStyle ¶
func DefaultStyle() Style
DefaultStyle returns the default style (default colors, no attributes).
func (Style) Background ¶
Background sets the background color.
func (Style) BackgroundColor ¶
BackgroundColor returns the current background color.
func (Style) Foreground ¶
Foreground sets the foreground color.
func (Style) ForegroundColor ¶
ForegroundColor returns the current foreground color.
func (Style) HyperlinkURL ¶
HyperlinkURL returns the OSC-8 hyperlink URL.
func (Style) StrikeThrough ¶
StrikeThrough enables or disables strikethrough.
type SubTarget ¶
type SubTarget struct {
// contains filtered or unexported fields
}
SubTarget wraps a RenderTarget with an offset for sub-region rendering.
func NewSubTarget ¶
func NewSubTarget(parent RenderTarget, x, y, w, h int) *SubTarget
NewSubTarget creates a sub-region of a RenderTarget.
func (*SubTarget) SetContent ¶
SetContent sets content with coordinates relative to the sub-target.
type SyncOutputWriter ¶
type SyncOutputWriter interface {
// SetSyncOutput enables or disables synchronized output support.
// Call this after detecting terminal capabilities.
SetSyncOutput(enabled bool)
// SyncOutputSupported reports whether the terminal supports
// synchronized output (DEC mode 2026).
SyncOutputSupported() bool
// BeginSync writes the DEC mode 2026 enable sequence (\x1b[?2026h)
// to the terminal, starting a synchronized update block.
BeginSync()
// EndSync writes the DEC mode 2026 disable sequence (\x1b[?2026l)
// to the terminal, ending a synchronized update block. The terminal
// flushes all buffered output at this point.
EndSync()
}
SyncOutputWriter is an optional interface for backends that support DEC private mode 2026 (synchronized output). When the terminal supports this mode, wrapping a frame update in BeginSync/EndSync causes the terminal to buffer all output and apply it atomically, eliminating screen tearing.
The runtime detects terminal capabilities at startup and calls SetSyncOutput(true) when the terminal is known to support mode 2026. The render loop then checks SyncOutputSupported before each frame and wraps the update in BeginSync/EndSync.
Usage:
if sw, ok := backend.(SyncOutputWriter); ok && sw.SyncOutputSupported() {
sw.BeginSync()
defer sw.EndSync()
}
// ... send frame data ...
backend.Show()
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package sim provides a simulation backend for testing.
|
Package sim provides a simulation backend for testing. |
|
Package tcell provides a Backend implementation using tcell.
|
Package tcell provides a Backend implementation using tcell. |
|
Package web provides a backend that renders FluffyUI applications to a web browser via WebSocket.
|
Package web provides a backend that renders FluffyUI applications to a web browser via WebSocket. |