Documentation ¶
Overview ¶
Package termui implements drawing and ui elements over drivers. See TerminalDriver.
Index ¶
- Variables
- func DrawBox(s TerminalDriver, b util.Rect, style Style)
- func DrawClear(s TerminalDriver)
- func DrawFill(s TerminalDriver, b util.Rect, g Glyph)
- func DrawHLine(s TerminalDriver, p util.Point, w int, style Style)
- func DrawStringCenter(s TerminalDriver, b util.Rect, text string, style Style)
- func DrawStringLeft(s TerminalDriver, b util.Rect, t string, style Style)
- func DrawStringRight(s TerminalDriver, b util.Rect, text string, style Style)
- func DrawVLine(s TerminalDriver, p util.Point, h int, style Style)
- func RunMode(s TerminalDriver, m Mode)
- type Color
- type EventKey
- type EventQuit
- type EventResize
- type Glyph
- type List
- type Mode
- type Style
- type TerminalDriver
- type TextBox
- type Theme
Constants ¶
This section is empty.
Variables ¶
var DefaultTheme = Theme{ Normal: StyleDefault. Background(ColorBlack). Foreground(ColorWhite), Highlight: StyleDefault. Background(ColorNavy). Foreground(ColorWhite), Error: StyleDefault. Background(ColorRed). Foreground(ColorWhite), }
The default theme
var ErrorQuit = errors.New("quit")
Error that indicates we just want to quit the Mode function
var Palette = []color.Color{ color.RGBA{R: 0, G: 0, B: 0, A: 255}, color.RGBA{R: 170, G: 0, B: 0, A: 255}, color.RGBA{R: 0, G: 170, B: 0, A: 255}, color.RGBA{R: 170, G: 85, B: 0, A: 255}, color.RGBA{R: 0, G: 0, B: 170, A: 255}, color.RGBA{R: 170, G: 0, B: 170, A: 255}, color.RGBA{R: 0, G: 170, B: 170, A: 255}, color.RGBA{R: 170, G: 170, B: 170, A: 255}, color.RGBA{R: 85, G: 85, B: 85, A: 255}, color.RGBA{R: 255, G: 85, B: 85, A: 255}, color.RGBA{R: 85, G: 255, B: 85, A: 255}, color.RGBA{R: 255, G: 255, B: 85, A: 255}, color.RGBA{R: 85, G: 85, B: 255, A: 255}, color.RGBA{R: 255, G: 85, B: 255, A: 255}, color.RGBA{R: 85, G: 255, B: 255, A: 255}, color.RGBA{R: 255, G: 255, B: 255, A: 255}, }
Built-in palette
var StyleDefault = Style(0).Foreground(ColorWhite).Background(ColorBlack)
Default terminal style
Functions ¶
func DrawFill ¶
func DrawFill(s TerminalDriver, b util.Rect, g Glyph)
DrawFill fills a region of the screen.
func DrawHLine ¶
func DrawHLine(s TerminalDriver, p util.Point, w int, style Style)
DrawHLine draws a horizontal line.
func DrawStringCenter ¶
func DrawStringCenter(s TerminalDriver, b util.Rect, text string, style Style)
DrawStringCenter draws a string centered.
func DrawStringLeft ¶
func DrawStringLeft(s TerminalDriver, b util.Rect, t string, style Style)
DrawStringLeft draws a string left-justified.
func DrawStringRight ¶
func DrawStringRight(s TerminalDriver, b util.Rect, text string, style Style)
DrawStringRight draws a string right-justified.
Types ¶
type Color ¶
type Color uint8
Color is a wrapper value for tcell.Color.
func (Color) MarshalJSON ¶
func (*Color) UnmarshalJSON ¶
type EventResize ¶
type List ¶
type List struct { Bounds util.Rect // Bounds of the rect on screen CursorPos int // Current cursor position Boxed bool // If true a box is drawn around the list Title string // Title for the box, if any Items []string // Items of the list Selected func(TerminalDriver, int) error // The function that is called if the user selects an item HideCursor bool // If true we will not highlight the cursor position }
List implements a mode that presents a scrollable list to the user.
func (*List) CurrentSelection ¶
CurrentSelection returns the string under the current cursor position.
func (*List) HandleEvent ¶
func (m *List) HandleEvent(s TerminalDriver, e any) error
HandleEvent implements the Mode interface.
type Mode ¶
type Mode interface { // HandleEvent is responsible for updating the mode's state in response to // events. If ErrorQuit is returned the mode is exited. Any other error is // treated as fatal. HandleEvent(TerminalDriver, any) error // Draw is responsible for drawing the mode to the terminal driver. Draw(TerminalDriver) }
Mode is the interface all objects implementing a game mode must implement.
type Style ¶
type Style uint16
Style defines the appearance of a glyph.
func (Style) Background ¶
Background returns the style with the background set.
func (Style) Foreground ¶
Foreground returns the style with the foreground set.
type TerminalDriver ¶
type TerminalDriver interface { // Init is responsible for all initialization operations. Init() error // Fini is responsible for all cleanup operations. Fini() // Quit forces the driver to exit. Quit() // SetCell sets a single cell of the screen. SetCell(util.Point, Glyph) // GetCell returns the glyph at the given point on the screen. GetCell(util.Point) Glyph // PollEvent returns the next event. PollEvent() any // FlushEvents discards all non-system events currently in the buffer. FlushEvents() // Size returns the size of the screen. Size() (int, int) // Sync must redraw the entire terminal display. Sync() // Show must redraw the dirty areas of the terminal display. Show() }
TerminalDriver is the interface terminal front-end implementations must implement to use termui.
type TextBox ¶
type TextBox struct { Bounds util.Rect // Fixed bounds of the text box display, line length is inferred from this Boxed bool // If true a box will be rendered around the text box Title string // Title to display if any, only valid if Boxed is true // contains filtered or unexported fields }
TextBox implements a word-wrapped text box that displays a single string.
func (*TextBox) HandleEvent ¶
func (m *TextBox) HandleEvent(s TerminalDriver, e any) error
HandleEvent implements the Mode interface.