...

Package termbox

import "github.com/gdamore/tcell/v2/termbox"
Overview
Index

Overview ▾

Package termbox is a compatibility layer to allow tcell to emulate the github.com/nsf/termbox package.

Constants

Keys codes.

const (
    KeyF1             = Key(tcell.KeyF1)
    KeyF2             = Key(tcell.KeyF2)
    KeyF3             = Key(tcell.KeyF3)
    KeyF4             = Key(tcell.KeyF4)
    KeyF5             = Key(tcell.KeyF5)
    KeyF6             = Key(tcell.KeyF6)
    KeyF7             = Key(tcell.KeyF7)
    KeyF8             = Key(tcell.KeyF8)
    KeyF9             = Key(tcell.KeyF9)
    KeyF10            = Key(tcell.KeyF10)
    KeyF11            = Key(tcell.KeyF11)
    KeyF12            = Key(tcell.KeyF12)
    KeyInsert         = Key(tcell.KeyInsert)
    KeyDelete         = Key(tcell.KeyDelete)
    KeyHome           = Key(tcell.KeyHome)
    KeyEnd            = Key(tcell.KeyEnd)
    KeyArrowUp        = Key(tcell.KeyUp)
    KeyArrowDown      = Key(tcell.KeyDown)
    KeyArrowRight     = Key(tcell.KeyRight)
    KeyArrowLeft      = Key(tcell.KeyLeft)
    KeyCtrlA          = Key(tcell.KeyCtrlA)
    KeyCtrlB          = Key(tcell.KeyCtrlB)
    KeyCtrlC          = Key(tcell.KeyCtrlC)
    KeyCtrlD          = Key(tcell.KeyCtrlD)
    KeyCtrlE          = Key(tcell.KeyCtrlE)
    KeyCtrlF          = Key(tcell.KeyCtrlF)
    KeyCtrlG          = Key(tcell.KeyCtrlG)
    KeyCtrlH          = Key(tcell.KeyCtrlH)
    KeyCtrlI          = Key(tcell.KeyCtrlI)
    KeyCtrlJ          = Key(tcell.KeyCtrlJ)
    KeyCtrlK          = Key(tcell.KeyCtrlK)
    KeyCtrlL          = Key(tcell.KeyCtrlL)
    KeyCtrlM          = Key(tcell.KeyCtrlM)
    KeyCtrlN          = Key(tcell.KeyCtrlN)
    KeyCtrlO          = Key(tcell.KeyCtrlO)
    KeyCtrlP          = Key(tcell.KeyCtrlP)
    KeyCtrlQ          = Key(tcell.KeyCtrlQ)
    KeyCtrlR          = Key(tcell.KeyCtrlR)
    KeyCtrlS          = Key(tcell.KeyCtrlS)
    KeyCtrlT          = Key(tcell.KeyCtrlT)
    KeyCtrlU          = Key(tcell.KeyCtrlU)
    KeyCtrlV          = Key(tcell.KeyCtrlV)
    KeyCtrlW          = Key(tcell.KeyCtrlW)
    KeyCtrlX          = Key(tcell.KeyCtrlX)
    KeyCtrlY          = Key(tcell.KeyCtrlY)
    KeyCtrlZ          = Key(tcell.KeyCtrlZ)
    KeyCtrlUnderscore = Key(tcell.KeyCtrlUnderscore)
    KeyBackspace      = Key(tcell.KeyBackspace)
    KeyBackspace2     = Key(tcell.KeyBackspace2)
    KeyTab            = Key(tcell.KeyTab)
    KeyEnter          = Key(tcell.KeyEnter)
    KeyEsc            = Key(tcell.KeyEscape)
    KeyPgdn           = Key(tcell.KeyPgDn)
    KeyPgup           = Key(tcell.KeyPgUp)
    KeySpace          = Key(tcell.Key(' '))
    KeyTilde          = Key(tcell.Key('~'))
    KeyCtrlSpace      = Key(tcell.KeyCtrlSpace)

    // The following assignments are provided for termbox
    // compatibility.  Their use in applications is discouraged.
    // The mouse keys are completely not supported as tcell uses
    // a separate mouse event instead of key strokes.
    MouseLeft         = Key(tcell.KeyF63) // arbitrary assignments
    MouseRight        = Key(tcell.KeyF62)
    MouseMiddle       = Key(tcell.KeyF61)
    MouseRelease      = Key(tcell.KeyF60)
    MouseWheelUp      = Key(tcell.KeyF59)
    MouseWheelDown    = Key(tcell.KeyF58)
    KeyCtrlTilde      = Key(tcell.KeyCtrlSpace) // termbox defines a bunch of weird ones, don't use them
    KeyCtrl2          = Key(tcell.KeyNUL)
    KeyCtrl3          = Key(tcell.KeyEscape)
    KeyCtrl4          = Key(tcell.KeyCtrlBackslash)
    KeyCtrl5          = Key(tcell.KeyCtrlRightSq)
    KeyCtrl6          = Key(tcell.KeyCtrlCarat)
    KeyCtrl7          = Key(tcell.KeyCtrlUnderscore)
    KeyCtrl8          = Key(tcell.KeyDEL)
    KeyCtrlSlash      = Key(tcell.KeyCtrlUnderscore)
    KeyCtrlRsqBracket = Key(tcell.KeyCtrlRightSq)
    KeyCtrlBackslash  = Key(tcell.KeyCtrlBackslash)
    KeyCtrlLsqBracket = Key(tcell.KeyCtrlLeftSq)
)

