Documentation
¶
Overview ¶
Package vio provides Vigo's terminal screen abstraction: cells, attributes, surfaces, palettes, glyph sets, and a Screen interface backed by tcell or a fake screen for tests.
Index ¶
- Constants
- Variables
- type Attr
- type BorderSet
- type Cell
- type Color
- type FakeScreen
- func (f *FakeScreen) Cursor() (x, y int, visible bool)
- func (f *FakeScreen) Events() <-chan event.Event
- func (f *FakeScreen) Fini()
- func (f *FakeScreen) Init() error
- func (f *FakeScreen) PushEvent(e event.Event)
- func (f *FakeScreen) Resize(w, h int)
- func (f *FakeScreen) SetCursor(x, y int, visible bool)
- func (f *FakeScreen) Show(s *Surface) error
- func (f *FakeScreen) Size() (int, int)
- func (f *FakeScreen) Surface() *Surface
- type Modifier
- type Palette
- type Point
- type Rect
- type Screen
- type Surface
- func (s *Surface) At(x, y int) Cell
- func (s *Surface) Box(r Rect, b BorderSet, attr Attr)
- func (s *Surface) Clear(attr Attr)
- func (s *Surface) DrawShadow(r Rect)
- func (s *Surface) DrawString(x, y int, str string, attr Attr) int
- func (s *Surface) FillRect(r Rect, ch rune, attr Attr)
- func (s *Surface) Resize(w, h int)
- func (s *Surface) Set(x, y int, ch rune, attr Attr)
- func (s *Surface) Size() (w, h int)
- func (s *Surface) Snapshot() []string
Constants ¶
const ( Black = tcell.ColorBlack Blue = tcell.ColorNavy // BIOS "blue", the dark TV desktop Green = tcell.ColorGreen Cyan = tcell.ColorTeal Red = tcell.ColorMaroon Magenta = tcell.ColorPurple Brown = tcell.ColorOlive LightGray = tcell.ColorSilver DarkGray = tcell.ColorGray LightBlue = tcell.ColorBlue LightGreen = tcell.ColorLime LightCyan = tcell.ColorAqua LightRed = tcell.ColorRed LightMagenta = tcell.ColorFuchsia Yellow = tcell.ColorYellow White = tcell.ColorWhite )
Common Borland-style palette colors, named after their CGA/EGA originals.
const ( ShadeLight rune = '░' ShadeMedium rune = '▒' ShadeDark rune = '▓' ShadeFull rune = '█' )
Shading runes used for backgrounds, dimming, and gauges.
Variables ¶
var ( Single = BorderSet{ H: '─', V: '│', TL: '┌', TR: '┐', BL: '└', BR: '┘', LJ: '├', RJ: '┤', TJ: '┬', BJ: '┴', IX: '┼', } Double = BorderSet{ H: '═', V: '║', TL: '╔', TR: '╗', BL: '╚', BR: '╝', LJ: '╠', RJ: '╣', TJ: '╦', BJ: '╩', IX: '╬', } // ASCII fallback used when the terminal can't render Unicode box-drawing // glyphs (e.g. LANG=C with no UTF-8 support). ASCII = BorderSet{ H: '-', V: '|', TL: '+', TR: '+', BL: '+', BR: '+', LJ: '+', RJ: '+', TJ: '+', BJ: '+', IX: '+', } )
Single-line and double-line border glyphs, matching the Turbo Vision classic frames.
var BorlandClassic = Palette{ {Fg: LightGray, Bg: Blue}, {Fg: Black, Bg: LightGray}, {Fg: DarkGray, Bg: LightGray}, {Fg: Black, Bg: Green}, {Fg: LightRed, Bg: LightGray}, {Fg: Black, Bg: LightGray}, {Fg: DarkGray, Bg: LightGray}, {Fg: White, Bg: Black}, {Fg: LightRed, Bg: LightGray}, {Fg: LightGray, Bg: Blue}, {Fg: Yellow, Bg: Blue}, {Fg: White, Bg: Blue}, {Fg: DarkGray, Bg: Black}, }
BorlandClassic is the default Turbo Vision palette (subset; full set is fleshed out as widgets ship in v0.2). Indices map 1..N as Turbo Vision did, leaving room for theme overlays.
Functions ¶
This section is empty.
Types ¶
type Attr ¶
Attr describes the visual attributes of a single screen cell.
type BorderSet ¶
type BorderSet struct {
H, V rune // horizontal, vertical
TL, TR, BL, BR rune // four corners
LJ, RJ, TJ, BJ, IX rune // tee joins (left, right, top, bottom) and intersection
}
BorderSet is the rune set used to draw a rectangular frame.
type Cell ¶
Cell is a single screen position: one rune plus its visual attributes. Wide characters (e.g. East Asian double-width or emoji) occupy two consecutive cells; the trailing cell carries Rune == 0 to mark continuation.
type Color ¶
Color is the foreground or background color of a cell. It is type-aliased to tcell.Color to avoid forcing translations at call sites; vio is the only package that should know it is tcell underneath.
type FakeScreen ¶
type FakeScreen struct {
// contains filtered or unexported fields
}
FakeScreen is an in-memory Screen for tests. It keeps a Surface that reflects the latest Show() call, exposes a queueable event channel via PushEvent, and never blocks on terminal I/O.
func NewFakeScreen ¶
func NewFakeScreen(w, h int) *FakeScreen
NewFakeScreen returns a fake screen of the given size.
func (*FakeScreen) Cursor ¶
func (f *FakeScreen) Cursor() (x, y int, visible bool)
Cursor returns the last cursor state set by Application.
func (*FakeScreen) Events ¶
func (f *FakeScreen) Events() <-chan event.Event
Events returns the queue of pushed events.
func (*FakeScreen) Fini ¶
func (f *FakeScreen) Fini()
Fini closes the event channel, signaling any consumer to exit.
func (*FakeScreen) Init ¶
func (f *FakeScreen) Init() error
Init is a no-op; FakeScreen is ready to use as soon as it is constructed.
func (*FakeScreen) PushEvent ¶
func (f *FakeScreen) PushEvent(e event.Event)
PushEvent queues an event to be delivered to the consumer. Tests can drive an Application by pushing key/mouse events.
func (*FakeScreen) Resize ¶
func (f *FakeScreen) Resize(w, h int)
Resize changes the screen dimensions and emits a synthetic resize event.
func (*FakeScreen) SetCursor ¶
func (f *FakeScreen) SetCursor(x, y int, visible bool)
SetCursor records the cursor position for inspection.
func (*FakeScreen) Show ¶
func (f *FakeScreen) Show(s *Surface) error
Show records the supplied surface for inspection by tests.
func (*FakeScreen) Size ¶
func (f *FakeScreen) Size() (int, int)
Size returns the configured dimensions.
func (*FakeScreen) Surface ¶
func (f *FakeScreen) Surface() *Surface
Surface returns the surface as of the last Show call. The returned surface is shared with the screen and callers must not mutate it while tests are running, but for read-only snapshots (Snapshot, At) it is safe.
type Modifier ¶
type Modifier uint8
Modifier is a bitmask of attribute modifiers (bold, italic, underline...).
type Palette ¶
type Palette []Attr
Palette is an ordered list of attributes. Views look up attributes by a 1-indexed slot number to decouple their drawing code from concrete colors; themes can swap palettes at runtime without touching any view's Draw.
Slot 0 is conventionally reserved for an "unset" attribute (transparent fall-through). The first usable slot is 1.
type Point ¶
type Point struct {
X, Y int
}
Point is a row/column coordinate. X grows right, Y grows down. Both are 0-indexed.
type Rect ¶
type Rect struct {
X, Y, W, H int
}
Rect is an axis-aligned rectangle in cell coordinates. (X, Y) is the top-left corner and W, H are the width and height in cells. A rect with W <= 0 or H <= 0 is empty.
func (Rect) Intersect ¶
Intersect returns the largest rect contained in both r and o; the result is empty when there is no overlap.
type Screen ¶
type Screen interface {
// Init opens the terminal, switches to the alternate screen, hides the
// cursor, and starts the event pump. It is illegal to call any other
// method before Init returns nil.
Init() error
// Fini restores the terminal state. It is safe to call multiple times.
Fini()
// Size returns the current screen dimensions.
Size() (w, h int)
// Show flushes the supplied surface to the terminal. The surface size
// must match Screen.Size().
Show(s *Surface) error
// Events returns the channel of input events. The channel is closed when
// the screen is finalized.
Events() <-chan event.Event
// SetCursor positions the hardware cursor. visible == false hides it.
SetCursor(x, y int, visible bool)
}
Screen is the contract every backend implements: a sized cell grid, an event source, and a flush primitive. The vio package ships two implementations: a tcell-backed real screen and an in-memory fake screen suitable for tests.
func NewTcellScreen ¶
func NewTcellScreen() Screen
NewTcellScreen returns a Screen backed by github.com/gdamore/tcell/v2.
type Surface ¶
type Surface struct {
// contains filtered or unexported fields
}
Surface is an in-memory grid of Cells. It is the single drawing target the view tree composes onto each frame; the active Screen flushes it to the terminal at the end of every frame.
Surfaces are not safe for concurrent mutation. The framework is single- threaded for UI work; background goroutines must post events instead.
func NewSurface ¶
NewSurface allocates a surface of the given size, with all cells set to the zero Cell (rune 0, Attr{}).
func (*Surface) At ¶
At returns the cell at (x, y). If (x, y) is out of bounds, the zero Cell is returned.
func (*Surface) Box ¶
Box draws a rectangular frame around r using the supplied border set and attribute. The frame is drawn on the boundary cells of r; r's interior is untouched.
func (*Surface) DrawShadow ¶
DrawShadow paints the Turbo Vision drop-shadow: two columns to the right and one row below r, dimmed to dark-gray-on-black.
func (*Surface) DrawString ¶
DrawString writes str starting at (x, y) and stops at the right edge of the surface. It returns the number of runes drawn.
func (*Surface) Resize ¶
Resize re-allocates the surface to (w, h). The contents are reset to zero. Callers should follow with a Clear or full re-draw.