Documentation
¶
Overview ¶
termbox is a library for creating cross-platform text-based interfaces
Index ¶
- Constants
- Variables
- func Clear(fg, bg Attribute) error
- func Close()
- func Flush() error
- func HideCursor()
- func Init() error
- func Interrupt()
- func SetCell(x, y int, ch rune, fg, bg Attribute)
- func SetCursor(x, y int)
- func Size() (int, int)
- func Sync() error
- type Attribute
- type Cell
- type Event
- type EventType
- type InputMode
- type Key
- type Modifier
- type OutputMode
Constants ¶
const ( SM_CXMIN = 28 SM_CYMIN = 29 )
Variables ¶
var (
IsInit bool = false
)
To know if termbox has been initialized or not
Functions ¶
func Close ¶
func Close()
Finalizes termbox library, should be called after successful initialization when termbox's functionality isn't required anymore.
func Init ¶
func Init() error
Initializes termbox library. This function should be called before any other functions. After successful initialization, the library must be finalized using 'Close' function.
Example usage:
err := termbox.Init()
if err != nil {
panic(err)
}
defer termbox.Close()
func Interrupt ¶
func Interrupt()
Interrupt an in-progress call to PollEvent by causing it to return EventInterrupt. Note that this function will block until the PollEvent function has successfully been interrupted.
func Size ¶
Returns the size of the internal back buffer (which is mostly the same as console's window size in characters). But it doesn't always match the size of the console window, after the console size has changed, the internal back buffer will get in sync only after Clear or Flush function calls.
func Sync ¶
func Sync() error
Sync comes handy when something causes desync between termbox's understanding of a terminal buffer and the reality. Such as a third party process. Sync forces a complete resync between the termbox and a terminal, it may not be visually pretty though. At the moment on Windows it does nothing.
Types ¶
type Attribute ¶
type Attribute uint16
const ( ColorDefault Attribute = iota ColorBlack ColorRed ColorGreen ColorYellow ColorBlue ColorMagenta ColorCyan ColorWhite )
Cell colors, you can combine a color with multiple attributes using bitwise OR ('|').
Cell attributes, it is possible to use multiple attributes by combining them using bitwise OR ('|'). Although, colors cannot be combined. But you can combine attributes and a single color.
It's worth mentioning that some platforms don't support certain attributes. For example windows console doesn't support AttrUnderline. And on some terminals applying AttrBold to background may result in blinking text. Use them with caution and test your code on various terminals.
type Cell ¶
A cell, single conceptual entity on the screen. The screen is basically a 2d array of cells. 'Ch' is a unicode character, 'Fg' and 'Bg' are foreground and background attributes respectively.
func CellBuffer ¶
func CellBuffer() []Cell
Returns a slice into the termbox's back buffer. You can get its dimensions using 'Size' function. The slice remains valid as long as no 'Clear' or 'Flush' function calls were made after call to this function.
type Event ¶
type Event struct {
Type EventType // one of Event* constants
Mod Modifier // one of Mod* constants or 0
Key Key // one of Key* constants, invalid if 'Ch' is not 0
Ch rune // a unicode character
Width int // width of the screen
Height int // height of the screen
Err error // error in case if input failed
MouseX int // x coord of mouse
MouseY int // y coord of mouse
N int // number of bytes written when getting a raw event
}
This type represents a termbox event. The 'Mod', 'Key' and 'Ch' fields are valid if 'Type' is EventKey. The 'Width' and 'Height' fields are valid if 'Type' is EventResize. The 'Err' field is valid if 'Type' is EventError.
type InputMode ¶
type InputMode int
Input mode. See SetInputMode function.
func SetInputMode ¶
Sets termbox input mode. Termbox has two input modes:
1. Esc input mode. When ESC sequence is in the buffer and it doesn't match any known sequence. ESC means KeyEsc. This is the default input mode.
2. Alt input mode. When ESC sequence is in the buffer and it doesn't match any known sequence. ESC enables ModAlt modifier for the next keyboard event.
Both input modes can be OR'ed with Mouse mode. Setting Mouse mode bit up will enable mouse button press/release and drag events.
If 'mode' is InputCurrent, returns the current input mode. See also Input* constants.
type Key ¶
type Key uint16
const ( KeyF1 Key = 0xFFFF - iota KeyF2 KeyF3 KeyF4 KeyF5 KeyF6 KeyF7 KeyF8 KeyF9 KeyF10 KeyF11 KeyF12 KeyInsert KeyDelete KeyHome KeyEnd KeyPgup KeyPgdn KeyArrowUp KeyArrowDown KeyArrowLeft KeyArrowRight MouseLeft MouseMiddle MouseRight MouseRelease MouseWheelUp MouseWheelDown )
Key constants, see Event.Key field.
const ( KeyCtrlTilde Key = 0x00 KeyCtrl2 Key = 0x00 KeyCtrlSpace Key = 0x00 KeyCtrlA Key = 0x01 KeyCtrlB Key = 0x02 KeyCtrlC Key = 0x03 KeyCtrlD Key = 0x04 KeyCtrlE Key = 0x05 KeyCtrlF Key = 0x06 KeyCtrlG Key = 0x07 KeyBackspace Key = 0x08 KeyCtrlH Key = 0x08 KeyTab Key = 0x09 KeyCtrlI Key = 0x09 KeyCtrlJ Key = 0x0A KeyCtrlK Key = 0x0B KeyCtrlL Key = 0x0C KeyEnter Key = 0x0D KeyCtrlM Key = 0x0D KeyCtrlN Key = 0x0E KeyCtrlO Key = 0x0F KeyCtrlP Key = 0x10 KeyCtrlQ Key = 0x11 KeyCtrlR Key = 0x12 KeyCtrlS Key = 0x13 KeyCtrlT Key = 0x14 KeyCtrlU Key = 0x15 KeyCtrlV Key = 0x16 KeyCtrlW Key = 0x17 KeyCtrlX Key = 0x18 KeyCtrlY Key = 0x19 KeyCtrlZ Key = 0x1A KeyEsc Key = 0x1B KeyCtrlLsqBracket Key = 0x1B KeyCtrl3 Key = 0x1B KeyCtrl4 Key = 0x1C KeyCtrlBackslash Key = 0x1C KeyCtrl5 Key = 0x1D KeyCtrlRsqBracket Key = 0x1D KeyCtrl6 Key = 0x1E KeyCtrl7 Key = 0x1F KeyCtrlSlash Key = 0x1F KeyCtrlUnderscore Key = 0x1F KeySpace Key = 0x20 KeyBackspace2 Key = 0x7F KeyCtrl8 Key = 0x7F )
type OutputMode ¶
type OutputMode int
const ( OutputCurrent OutputMode = iota OutputNormal Output256 Output216 OutputGrayscale )
Output mode. See SetOutputMode function.
func SetOutputMode ¶
func SetOutputMode(mode OutputMode) OutputMode
Sets the termbox output mode.
Windows console does not support extra colour modes, so this will always set and return OutputNormal.