Modifiers.

const (
    ModAlt = Modifier(tcell.ModAlt)
)

func Clear

func Clear(fg, bg Attribute)

Clear clears the screen with the given attributes.

func Close

func Close()

Close cleans up the terminal, restoring terminal modes, etc.

func Flush

func Flush() error

Flush updates the screen.

func HideCursor

func HideCursor()

HideCursor hides the terminal cursor.

func Init

func Init() error

Init initializes the screen for use.

func Interrupt

func Interrupt()

Interrupt posts an interrupt event.

func SetCell

func SetCell(x, y int, ch rune, fg, bg Attribute)

SetCell sets the character cell at a given location to the given content (rune) and attributes.

func SetCursor

func SetCursor(x, y int)

SetCursor displays the terminal cursor at the given location.

func Size

func Size() (int, int)

Size returns the screen size as width, height in character cells.

func Sync

func Sync() error

Sync forces a resync of the screen.

type Attribute

Attribute affects the presentation of characters, such as color, boldness, and so forth.

type Attribute uint16

Colors first. The order here is significant.

const (
    ColorDefault Attribute = iota
    ColorBlack
    ColorRed
    ColorGreen
    ColorYellow
    ColorBlue
    ColorMagenta
    ColorCyan
    ColorWhite
)

Other attributes.

const (
    AttrBold Attribute = 1 << (9 + iota)
    AttrUnderline
    AttrReverse
)

type Cell

Cell represents a single character cell on screen.

type Cell struct {
    Ch rune
    Fg Attribute
    Bg Attribute
}

type Event

Event represents an event like a key press, mouse action, or window resize.

type Event struct {
    Type   EventType
    Mod    Modifier
    Key    Key
    Ch     rune
    Width  int
    Height int
    Err    error
    MouseX int
    MouseY int
    N      int
}

func ParseEvent

func ParseEvent(data []byte) Event

ParseEvent is not supported.

func PollEvent

func PollEvent() Event

PollEvent blocks until an event is ready, and then returns it.

func PollRawEvent

func PollRawEvent(data []byte) Event

PollRawEvent is not supported.

type EventType

EventType represents the type of event.

type EventType uint8

Event types.

const (
    EventNone EventType = iota
    EventKey
    EventResize
    EventMouse
    EventInterrupt
    EventError
    EventRaw
)

type InputMode

InputMode is not used.

type InputMode int

Unused input modes; here for compatibility.

const (
    InputCurrent InputMode = iota
    InputEsc
    InputAlt
    InputMouse
)

func SetInputMode

func SetInputMode(mode InputMode) InputMode

SetInputMode does not do anything in this version.

type Key

Key is a key press.

type Key tcell.Key

type Modifier

Modifier represents the possible modifier keys.

type Modifier tcell.ModMask

type OutputMode

OutputMode represents an output mode, which determines how colors are used. See the termbox documentation for an explanation.

type OutputMode int

OutputMode values.

const (
    OutputCurrent OutputMode = iota
    OutputNormal
    Output256
    Output216
    OutputGrayscale
)

func SetOutputMode

func SetOutputMode(mode OutputMode) OutputMode

SetOutputMode is used to set the color palette used.