Documentation ¶
Index ¶
- Constants
- Variables
- func Init(backend Backend) error
- func InitTCell() error
- func MaxInt(a, b int) int
- func MinInt(a, b int) int
- func Quit()
- func RGBAToTCellColor(color color.RGBA) tcell.Color
- func RandomSeed() int64
- func Run(cb func(*Screen)) error
- func SetSeed(seed int64)
- func Setup(cb func(*Screen)) error
- func StyleToTCellStyle(style Style) tcell.Style
- type Backend
- type BackendTCell
- func (backend *BackendTCell) Init() (err error)
- func (backend *BackendTCell) Quit()
- func (backend *BackendTCell) Refresh()
- func (backend *BackendTCell) Run(cb func(*Screen)) (err error)
- func (backend *BackendTCell) Scale() float64
- func (backend *BackendTCell) SetGlyphs(id glyphs.ID, path string, size float64) error
- func (backend *BackendTCell) SetScale(scale float64)
- func (backend *BackendTCell) SetSize(w, h int)
- func (backend *BackendTCell) SetTitle(title string)
- func (backend *BackendTCell) Setup(cb func(*Screen)) (err error)
- func (backend *BackendTCell) Size() (int, int)
- func (backend *BackendTCell) SyncSize()
- func (backend *BackendTCell) Units() int
- type BackendVirtual
- func (backend *BackendVirtual) Init() error
- func (backend *BackendVirtual) Quit()
- func (backend *BackendVirtual) Refresh()
- func (backend *BackendVirtual) Run(cb func(*Screen)) (err error)
- func (backend *BackendVirtual) Scale() float64
- func (backend *BackendVirtual) SetGlyphs(id glyphs.ID, path string, size float64) error
- func (backend *BackendVirtual) SetScale(scale float64)
- func (backend *BackendVirtual) SetSize(w, h int)
- func (backend *BackendVirtual) SetTitle(title string)
- func (backend *BackendVirtual) Setup(cb func(*Screen)) (err error)
- func (backend *BackendVirtual) Size() (int, int)
- func (backend *BackendVirtual) SyncSize()
- func (backend *BackendVirtual) Units() int
- type Cell
- type Color
- type Event
- type EventKey
- type EventMouse
- type EventQuit
- type EventResize
- type Key
- type Mod
- type Screen
- func (screen *Screen) Clear()
- func (screen *Screen) Close()
- func (screen *Screen) DrawRune(x int, y int, r rune, s Style) error
- func (screen *Screen) DrawScreen(destX, destY, destWidth, destHeight, sourceX, sourceY int, subscreen *Screen) error
- func (screen *Screen) DrawString(x int, y int, str string, s Style) error
- func (screen *Screen) Flush()
- func (screen *Screen) ForceRedraw()
- func (screen *Screen) Init() (err error)
- func (screen *Screen) Scale() float64
- func (screen *Screen) SetBackground(x int, y int, c Color) error
- func (screen *Screen) SetDefaultBackground(c Color)
- func (screen *Screen) SetDefaultForeground(c Color)
- func (screen *Screen) SetForeground(x int, y int, c Color) error
- func (screen *Screen) SetGlyphs(id glyphs.ID, path string, size float64) error
- func (screen *Screen) SetGlyphsID(x int, y int, id glyphs.ID) error
- func (screen *Screen) SetRune(x int, y int, r rune) error
- func (screen *Screen) SetScale(scale float64)
- func (screen *Screen) SetSize(c, r int)
- func (screen *Screen) SetStyle(x int, y int, s Style) error
- func (screen *Screen) SetTitle(title string)
- func (screen *Screen) SetWindowSize(w, h int)
- func (screen *Screen) Size() (int, int)
- func (screen *Screen) Sync() (err error)
- func (screen *Screen) WaitEvent() Event
- func (screen *Screen) WindowSize() (int, int)
- type Style
Constants ¶
const ( KeyNull Key = iota KeyBackspace KeyTab KeyReturn KeyEscape KeySpace KeyExclaim KeyDoubleQuote KeyHash KeyDollar KeyPercent KeyAmpersand KeyQuote KeyLeftParenthesis KeyRightParenthesis KeyAsterisk KeyPlus KeyComma KeyMinus KeyPeriod KeySlash Key0 Key1 Key2 Key3 Key4 Key5 Key6 Key7 Key8 Key9 KeyColon KeySemiColon KeyLess KeyEqual KeyGreater KeyQuestion KeyAt KeyLeftBracket = iota + 26 KeyBackslash KeyRightBracket KeyCaret KeyUnderscore KeyBackquote KeyA KeyB KeyC KeyD KeyE KeyF KeyG KeyH KeyI KeyJ KeyK KeyL KeyM KeyN KeyO KeyP KeyQ KeyR KeyS KeyT KeyU KeyV KeyW KeyX KeyY KeyZ KeyLeftCurlyBracket KeyPipe KeyRightCurlyBracket KeyGraveAccent KeyDelete KeyAlt KeyControl KeyShift KeyCapsLock KeyEnd KeyMenu KeyHome KeyPrintScreen KeyScrollLock KeyEnter KeyInsert KeyPageUp KeyPageDown KeyPause KeySemicolon KeyApostrophe KeyF1 KeyF2 KeyF3 KeyF4 KeyF5 KeyF6 KeyF7 KeyF8 KeyF9 KeyF10 KeyF11 KeyF12 KeyNumLock KeyKP0 KeyKP1 KeyKP2 KeyKP3 KeyKP4 KeyKP5 KeyKP6 KeyKP7 KeyKP8 KeyKP9 KeyKPAdd KeyKPPeriod KeyKPDivide KeyKPDecimal KeyKPEnter KeyKPEqual KeyKPMultiply KeyKPSubtract KeyLeft KeyUp KeyRight KeyDown )
These are our constant key variables.
const ( UnitCells = iota UnitPixels )
Units a backend might use.
Variables ¶
var ( ColorNone = Color{0x00, 0x00, 0x00, 0x00} Color0 = Color{0x00, 0x00, 0x00, 0xFF} Color1 = Color{0x80, 0x00, 0x00, 0xFF} Color2 = Color{0x00, 0x80, 0x00, 0xFF} Color3 = Color{0x80, 0x80, 0x00, 0xFF} Color4 = Color{0x00, 0x00, 0x80, 0xFF} Color5 = Color{0x80, 0x00, 0x80, 0xFF} Color6 = Color{0x00, 0x80, 0x80, 0xFF} Color7 = Color{0xC0, 0xC0, 0xC0, 0xFF} Color8 = Color{0x80, 0x80, 0x80, 0xFF} Color9 = Color{0xFF, 0x00, 0x00, 0xFF} Color10 = Color{0x00, 0xFF, 0x00, 0xFF} Color11 = Color{0xFF, 0xFF, 0x00, 0xFF} Color12 = Color{0x00, 0x00, 0xFF, 0xFF} Color13 = Color{0xFF, 0x00, 0xFF, 0xFF} Color14 = Color{0x00, 0xFF, 0xFF, 0xFF} Color15 = Color{0xFF, 0xFF, 0xFF, 0xFF} ColorBlack = Color0 ColorMaroon = Color1 ColorGreen = Color2 ColorOlive = Color3 ColorPurple = Color5 ColorTeal = Color6 ColorSilver = Color7 ColorGray = Color8 ColorRed = Color9 ColorLime = Color10 ColorYellow = Color11 ColorBlue = Color12 ColorFuchsia = Color13 ColorAqua = Color14 ColorWhite = Color15 )
These colors represent the default 8 color and 8 bright colors.
var Random = rand.New(rand.NewSource(0))
Random is our global default for random calls.
var RuneMap = map[Key]rune{ KeySpace: ' ', KeyExclaim: '!', KeyDoubleQuote: '"', KeyHash: '#', KeyDollar: '$', KeyPercent: '%', KeyAmpersand: '&', KeyQuote: '\'', KeyLeftParenthesis: '(', KeyRightParenthesis: ')', KeyAsterisk: '*', KeyPlus: '+', KeyComma: ',', KeyMinus: '-', KeyPeriod: '.', KeySlash: '/', Key0: '0', Key1: '1', Key2: '2', Key3: '3', Key4: '4', Key5: '5', Key6: '6', Key7: '7', Key8: '8', Key9: '9', KeyColon: ':', KeySemiColon: ';', KeyLess: '<', KeyEqual: '=', KeyGreater: '>', KeyQuestion: '?', KeyAt: '@', KeyA: 'A', KeyB: 'B', KeyC: 'C', KeyD: 'D', KeyE: 'E', KeyF: 'F', KeyG: 'G', KeyH: 'H', KeyI: 'I', KeyJ: 'J', KeyK: 'K', KeyL: 'L', KeyM: 'M', KeyN: 'N', KeyO: 'O', KeyP: 'P', KeyQ: 'Q', KeyR: 'R', KeyS: 'S', KeyT: 'T', KeyU: 'U', KeyV: 'V', KeyW: 'W', KeyX: 'X', KeyY: 'Y', KeyZ: 'Z', }
RuneMap provides a Key to default rune mapping.
var RuneToKeyMap = map[rune]Key{ ' ': KeySpace, '!': KeyExclaim, '"': KeyDoubleQuote, '#': KeyHash, '$': KeyDollar, '%': KeyPercent, '&': KeyAmpersand, '\'': KeyQuote, '(': KeyLeftParenthesis, ')': KeyRightParenthesis, '*': KeyAsterisk, '+': KeyPlus, ',': KeyComma, '-': KeyMinus, '.': KeyPeriod, '/': KeySlash, '0': Key0, '1': Key1, '2': Key2, '3': Key3, '4': Key4, '5': Key5, '6': Key6, '7': Key7, '8': Key8, '9': Key9, ':': KeyColon, ';': KeySemiColon, '<': KeyLess, '=': KeyEqual, '>': KeyGreater, '?': KeyQuestion, '@': KeyAt, 'A': KeyA, 'B': KeyB, 'C': KeyC, 'D': KeyD, 'E': KeyE, 'F': KeyF, 'G': KeyG, 'H': KeyH, 'I': KeyI, 'J': KeyJ, 'K': KeyK, 'L': KeyL, 'M': KeyM, 'N': KeyN, 'O': KeyO, 'P': KeyP, 'Q': KeyQ, 'R': KeyR, 'S': KeyS, 'T': KeyT, 'U': KeyU, 'V': KeyV, 'W': KeyW, 'X': KeyX, 'Y': KeyY, 'Z': KeyZ, '[': KeyLeftBracket, '\\': KeyBackslash, ']': KeyRightBracket, '^': KeyCaret, '_': KeyUnderscore, '`': KeyGraveAccent, 'a': KeyA, 'b': KeyB, 'c': KeyC, 'd': KeyD, 'e': KeyE, 'f': KeyF, 'g': KeyG, 'h': KeyH, 'i': KeyI, 'j': KeyJ, 'k': KeyK, 'l': KeyL, 'm': KeyM, 'n': KeyN, 'o': KeyO, 'p': KeyP, 'q': KeyQ, 'r': KeyR, 's': KeyS, 't': KeyT, 'u': KeyU, 'v': KeyV, 'w': KeyW, 'x': KeyX, 'y': KeyY, 'z': KeyZ, '{': KeyLeftCurlyBracket, '|': KeyPipe, '}': KeyRightCurlyBracket, '~': KeyGraveAccent, }
RuneToKeyMap provides rune to key mapping.
Functions ¶
func Init ¶
Init initializes a given Backend interface. Built-in options are EbitenBackend and TCellBackend.
func InitTCell ¶
func InitTCell() error
InitTCell initializes the TCell backend for use. Calls BackendTCell.Init().
func RGBAToTCellColor ¶
RGBAToTCellColor converts a color.RGBA to a tcell.Color type.
func RandomSeed ¶
func RandomSeed() int64
RandomSeed returns a randomized int64 seed based upon time.
func Setup ¶
Setup takes a callback for setting up goro before the backend creates any windows. Optional.
func StyleToTCellStyle ¶
StyleToTCellStyle converts a provided Style into a tcell.Style.
Types ¶
type Backend ¶
type Backend interface { Init() error Setup(func(*Screen)) error Run(func(*Screen)) error Refresh() Quit() Size() (int, int) SetSize(int, int) Units() int Scale() float64 SetScale(float64) SetTitle(string) SetGlyphs(glyphs.ID, string, float64) error SyncSize() }
Backend is an interface through which a Screen is displayed and controlled.
type BackendTCell ¶
type BackendTCell struct {
// contains filtered or unexported fields
}
BackendTCell is the backend for the tcell library.
func (*BackendTCell) Init ¶
func (backend *BackendTCell) Init() (err error)
Init initializes the base data structures and sets up the library for use.
func (*BackendTCell) Refresh ¶
func (backend *BackendTCell) Refresh()
Refresh causes the backend loop to redraw the screen.
func (*BackendTCell) Run ¶
func (backend *BackendTCell) Run(cb func(*Screen)) (err error)
Run runs the given function cb as a goroutine and starts the entire tcell loop.
func (*BackendTCell) Scale ¶
func (backend *BackendTCell) Scale() float64
Scale returns the current backend window scaling. Does nothing.
func (*BackendTCell) SetScale ¶
func (backend *BackendTCell) SetScale(scale float64)
SetScale sets the backend window's scaling. Does nothing.
func (*BackendTCell) SetSize ¶
func (backend *BackendTCell) SetSize(w, h int)
SetSize sets the backend window to the provided width and height. Does nothing.
func (*BackendTCell) SetTitle ¶
func (backend *BackendTCell) SetTitle(title string)
SetTitle sets the backend window's title.
func (*BackendTCell) Setup ¶
func (backend *BackendTCell) Setup(cb func(*Screen)) (err error)
Setup runs the given function cb.
func (*BackendTCell) Size ¶
func (backend *BackendTCell) Size() (int, int)
Size returns the current backend window dimensions.
func (*BackendTCell) Units ¶
func (backend *BackendTCell) Units() int
Units returns the unit type the backend uses for Size().
type BackendVirtual ¶
type BackendVirtual struct {
// contains filtered or unexported fields
}
BackendVirtual is the virtual backend used for sub-screens.
func (*BackendVirtual) Init ¶
func (backend *BackendVirtual) Init() error
Init sets up our appropriate data structures.
func (*BackendVirtual) Refresh ¶
func (backend *BackendVirtual) Refresh()
Refresh forces the screen to redraw.
func (*BackendVirtual) Run ¶
func (backend *BackendVirtual) Run(cb func(*Screen)) (err error)
Run runs the given function cb as a goroutine.
func (*BackendVirtual) Scale ¶
func (backend *BackendVirtual) Scale() float64
Scale returns the current backend window scaling.
func (*BackendVirtual) SetScale ¶
func (backend *BackendVirtual) SetScale(scale float64)
SetScale sets the backend window's scaling.
func (*BackendVirtual) SetSize ¶
func (backend *BackendVirtual) SetSize(w, h int)
SetSize sets the backend window to the provided width and height.
func (*BackendVirtual) SetTitle ¶
func (backend *BackendVirtual) SetTitle(title string)
SetTitle sets the backend window's title.
func (*BackendVirtual) Setup ¶
func (backend *BackendVirtual) Setup(cb func(*Screen)) (err error)
Setup runs the given function cb.
func (*BackendVirtual) Size ¶
func (backend *BackendVirtual) Size() (int, int)
Size returns the current backend window dimensions.
func (*BackendVirtual) Units ¶
func (backend *BackendVirtual) Units() int
Units returns the unit type the backend uses for Size().
type Cell ¶
type Cell struct { Rune rune Style Style Redraw bool Dirty bool PendingRune rune PendingStyle Style PendingGlyphs glyphs.ID Glyphs glyphs.ID }
Cell abstractly represents a rune, style, and other data.
type EventKey ¶
EventKey represents a keypress event.
func (EventKey) HasModifiers ¶
HasModifiers returns if any modifier keys were held.
type EventMouse ¶
EventMouse represents a mouse press event.
type EventResize ¶
type EventResize struct {
Columns, Rows int
}
EventResize represents screen changes such as terminal resizing.
type Screen ¶
type Screen struct {
ScrollX, ScrollY int
Columns, Rows int
UseKeys bool
UseMouse bool
AutoSize bool
Foreground Color
Background Color
Redraw bool
// contains filtered or unexported fields
}
Screen is a virtual Rows x Columns buffer used for drawing runes to.
func (*Screen) Close ¶
func (screen *Screen) Close()
Close sets the Screen as inactive thereby allowing the backend to clean it up.
func (*Screen) DrawRune ¶
DrawRune draws a given rune at the position of x and y with a given style.
func (*Screen) DrawScreen ¶
func (screen *Screen) DrawScreen(destX, destY, destWidth, destHeight, sourceX, sourceY int, subscreen *Screen) error
DrawScreen draws the provided screen onto the current screen.
func (*Screen) DrawString ¶
DrawString draws a string at the position of x and y with a given style, iterating in the x direction as it goes.
func (*Screen) Flush ¶
func (screen *Screen) Flush()
Flush forcibly causes the screen to commit any pending changes via a Draw* call and render to the backend.
func (*Screen) ForceRedraw ¶
func (screen *Screen) ForceRedraw()
ForceRedraw marks each cell of the screen to be redrawn.
func (*Screen) SetBackground ¶
SetBackground sets the background at the given location.
func (*Screen) SetDefaultBackground ¶
SetDefaultBackground sets the default background color to use.
func (*Screen) SetDefaultForeground ¶
SetDefaultForeground sets the default foreground color to use.
func (*Screen) SetForeground ¶
SetForeground sets the foreground at the given location.
func (*Screen) SetGlyphs ¶
SetGlyphs sets the screen backend's window to use the provided font. Only available for graphical backends.
func (*Screen) SetGlyphsID ¶
SetGlyphsID sets the glyphs at a given location.
func (*Screen) SetWindowSize ¶
SetWindowSize sets the current backend's window to the provided width and height in the backend's units, if available.
func (*Screen) Sync ¶
Sync synchronizes the screen's actual cells with the current Rows and Columns.
func (*Screen) WindowSize ¶
WindowSize returns the current backend's window size in its preferred units, if available.