...

Package tcell

import "github.com/gdamore/tcell/v2"
Overview
Index
Examples
Subdirectories

Overview ▾

Package tcell provides a lower-level, portable API for building programs that interact with terminals or consoles. It works with both common (and many uncommon!) terminals or terminal emulators, and Windows console implementations.

It provides support for up to 256 colors, text attributes, and box drawing elements. A database of terminals built from a real terminfo database is provided, along with code to generate new database entries.

Tcell offers very rich support for mice, dependent upon the terminal of course. (Windows, XTerm, and iTerm 2 are known to work very well.)

If the environment is not Unicode by default, such as an ISO8859 based locale or GB18030, Tcell can convert input and output, so that your terminal can operate in whatever locale is most convenient, while the application program can just assume "everything is UTF-8". Reasonable defaults are used for updating characters to something suitable for display. Unicode box drawing characters will be converted to use the alternate character set of your terminal, if native conversions are not available. If no ACS is available, then some ASCII fallbacks will be used.

Note that support for non-UTF-8 locales (other than C) must be enabled by the application using RegisterEncoding() -- we don't have them all enabled by default to avoid bloating the application unnecessarily. (These days UTF-8 is good enough for almost everyone, and nobody should be using legacy locales anymore.) Also, actual glyphs for various code point will only be displayed if your terminal or emulator (or the font the emulator is using) supports them.

A rich set of key codes is supported, with support for up to 65 function keys, and various other special keys.

Index ▾

Constants
Variables
func GetEncoding(charset string) encoding.Encoding
func LookupTerminfo(name string) (ti *terminfo.Terminfo, e error)
func RegisterEncoding(charset string, enc encoding.Encoding)
func SetEncodingFallback(fb EncodingFallback)
type AttrMask
type ButtonMask
type CellBuffer
    func (cb *CellBuffer) Dirty(x, y int) bool
    func (cb *CellBuffer) Fill(r rune, style Style)
    func (cb *CellBuffer) GetContent(x, y int) (rune, []rune, Style, int)
    func (cb *CellBuffer) Invalidate()
    func (cb *CellBuffer) Resize(w, h int)
    func (cb *CellBuffer) SetContent(x int, y int, mainc rune, combc []rune, style Style)
    func (cb *CellBuffer) SetDirty(x, y int, dirty bool)
    func (cb *CellBuffer) Size() (int, int)
type Color
    func FindColor(c Color, palette []Color) Color
    func FromImageColor(imageColor ic.Color) Color
    func GetColor(name string) Color
    func NewHexColor(v int32) Color
    func NewRGBColor(r, g, b int32) Color
    func PaletteColor(index int) Color
    func (c Color) Hex() int32
    func (c Color) IsRGB() bool
    func (c Color) RGB() (int32, int32, int32)
    func (c Color) TrueColor() Color
    func (c Color) Valid() bool
type CursorStyle
type EncodingFallback
type Event
type EventError
    func NewEventError(err error) *EventError
    func (ev *EventError) Error() string
    func (ev *EventError) When() time.Time
type EventHandler
type EventInterrupt
    func NewEventInterrupt(data interface{}) *EventInterrupt
    func (ev *EventInterrupt) Data() interface{}
    func (ev *EventInterrupt) When() time.Time
type EventKey
    func NewEventKey(k Key, ch rune, mod ModMask) *EventKey
    func (ev *EventKey) Key() Key
    func (ev *EventKey) Modifiers() ModMask
    func (ev *EventKey) Name() string
    func (ev *EventKey) Rune() rune
    func (ev *EventKey) When() time.Time
type EventMouse
    func NewEventMouse(x, y int, btn ButtonMask, mod ModMask) *EventMouse
    func (ev *EventMouse) Buttons() ButtonMask
    func (ev *EventMouse) Modifiers() ModMask
    func (ev *EventMouse) Position() (int, int)
    func (ev *EventMouse) When() time.Time
type EventPaste
    func NewEventPaste(start bool) *EventPaste
    func (ev *EventPaste) End() bool
    func (ev *EventPaste) Start() bool
    func (ev *EventPaste) When() time.Time
type EventResize
    func NewEventResize(width, height int) *EventResize
    func (ev *EventResize) Size() (int, int)
    func (ev *EventResize) When() time.Time
type EventTime
    func (e *EventTime) SetEventNow()
    func (e *EventTime) SetEventTime(t time.Time)
    func (e *EventTime) When() time.Time
type Key
type ModMask
type MouseFlags
type Screen
    func NewConsoleScreen() (Screen, error)
    func NewScreen() (Screen, error)
    func NewTerminfoScreen() (Screen, error)
    func NewTerminfoScreenFromTty(tty Tty) (Screen, error)
    func NewTerminfoScreenFromTtyTerminfo(tty Tty, ti *terminfo.Terminfo) (s Screen, e error)
type SimCell
type SimulationScreen
    func NewSimulationScreen(charset string) SimulationScreen
type Style
    func (s Style) Attributes(attrs AttrMask) Style
    func (s Style) Background(c Color) Style
    func (s Style) Blink(on bool) Style
    func (s Style) Bold(on bool) Style
    func (s Style) Decompose() (fg Color, bg Color, attr AttrMask)
    func (s Style) Dim(on bool) Style
    func (s Style) Foreground(c Color) Style
    func (s Style) Italic(on bool) Style
    func (s Style) Normal() Style
    func (s Style) Reverse(on bool) Style
    func (s Style) StrikeThrough(on bool) Style
    func (s Style) Underline(on bool) Style
    func (s Style) Url(url string) Style
    func (s Style) UrlId(id string) Style
type Tty
    func NewDevTty() (Tty, error)
    func NewDevTtyFromDev(dev string) (Tty, error)
    func NewStdIoTty() (Tty, error)

Examples

RegisterEncoding

Package files

attr.go cell.go charset_unix.go color.go colorfit.go console_stub.go doc.go encoding.go errors.go event.go interrupt.go key.go mouse.go nonblock_unix.go paste.go resize.go runes.go screen.go simulation.go stdin_unix.go style.go terms_default.go terms_dynamic.go tscreen.go tscreen_unix.go tty.go tty_unix.go

Constants

Note that the order of these options is important -- it follows the definitions used by ECMA and XTerm. Hence any further named colors must begin at a value not less than 256.

const (
    ColorBlack = ColorValid + iota
    ColorMaroon
    ColorGreen
    ColorOlive
    ColorNavy
    ColorPurple
    ColorTeal
    ColorSilver
    ColorGray
    ColorRed
    ColorLime
    ColorYellow
    ColorBlue
    ColorFuchsia
    ColorAqua
    ColorWhite
    Color16
    Color17
    Color18
    Color19
    Color20
    Color21
    Color22
    Color23
    Color24
    Color25
    Color26
    Color27
    Color28
    Color29
    Color30
    Color31
    Color32
    Color33
    Color34
    Color35
    Color36
    Color37
    Color38
    Color39
    Color40
    Color41
    Color42
    Color43
    Color44
    Color45
    Color46
    Color47
    Color48
    Color49
    Color50
    Color51
    Color52
    Color53
    Color54
    Color55
    Color56
    Color57
    Color58
    Color59
    Color60
    Color61
    Color62
    Color63
    Color64
    Color65
    Color66
    Color67
    Color68
    Color69
    Color70
    Color71
    Color72
    Color73
    Color74
    Color75
    Color76
    Color77
    Color78
    Color79
    Color80
    Color81
    Color82
    Color83
    Color84
    Color85
    Color86
    Color87
    Color88
    Color89
    Color90
    Color91
    Color92
    Color93
    Color94
    Color95
    Color96
    Color97
    Color98
    Color99
    Color100
    Color101
    Color102
    Color103
    Color104
    Color105
    Color106
    Color107
    Color108
    Color109
    Color110
    Color111
    Color112
    Color113
    Color114
    Color115
    Color116
    Color117
    Color118
    Color119
    Color120
    Color121
    Color122
    Color123
    Color124
    Color125
    Color126
    Color127
    Color128
    Color129
    Color130
    Color131
    Color132
    Color133
    Color134
    Color135
    Color136
    Color137
    Color138
    Color139
    Color140
    Color141
    Color142
    Color143
    Color144
    Color145
    Color146
    Color147
    Color148
    Color149
    Color150
    Color151
    Color152
    Color153
    Color154
    Color155
    Color156
    Color157
    Color158
    Color159
    Color160
    Color161
    Color162
    Color163
    Color164
    Color165
    Color166
    Color167
    Color168
    Color169
    Color170
    Color171
    Color172
    Color173
    Color174
    Color175
    Color176
    Color177
    Color178
    Color179
    Color180
    Color181
    Color182
    Color183
    Color184
    Color185
    Color186
    Color187
    Color188
    Color189
    Color190
    Color191
    Color192
    Color193
    Color194
    Color195
    Color196
    Color197
    Color198
    Color199
    Color200
    Color201
    Color202
    Color203
    Color204
    Color205
    Color206
    Color207
    Color208
    Color209
    Color210
    Color211
    Color212
    Color213
    Color214
    Color215
    Color216
    Color217
    Color218
    Color219
    Color220
    Color221
    Color222
    Color223
    Color224
    Color225
    Color226
    Color227
    Color228
    Color229
    Color230
    Color231
    Color232
    Color233
    Color234
    Color235
    Color236
    Color237
    Color238
    Color239
    Color240
    Color241
    Color242
    Color243
    Color244
    Color245
    Color246
    Color247
    Color248
    Color249
    Color250
    Color251
    Color252
    Color253
    Color254
    Color255
    ColorAliceBlue
    ColorAntiqueWhite
    ColorAquaMarine
    ColorAzure
    ColorBeige
    ColorBisque
    ColorBlanchedAlmond
    ColorBlueViolet
    ColorBrown
    ColorBurlyWood
    ColorCadetBlue
    ColorChartreuse
    ColorChocolate
    ColorCoral
    ColorCornflowerBlue
    ColorCornsilk
    ColorCrimson
    ColorDarkBlue
    ColorDarkCyan
    ColorDarkGoldenrod
    ColorDarkGray
    ColorDarkGreen
    ColorDarkKhaki
    ColorDarkMagenta
    ColorDarkOliveGreen
    ColorDarkOrange
    ColorDarkOrchid
    ColorDarkRed
    ColorDarkSalmon
    ColorDarkSeaGreen
    ColorDarkSlateBlue
    ColorDarkSlateGray
    ColorDarkTurquoise
    ColorDarkViolet
    ColorDeepPink
    ColorDeepSkyBlue
    ColorDimGray
    ColorDodgerBlue
    ColorFireBrick
    ColorFloralWhite
    ColorForestGreen
    ColorGainsboro
    ColorGhostWhite
    ColorGold
    ColorGoldenrod
    ColorGreenYellow
    ColorHoneydew
    ColorHotPink
    ColorIndianRed
    ColorIndigo
    ColorIvory
    ColorKhaki
    ColorLavender
    ColorLavenderBlush
    ColorLawnGreen
    ColorLemonChiffon
    ColorLightBlue
    ColorLightCoral
    ColorLightCyan
    ColorLightGoldenrodYellow
    ColorLightGray
    ColorLightGreen
    ColorLightPink
    ColorLightSalmon
    ColorLightSeaGreen
    ColorLightSkyBlue
    ColorLightSlateGray
    ColorLightSteelBlue
    ColorLightYellow
    ColorLimeGreen
    ColorLinen
    ColorMediumAquamarine
    ColorMediumBlue
    ColorMediumOrchid
    ColorMediumPurple
    ColorMediumSeaGreen
    ColorMediumSlateBlue
    ColorMediumSpringGreen
    ColorMediumTurquoise
    ColorMediumVioletRed
    ColorMidnightBlue
    ColorMintCream
    ColorMistyRose
    ColorMoccasin
    ColorNavajoWhite
    ColorOldLace
    ColorOliveDrab
    ColorOrange
    ColorOrangeRed
    ColorOrchid
    ColorPaleGoldenrod
    ColorPaleGreen
    ColorPaleTurquoise
    ColorPaleVioletRed
    ColorPapayaWhip
    ColorPeachPuff
    ColorPeru
    ColorPink
    ColorPlum
    ColorPowderBlue
    ColorRebeccaPurple
    ColorRosyBrown
    ColorRoyalBlue
    ColorSaddleBrown
    ColorSalmon
    ColorSandyBrown
    ColorSeaGreen
    ColorSeashell
    ColorSienna
    ColorSkyblue
    ColorSlateBlue
    ColorSlateGray
    ColorSnow
    ColorSpringGreen
    ColorSteelBlue
    ColorTan
    ColorThistle
    ColorTomato
    ColorTurquoise
    ColorViolet
    ColorWheat
    ColorWhiteSmoke
    ColorYellowGreen
)

These are aliases for the color gray, because some of us spell it as grey.

const (
    ColorGrey           = ColorGray
    ColorDimGrey        = ColorDimGray
    ColorDarkGrey       = ColorDarkGray
    ColorDarkSlateGrey  = ColorDarkSlateGray
    ColorLightGrey      = ColorLightGray
    ColorLightSlateGrey = ColorLightSlateGray
    ColorSlateGrey      = ColorSlateGray
)
const (
    // EncodingFallbackFail behavior causes GetEncoding to fail
    // when it cannot find an encoding.
    EncodingFallbackFail = iota

    // EncodingFallbackASCII behavior causes GetEncoding to fall back
    // to a 7-bit ASCII encoding, if no other encoding can be found.
    EncodingFallbackASCII

    // EncodingFallbackUTF8 behavior causes GetEncoding to assume
    // UTF8 can pass unmodified upon failure.  Note that this behavior
    // is not recommended, unless you are sure your terminal can cope
    // with real UTF8 sequences.
    EncodingFallbackUTF8
)

These keys are aliases for other names.

const (
    KeyBackspace  = KeyBS
    KeyTab        = KeyTAB
    KeyEsc        = KeyESC
    KeyEscape     = KeyESC
    KeyEnter      = KeyCR
    KeyBackspace2 = KeyDEL
)

The names of these constants are chosen to match Terminfo names, modulo case, and changing the prefix from ACS_ to Rune. These are the runes we provide extra special handling for, with ASCII fallbacks for terminals that lack them.

const (
    RuneSterling = '£'
    RuneDArrow   = '↓'
    RuneLArrow   = '←'
    RuneRArrow   = '→'
    RuneUArrow   = '↑'
    RuneBullet   = '·'
    RuneBoard    = '░'
    RuneCkBoard  = '▒'
    RuneDegree   = '°'
    RuneDiamond  = '◆'
    RuneGEqual   = '≥'
    RunePi       = 'π'
    RuneHLine    = '─'
    RuneLantern  = '§'
    RunePlus     = '┼'
    RuneLEqual   = '≤'
    RuneLLCorner = '└'
    RuneLRCorner = '┘'
    RuneNEqual   = '≠'
    RunePlMinus  = '±'
    RuneS1       = '⎺'
    RuneS3       = '⎻'
    RuneS7       = '⎼'
    RuneS9       = '⎽'
    RuneBlock    = '█'
    RuneTTee     = '┬'
    RuneRTee     = '┤'
    RuneLTee     = '├'
    RuneBTee     = '┴'
    RuneULCorner = '┌'
    RuneURCorner = '┐'
    RuneVLine    = '│'
)
const (
    MouseButtonEvents = MouseFlags(1) // Click events only
    MouseDragEvents   = MouseFlags(2) // Click-drag events (includes button events)
    MouseMotionEvents = MouseFlags(4) // All mouse events (includes click and drag events)
)
const (
    CursorStyleDefault = CursorStyle(iota) // The default
    CursorStyleBlinkingBlock
    CursorStyleSteadyBlock
    CursorStyleBlinkingUnderline
    CursorStyleSteadyUnderline
    CursorStyleBlinkingBar
    CursorStyleSteadyBar
)

Special colors.

const (
    // ColorReset is used to indicate that the color should use the
    // vanilla terminal colors.  (Basically go back to the defaults.)
    ColorReset = ColorSpecial | iota
)

Variables

var (
    // ErrTermNotFound indicates that a suitable terminal entry could
    // not be found.  This can result from either not having TERM set,
    // or from the TERM failing to support certain minimal functionality,
    // in particular absolute cursor addressability (the cup capability)
    // is required.  For example, legacy "adm3" lacks this capability,
    // whereas the slightly newer "adm3a" supports it.  This failure
    // occurs most often with "dumb".
    ErrTermNotFound = terminfo.ErrTermNotFound

    // ErrNoScreen indicates that no suitable screen could be found.
    // This may result from attempting to run on a platform where there
    // is no support for either termios or console I/O (such as nacl),
    // or from running in an environment where there is no access to
    // a suitable console/terminal device.  (For example, running on
    // without a controlling TTY or with no /dev/tty on POSIX platforms.)
    ErrNoScreen = errors.New("no suitable screen available")

    // ErrNoCharset indicates that the locale environment the
    // program is not supported by the program, because no suitable
    // encoding was found for it.  This problem never occurs if
    // the environment is UTF-8 or UTF-16.
    ErrNoCharset = errors.New("character set not supported")

    // ErrEventQFull indicates that the event queue is full, and
    // cannot accept more events.
    ErrEventQFull = errors.New("event queue full")
)

ColorNames holds the written names of colors. Useful to present a list of recognized named colors.

var ColorNames = map[string]Color{
    "black":                ColorBlack,
    "maroon":               ColorMaroon,
    "green":                ColorGreen,
    "olive":                ColorOlive,
    "navy":                 ColorNavy,
    "purple":               ColorPurple,
    "teal":                 ColorTeal,
    "silver":               ColorSilver,
    "gray":                 ColorGray,
    "red":                  ColorRed,
    "lime":                 ColorLime,
    "yellow":               ColorYellow,
    "blue":                 ColorBlue,
    "fuchsia":              ColorFuchsia,
    "aqua":                 ColorAqua,
    "white":                ColorWhite,
    "aliceblue":            ColorAliceBlue,
    "antiquewhite":         ColorAntiqueWhite,
    "aquamarine":           ColorAquaMarine,
    "azure":                ColorAzure,
    "beige":                ColorBeige,
    "bisque":               ColorBisque,
    "blanchedalmond":       ColorBlanchedAlmond,
    "blueviolet":           ColorBlueViolet,
    "brown":                ColorBrown,
    "burlywood":            ColorBurlyWood,
    "cadetblue":            ColorCadetBlue,
    "chartreuse":           ColorChartreuse,
    "chocolate":            ColorChocolate,
    "coral":                ColorCoral,
    "cornflowerblue":       ColorCornflowerBlue,
    "cornsilk":             ColorCornsilk,
    "crimson":              ColorCrimson,
    "darkblue":             ColorDarkBlue,
    "darkcyan":             ColorDarkCyan,
    "darkgoldenrod":        ColorDarkGoldenrod,
    "darkgray":             ColorDarkGray,
    "darkgreen":            ColorDarkGreen,
    "darkkhaki":            ColorDarkKhaki,
    "darkmagenta":          ColorDarkMagenta,
    "darkolivegreen":       ColorDarkOliveGreen,
    "darkorange":           ColorDarkOrange,
    "darkorchid":           ColorDarkOrchid,
    "darkred":              ColorDarkRed,
    "darksalmon":           ColorDarkSalmon,
    "darkseagreen":         ColorDarkSeaGreen,
    "darkslateblue":        ColorDarkSlateBlue,
    "darkslategray":        ColorDarkSlateGray,
    "darkturquoise":        ColorDarkTurquoise,
    "darkviolet":           ColorDarkViolet,
    "deeppink":             ColorDeepPink,
    "deepskyblue":          ColorDeepSkyBlue,
    "dimgray":              ColorDimGray,
    "dodgerblue":           ColorDodgerBlue,
    "firebrick":            ColorFireBrick,
    "floralwhite":          ColorFloralWhite,
    "forestgreen":          ColorForestGreen,
    "gainsboro":            ColorGainsboro,
    "ghostwhite":           ColorGhostWhite,
    "gold":                 ColorGold,
    "goldenrod":            ColorGoldenrod,
    "greenyellow":          ColorGreenYellow,
    "honeydew":             ColorHoneydew,
    "hotpink":              ColorHotPink,
    "indianred":            ColorIndianRed,
    "indigo":               ColorIndigo,
    "ivory":                ColorIvory,
    "khaki":                ColorKhaki,
    "lavender":             ColorLavender,
    "lavenderblush":        ColorLavenderBlush,
    "lawngreen":            ColorLawnGreen,
    "lemonchiffon":         ColorLemonChiffon,
    "lightblue":            ColorLightBlue,
    "lightcoral":           ColorLightCoral,
    "lightcyan":            ColorLightCyan,
    "lightgoldenrodyellow": ColorLightGoldenrodYellow,
    "lightgray":            ColorLightGray,
    "lightgreen":           ColorLightGreen,
    "lightpink":            ColorLightPink,
    "lightsalmon":          ColorLightSalmon,
    "lightseagreen":        ColorLightSeaGreen,
    "lightskyblue":         ColorLightSkyBlue,
    "lightslategray":       ColorLightSlateGray,
    "lightsteelblue":       ColorLightSteelBlue,
    "lightyellow":          ColorLightYellow,
    "limegreen":            ColorLimeGreen,
    "linen":                ColorLinen,
    "mediumaquamarine":     ColorMediumAquamarine,
    "mediumblue":           ColorMediumBlue,
    "mediumorchid":         ColorMediumOrchid,
    "mediumpurple":         ColorMediumPurple,
    "mediumseagreen":       ColorMediumSeaGreen,
    "mediumslateblue":      ColorMediumSlateBlue,
    "mediumspringgreen":    ColorMediumSpringGreen,
    "mediumturquoise":      ColorMediumTurquoise,
    "mediumvioletred":      ColorMediumVioletRed,
    "midnightblue":         ColorMidnightBlue,
    "mintcream":            ColorMintCream,
    "mistyrose":            ColorMistyRose,
    "moccasin":             ColorMoccasin,
    "navajowhite":          ColorNavajoWhite,
    "oldlace":              ColorOldLace,
    "olivedrab":            ColorOliveDrab,
    "orange":               ColorOrange,
    "orangered":            ColorOrangeRed,
    "orchid":               ColorOrchid,
    "palegoldenrod":        ColorPaleGoldenrod,
    "palegreen":            ColorPaleGreen,
    "paleturquoise":        ColorPaleTurquoise,
    "palevioletred":        ColorPaleVioletRed,
    "papayawhip":           ColorPapayaWhip,
    "peachpuff":            ColorPeachPuff,
    "peru":                 ColorPeru,
    "pink":                 ColorPink,
    "plum":                 ColorPlum,
    "powderblue":           ColorPowderBlue,
    "rebeccapurple":        ColorRebeccaPurple,
    "rosybrown":            ColorRosyBrown,
    "royalblue":            ColorRoyalBlue,
    "saddlebrown":          ColorSaddleBrown,
    "salmon":               ColorSalmon,
    "sandybrown":           ColorSandyBrown,
    "seagreen":             ColorSeaGreen,
    "seashell":             ColorSeashell,
    "sienna":               ColorSienna,
    "skyblue":              ColorSkyblue,
    "slateblue":            ColorSlateBlue,
    "slategray":            ColorSlateGray,
    "snow":                 ColorSnow,
    "springgreen":          ColorSpringGreen,
    "steelblue":            ColorSteelBlue,
    "tan":                  ColorTan,
    "thistle":              ColorThistle,
    "tomato":               ColorTomato,
    "turquoise":            ColorTurquoise,
    "violet":               ColorViolet,
    "wheat":                ColorWheat,
    "whitesmoke":           ColorWhiteSmoke,
    "yellowgreen":          ColorYellowGreen,
    "grey":                 ColorGray,
    "dimgrey":              ColorDimGray,
    "darkgrey":             ColorDarkGray,
    "darkslategrey":        ColorDarkSlateGray,
    "lightgrey":            ColorLightGray,
    "lightslategrey":       ColorLightSlateGray,
    "slategrey":            ColorSlateGray,
}

ColorValues maps color constants to their RGB values.

var ColorValues = map[Color]int32{
    ColorBlack:                0x000000,
    ColorMaroon:               0x800000,
    ColorGreen:                0x008000,
    ColorOlive:                0x808000,
    ColorNavy:                 0x000080,
    ColorPurple:               0x800080,
    ColorTeal:                 0x008080,
    ColorSilver:               0xC0C0C0,
    ColorGray:                 0x808080,
    ColorRed:                  0xFF0000,
    ColorLime:                 0x00FF00,
    ColorYellow:               0xFFFF00,
    ColorBlue:                 0x0000FF,
    ColorFuchsia:              0xFF00FF,
    ColorAqua:                 0x00FFFF,
    ColorWhite:                0xFFFFFF,
    Color16:                   0x000000,
    Color17:                   0x00005F,
    Color18:                   0x000087,
    Color19:                   0x0000AF,
    Color20:                   0x0000D7,
    Color21:                   0x0000FF,
    Color22:                   0x005F00,
    Color23:                   0x005F5F,
    Color24:                   0x005F87,
    Color25:                   0x005FAF,
    Color26:                   0x005FD7,
    Color27:                   0x005FFF,
    Color28:                   0x008700,
    Color29:                   0x00875F,
    Color30:                   0x008787,
    Color31:                   0x0087Af,
    Color32:                   0x0087D7,
    Color33:                   0x0087FF,
    Color34:                   0x00AF00,
    Color35:                   0x00AF5F,
    Color36:                   0x00AF87,
    Color37:                   0x00AFAF,
    Color38:                   0x00AFD7,
    Color39:                   0x00AFFF,
    Color40:                   0x00D700,
    Color41:                   0x00D75F,
    Color42:                   0x00D787,
    Color43:                   0x00D7AF,
    Color44:                   0x00D7D7,
    Color45:                   0x00D7FF,
    Color46:                   0x00FF00,
    Color47:                   0x00FF5F,
    Color48:                   0x00FF87,
    Color49:                   0x00FFAF,
    Color50:                   0x00FFd7,
    Color51:                   0x00FFFF,
    Color52:                   0x5F0000,
    Color53:                   0x5F005F,
    Color54:                   0x5F0087,
    Color55:                   0x5F00AF,
    Color56:                   0x5F00D7,
    Color57:                   0x5F00FF,
    Color58:                   0x5F5F00,
    Color59:                   0x5F5F5F,
    Color60:                   0x5F5F87,
    Color61:                   0x5F5FAF,
    Color62:                   0x5F5FD7,
    Color63:                   0x5F5FFF,
    Color64:                   0x5F8700,
    Color65:                   0x5F875F,
    Color66:                   0x5F8787,
    Color67:                   0x5F87AF,
    Color68:                   0x5F87D7,
    Color69:                   0x5F87FF,
    Color70:                   0x5FAF00,
    Color71:                   0x5FAF5F,
    Color72:                   0x5FAF87,
    Color73:                   0x5FAFAF,
    Color74:                   0x5FAFD7,
    Color75:                   0x5FAFFF,
    Color76:                   0x5FD700,
    Color77:                   0x5FD75F,
    Color78:                   0x5FD787,
    Color79:                   0x5FD7AF,
    Color80:                   0x5FD7D7,
    Color81:                   0x5FD7FF,
    Color82:                   0x5FFF00,
    Color83:                   0x5FFF5F,
    Color84:                   0x5FFF87,
    Color85:                   0x5FFFAF,
    Color86:                   0x5FFFD7,
    Color87:                   0x5FFFFF,
    Color88:                   0x870000,
    Color89:                   0x87005F,
    Color90:                   0x870087,
    Color91:                   0x8700AF,
    Color92:                   0x8700D7,
    Color93:                   0x8700FF,
    Color94:                   0x875F00,
    Color95:                   0x875F5F,
    Color96:                   0x875F87,
    Color97:                   0x875FAF,
    Color98:                   0x875FD7,
    Color99:                   0x875FFF,
    Color100:                  0x878700,
    Color101:                  0x87875F,
    Color102:                  0x878787,
    Color103:                  0x8787AF,
    Color104:                  0x8787D7,
    Color105:                  0x8787FF,
    Color106:                  0x87AF00,
    Color107:                  0x87AF5F,
    Color108:                  0x87AF87,
    Color109:                  0x87AFAF,
    Color110:                  0x87AFD7,
    Color111:                  0x87AFFF,
    Color112:                  0x87D700,
    Color113:                  0x87D75F,
    Color114:                  0x87D787,
    Color115:                  0x87D7AF,
    Color116:                  0x87D7D7,
    Color117:                  0x87D7FF,
    Color118:                  0x87FF00,
    Color119:                  0x87FF5F,
    Color120:                  0x87FF87,
    Color121:                  0x87FFAF,
    Color122:                  0x87FFD7,
    Color123:                  0x87FFFF,
    Color124:                  0xAF0000,
    Color125:                  0xAF005F,
    Color126:                  0xAF0087,
    Color127:                  0xAF00AF,
    Color128:                  0xAF00D7,
    Color129:                  0xAF00FF,
    Color130:                  0xAF5F00,
    Color131:                  0xAF5F5F,
    Color132:                  0xAF5F87,
    Color133:                  0xAF5FAF,
    Color134:                  0xAF5FD7,
    Color135:                  0xAF5FFF,
    Color136:                  0xAF8700,
    Color137:                  0xAF875F,
    Color138:                  0xAF8787,
    Color139:                  0xAF87AF,
    Color140:                  0xAF87D7,
    Color141:                  0xAF87FF,
    Color142:                  0xAFAF00,
    Color143:                  0xAFAF5F,
    Color144:                  0xAFAF87,
    Color145:                  0xAFAFAF,
    Color146:                  0xAFAFD7,
    Color147:                  0xAFAFFF,
    Color148:                  0xAFD700,
    Color149:                  0xAFD75F,
    Color150:                  0xAFD787,
    Color151:                  0xAFD7AF,
    Color152:                  0xAFD7D7,
    Color153:                  0xAFD7FF,
    Color154:                  0xAFFF00,
    Color155:                  0xAFFF5F,
    Color156:                  0xAFFF87,
    Color157:                  0xAFFFAF,
    Color158:                  0xAFFFD7,
    Color159:                  0xAFFFFF,
    Color160:                  0xD70000,
    Color161:                  0xD7005F,
    Color162:                  0xD70087,
    Color163:                  0xD700AF,
    Color164:                  0xD700D7,
    Color165:                  0xD700FF,
    Color166:                  0xD75F00,
    Color167:                  0xD75F5F,
    Color168:                  0xD75F87,
    Color169:                  0xD75FAF,
    Color170:                  0xD75FD7,
    Color171:                  0xD75FFF,
    Color172:                  0xD78700,
    Color173:                  0xD7875F,
    Color174:                  0xD78787,
    Color175:                  0xD787AF,
    Color176:                  0xD787D7,
    Color177:                  0xD787FF,
    Color178:                  0xD7AF00,
    Color179:                  0xD7AF5F,
    Color180:                  0xD7AF87,
    Color181:                  0xD7AFAF,
    Color182:                  0xD7AFD7,
    Color183:                  0xD7AFFF,
    Color184:                  0xD7D700,
    Color185:                  0xD7D75F,
    Color186:                  0xD7D787,
    Color187:                  0xD7D7AF,
    Color188:                  0xD7D7D7,
    Color189:                  0xD7D7FF,
    Color190:                  0xD7FF00,
    Color191:                  0xD7FF5F,
    Color192:                  0xD7FF87,
    Color193:                  0xD7FFAF,
    Color194:                  0xD7FFD7,
    Color195:                  0xD7FFFF,
    Color196:                  0xFF0000,
    Color197:                  0xFF005F,
    Color198:                  0xFF0087,
    Color199:                  0xFF00AF,
    Color200:                  0xFF00D7,
    Color201:                  0xFF00FF,
    Color202:                  0xFF5F00,
    Color203:                  0xFF5F5F,
    Color204:                  0xFF5F87,
    Color205:                  0xFF5FAF,
    Color206:                  0xFF5FD7,
    Color207:                  0xFF5FFF,
    Color208:                  0xFF8700,
    Color209:                  0xFF875F,
    Color210:                  0xFF8787,
    Color211:                  0xFF87AF,
    Color212:                  0xFF87D7,
    Color213:                  0xFF87FF,
    Color214:                  0xFFAF00,
    Color215:                  0xFFAF5F,
    Color216:                  0xFFAF87,
    Color217:                  0xFFAFAF,
    Color218:                  0xFFAFD7,
    Color219:                  0xFFAFFF,
    Color220:                  0xFFD700,
    Color221:                  0xFFD75F,
    Color222:                  0xFFD787,
    Color223:                  0xFFD7AF,
    Color224:                  0xFFD7D7,
    Color225:                  0xFFD7FF,
    Color226:                  0xFFFF00,
    Color227:                  0xFFFF5F,
    Color228:                  0xFFFF87,
    Color229:                  0xFFFFAF,
    Color230:                  0xFFFFD7,
    Color231:                  0xFFFFFF,
    Color232:                  0x080808,
    Color233:                  0x121212,
    Color234:                  0x1C1C1C,
    Color235:                  0x262626,
    Color236:                  0x303030,
    Color237:                  0x3A3A3A,
    Color238:                  0x444444,
    Color239:                  0x4E4E4E,
    Color240:                  0x585858,
    Color241:                  0x626262,
    Color242:                  0x6C6C6C,
    Color243:                  0x767676,
    Color244:                  0x808080,
    Color245:                  0x8A8A8A,
    Color246:                  0x949494,
    Color247:                  0x9E9E9E,
    Color248:                  0xA8A8A8,
    Color249:                  0xB2B2B2,
    Color250:                  0xBCBCBC,
    Color251:                  0xC6C6C6,
    Color252:                  0xD0D0D0,
    Color253:                  0xDADADA,
    Color254:                  0xE4E4E4,
    Color255:                  0xEEEEEE,
    ColorAliceBlue:            0xF0F8FF,
    ColorAntiqueWhite:         0xFAEBD7,
    ColorAquaMarine:           0x7FFFD4,
    ColorAzure:                0xF0FFFF,
    ColorBeige:                0xF5F5DC,
    ColorBisque:               0xFFE4C4,
    ColorBlanchedAlmond:       0xFFEBCD,
    ColorBlueViolet:           0x8A2BE2,
    ColorBrown:                0xA52A2A,
    ColorBurlyWood:            0xDEB887,
    ColorCadetBlue:            0x5F9EA0,
    ColorChartreuse:           0x7FFF00,
    ColorChocolate:            0xD2691E,
    ColorCoral:                0xFF7F50,
    ColorCornflowerBlue:       0x6495ED,
    ColorCornsilk:             0xFFF8DC,
    ColorCrimson:              0xDC143C,
    ColorDarkBlue:             0x00008B,
    ColorDarkCyan:             0x008B8B,
    ColorDarkGoldenrod:        0xB8860B,
    ColorDarkGray:             0xA9A9A9,
    ColorDarkGreen:            0x006400,
    ColorDarkKhaki:            0xBDB76B,
    ColorDarkMagenta:          0x8B008B,
    ColorDarkOliveGreen:       0x556B2F,
    ColorDarkOrange:           0xFF8C00,
    ColorDarkOrchid:           0x9932CC,
    ColorDarkRed:              0x8B0000,
    ColorDarkSalmon:           0xE9967A,
    ColorDarkSeaGreen:         0x8FBC8F,
    ColorDarkSlateBlue:        0x483D8B,
    ColorDarkSlateGray:        0x2F4F4F,
    ColorDarkTurquoise:        0x00CED1,
    ColorDarkViolet:           0x9400D3,
    ColorDeepPink:             0xFF1493,
    ColorDeepSkyBlue:          0x00BFFF,
    ColorDimGray:              0x696969,
    ColorDodgerBlue:           0x1E90FF,
    ColorFireBrick:            0xB22222,
    ColorFloralWhite:          0xFFFAF0,
    ColorForestGreen:          0x228B22,
    ColorGainsboro:            0xDCDCDC,
    ColorGhostWhite:           0xF8F8FF,
    ColorGold:                 0xFFD700,
    ColorGoldenrod:            0xDAA520,
    ColorGreenYellow:          0xADFF2F,
    ColorHoneydew:             0xF0FFF0,
    ColorHotPink:              0xFF69B4,
    ColorIndianRed:            0xCD5C5C,
    ColorIndigo:               0x4B0082,
    ColorIvory:                0xFFFFF0,
    ColorKhaki:                0xF0E68C,
    ColorLavender:             0xE6E6FA,
    ColorLavenderBlush:        0xFFF0F5,
    ColorLawnGreen:            0x7CFC00,
    ColorLemonChiffon:         0xFFFACD,
    ColorLightBlue:            0xADD8E6,
    ColorLightCoral:           0xF08080,
    ColorLightCyan:            0xE0FFFF,
    ColorLightGoldenrodYellow: 0xFAFAD2,
    ColorLightGray:            0xD3D3D3,
    ColorLightGreen:           0x90EE90,
    ColorLightPink:            0xFFB6C1,
    ColorLightSalmon:          0xFFA07A,
    ColorLightSeaGreen:        0x20B2AA,
    ColorLightSkyBlue:         0x87CEFA,
    ColorLightSlateGray:       0x778899,
    ColorLightSteelBlue:       0xB0C4DE,
    ColorLightYellow:          0xFFFFE0,
    ColorLimeGreen:            0x32CD32,
    ColorLinen:                0xFAF0E6,
    ColorMediumAquamarine:     0x66CDAA,
    ColorMediumBlue:           0x0000CD,
    ColorMediumOrchid:         0xBA55D3,
    ColorMediumPurple:         0x9370DB,
    ColorMediumSeaGreen:       0x3CB371,
    ColorMediumSlateBlue:      0x7B68EE,
    ColorMediumSpringGreen:    0x00FA9A,
    ColorMediumTurquoise:      0x48D1CC,
    ColorMediumVioletRed:      0xC71585,
    ColorMidnightBlue:         0x191970,
    ColorMintCream:            0xF5FFFA,
    ColorMistyRose:            0xFFE4E1,
    ColorMoccasin:             0xFFE4B5,
    ColorNavajoWhite:          0xFFDEAD,
    ColorOldLace:              0xFDF5E6,
    ColorOliveDrab:            0x6B8E23,
    ColorOrange:               0xFFA500,
    ColorOrangeRed:            0xFF4500,
    ColorOrchid:               0xDA70D6,
    ColorPaleGoldenrod:        0xEEE8AA,
    ColorPaleGreen:            0x98FB98,
    ColorPaleTurquoise:        0xAFEEEE,
    ColorPaleVioletRed:        0xDB7093,
    ColorPapayaWhip:           0xFFEFD5,
    ColorPeachPuff:            0xFFDAB9,
    ColorPeru:                 0xCD853F,
    ColorPink:                 0xFFC0CB,
    ColorPlum:                 0xDDA0DD,
    ColorPowderBlue:           0xB0E0E6,
    ColorRebeccaPurple:        0x663399,
    ColorRosyBrown:            0xBC8F8F,
    ColorRoyalBlue:            0x4169E1,
    ColorSaddleBrown:          0x8B4513,
    ColorSalmon:               0xFA8072,
    ColorSandyBrown:           0xF4A460,
    ColorSeaGreen:             0x2E8B57,
    ColorSeashell:             0xFFF5EE,
    ColorSienna:               0xA0522D,
    ColorSkyblue:              0x87CEEB,
    ColorSlateBlue:            0x6A5ACD,
    ColorSlateGray:            0x708090,
    ColorSnow:                 0xFFFAFA,
    ColorSpringGreen:          0x00FF7F,
    ColorSteelBlue:            0x4682B4,
    ColorTan:                  0xD2B48C,
    ColorThistle:              0xD8BFD8,
    ColorTomato:               0xFF6347,
    ColorTurquoise:            0x40E0D0,
    ColorViolet:               0xEE82EE,
    ColorWheat:                0xF5DEB3,
    ColorWhiteSmoke:           0xF5F5F5,
    ColorYellowGreen:          0x9ACD32,
}

KeyNames holds the written names of special keys. Useful to echo back a key name, or to look up a key from a string value.

var KeyNames = map[Key]string{
    KeyEnter:          "Enter",
    KeyBackspace:      "Backspace",
    KeyTab:            "Tab",
    KeyBacktab:        "Backtab",
    KeyEsc:            "Esc",
    KeyBackspace2:     "Backspace2",
    KeyDelete:         "Delete",
    KeyInsert:         "Insert",
    KeyUp:             "Up",
    KeyDown:           "Down",
    KeyLeft:           "Left",
    KeyRight:          "Right",
    KeyHome:           "Home",
    KeyEnd:            "End",
    KeyUpLeft:         "UpLeft",
    KeyUpRight:        "UpRight",
    KeyDownLeft:       "DownLeft",
    KeyDownRight:      "DownRight",
    KeyCenter:         "Center",
    KeyPgDn:           "PgDn",
    KeyPgUp:           "PgUp",
    KeyClear:          "Clear",
    KeyExit:           "Exit",
    KeyCancel:         "Cancel",
    KeyPause:          "Pause",
    KeyPrint:          "Print",
    KeyF1:             "F1",
    KeyF2:             "F2",
    KeyF3:             "F3",
    KeyF4:             "F4",
    KeyF5:             "F5",
    KeyF6:             "F6",
    KeyF7:             "F7",
    KeyF8:             "F8",
    KeyF9:             "F9",
    KeyF10:            "F10",
    KeyF11:            "F11",
    KeyF12:            "F12",
    KeyF13:            "F13",
    KeyF14:            "F14",
    KeyF15:            "F15",
    KeyF16:            "F16",
    KeyF17:            "F17",
    KeyF18:            "F18",
    KeyF19:            "F19",
    KeyF20:            "F20",
    KeyF21:            "F21",
    KeyF22:            "F22",
    KeyF23:            "F23",
    KeyF24:            "F24",
    KeyF25:            "F25",
    KeyF26:            "F26",
    KeyF27:            "F27",
    KeyF28:            "F28",
    KeyF29:            "F29",
    KeyF30:            "F30",
    KeyF31:            "F31",
    KeyF32:            "F32",
    KeyF33:            "F33",
    KeyF34:            "F34",
    KeyF35:            "F35",
    KeyF36:            "F36",
    KeyF37:            "F37",
    KeyF38:            "F38",
    KeyF39:            "F39",
    KeyF40:            "F40",
    KeyF41:            "F41",
    KeyF42:            "F42",
    KeyF43:            "F43",
    KeyF44:            "F44",
    KeyF45:            "F45",
    KeyF46:            "F46",
    KeyF47:            "F47",
    KeyF48:            "F48",
    KeyF49:            "F49",
    KeyF50:            "F50",
    KeyF51:            "F51",
    KeyF52:            "F52",
    KeyF53:            "F53",
    KeyF54:            "F54",
    KeyF55:            "F55",
    KeyF56:            "F56",
    KeyF57:            "F57",
    KeyF58:            "F58",
    KeyF59:            "F59",
    KeyF60:            "F60",
    KeyF61:            "F61",
    KeyF62:            "F62",
    KeyF63:            "F63",
    KeyF64:            "F64",
    KeyCtrlA:          "Ctrl-A",
    KeyCtrlB:          "Ctrl-B",
    KeyCtrlC:          "Ctrl-C",
    KeyCtrlD:          "Ctrl-D",
    KeyCtrlE:          "Ctrl-E",
    KeyCtrlF:          "Ctrl-F",
    KeyCtrlG:          "Ctrl-G",
    KeyCtrlJ:          "Ctrl-J",
    KeyCtrlK:          "Ctrl-K",
    KeyCtrlL:          "Ctrl-L",
    KeyCtrlN:          "Ctrl-N",
    KeyCtrlO:          "Ctrl-O",
    KeyCtrlP:          "Ctrl-P",
    KeyCtrlQ:          "Ctrl-Q",
    KeyCtrlR:          "Ctrl-R",
    KeyCtrlS:          "Ctrl-S",
    KeyCtrlT:          "Ctrl-T",
    KeyCtrlU:          "Ctrl-U",
    KeyCtrlV:          "Ctrl-V",
    KeyCtrlW:          "Ctrl-W",
    KeyCtrlX:          "Ctrl-X",
    KeyCtrlY:          "Ctrl-Y",
    KeyCtrlZ:          "Ctrl-Z",
    KeyCtrlSpace:      "Ctrl-Space",
    KeyCtrlUnderscore: "Ctrl-_",
    KeyCtrlRightSq:    "Ctrl-]",
    KeyCtrlBackslash:  "Ctrl-\\",
    KeyCtrlCarat:      "Ctrl-^",
}

RuneFallbacks is the default map of fallback strings that will be used to replace a rune when no other more appropriate transformation is available, and the rune cannot be displayed directly.

New entries may be added to this map over time, as it becomes clear that such is desirable. Characters that represent either letters or numbers should not be added to this list unless it is certain that the meaning will still convey unambiguously.

As an example, it would be appropriate to add an ASCII mapping for the full width form of the letter 'A', but it would not be appropriate to do so a glyph representing the country China.

Programs that desire richer fallbacks may register additional ones, or change or even remove these mappings with Screen.RegisterRuneFallback Screen.UnregisterRuneFallback methods.

Note that Unicode is presumed to be able to display all glyphs. This is a pretty poor assumption, but there is no easy way to figure out which glyphs are supported in a given font. Hence, some care in selecting the characters you support in your application is still appropriate.

var RuneFallbacks = map[rune]string{
    RuneSterling: "f",
    RuneDArrow:   "v",
    RuneLArrow:   "<",
    RuneRArrow:   ">",
    RuneUArrow:   "^",
    RuneBullet:   "o",
    RuneBoard:    "#",
    RuneCkBoard:  ":",
    RuneDegree:   "\\",
    RuneDiamond:  "+",
    RuneGEqual:   ">",
    RunePi:       "*",
    RuneHLine:    "-",
    RuneLantern:  "#",
    RunePlus:     "+",
    RuneLEqual:   "<",
    RuneLLCorner: "+",
    RuneLRCorner: "+",
    RuneNEqual:   "!",
    RunePlMinus:  "#",
    RuneS1:       "~",
    RuneS3:       "-",
    RuneS7:       "-",
    RuneS9:       "_",
    RuneBlock:    "#",
    RuneTTee:     "+",
    RuneRTee:     "+",
    RuneLTee:     "+",
    RuneBTee:     "+",
    RuneULCorner: "+",
    RuneURCorner: "+",
    RuneVLine:    "|",
}

func GetEncoding

func GetEncoding(charset string) encoding.Encoding

GetEncoding is used by Screen implementors who want to locate an encoding for the given character set name. Note that this will return nil for either the Unicode (UTF-8) or ASCII encodings, since we don't use encodings for them but instead have our own native methods.

func LookupTerminfo

func LookupTerminfo(name string) (ti *terminfo.Terminfo, e error)

LookupTerminfo attempts to find a definition for the named $TERM falling back to attempting to parse the output from infocmp.

func RegisterEncoding

func RegisterEncoding(charset string, enc encoding.Encoding)

The East Asian encodings have been seen to add 100-200K per encoding to the size of the resulting binary.

Example

Code:

RegisterEncoding("GBK", simplifiedchinese.GBK)
enc := GetEncoding("GBK")
glyph, _ := enc.NewDecoder().Bytes([]byte{0x82, 0x74})
fmt.Println(string(glyph))

Output:

倀

func SetEncodingFallback

func SetEncodingFallback(fb EncodingFallback)

SetEncodingFallback changes the behavior of GetEncoding when a suitable encoding is not found. The default is EncodingFallbackFail, which causes GetEncoding to simply return nil.

type AttrMask

AttrMask represents a mask of text attributes, apart from color. Note that support for attributes may vary widely across terminals.

type AttrMask int

Attributes are not colors, but affect the display of text. They can be combined.

const (
    AttrBold AttrMask = 1 << iota
    AttrBlink
    AttrReverse
    AttrUnderline
    AttrDim
    AttrItalic
    AttrStrikeThrough
    AttrInvalid              // Mark the style or attributes invalid
    AttrNone    AttrMask = 0 // Just normal text.
)

type ButtonMask

ButtonMask is a mask of mouse buttons and wheel events. Mouse button presses are normally delivered as both press and release events. Mouse wheel events are normally just single impulse events. Windows supports up to eight separate buttons plus all four wheel directions, but XTerm can only support mouse buttons 1-3 and wheel up/down. Its not unheard of for terminals to support only one or two buttons (think Macs). Old terminals, and true emulations (such as vt100) won't support mice at all, of course.

type ButtonMask int16

These are the actual button values. Note that tcell version 1.x reversed buttons two and three on *nix based terminals. We use button 1 as the primary, and button 2 as the secondary, and button 3 (which is often missing) as the middle.

const (
    Button1 ButtonMask = 1 << iota // Usually the left (primary) mouse button.
    Button2                        // Usually the right (secondary) mouse button.
    Button3                        // Usually the middle mouse button.
    Button4                        // Often a side button (thumb/next).
    Button5                        // Often a side button (thumb/prev).
    Button6
    Button7
    Button8
    WheelUp                   // Wheel motion up/away from user.
    WheelDown                 // Wheel motion down/towards user.
    WheelLeft                 // Wheel motion to left.
    WheelRight                // Wheel motion to right.
    ButtonNone ButtonMask = 0 // No button or wheel events.

    ButtonPrimary   = Button1
    ButtonSecondary = Button2
    ButtonMiddle    = Button3
)

type CellBuffer

CellBuffer represents a two dimensional array of character cells. This is primarily intended for use by Screen implementors; it contains much of the common code they need. To create one, just declare a variable of its type; no explicit initialization is necessary.

CellBuffer is not thread safe.

type CellBuffer struct {
    // contains filtered or unexported fields
}

func (*CellBuffer) Dirty

func (cb *CellBuffer) Dirty(x, y int) bool

Dirty checks if a character at the given location needs an to be refreshed on the physical display. This returns true if the cell content is different since the last time it was marked clean.

func (*CellBuffer) Fill

func (cb *CellBuffer) Fill(r rune, style Style)

Fill fills the entire cell buffer array with the specified character and style. Normally choose ' ' to clear the screen. This API doesn't support combining characters, or characters with a width larger than one.

func (*CellBuffer) GetContent

func (cb *CellBuffer) GetContent(x, y int) (rune, []rune, Style, int)

GetContent returns the contents of a character cell, including the primary rune, any combining character runes (which will usually be nil), the style, and the display width in cells. (The width can be either 1, normally, or 2 for East Asian full-width characters.)

func (*CellBuffer) Invalidate

func (cb *CellBuffer) Invalidate()

Invalidate marks all characters within the buffer as dirty.

func (*CellBuffer) Resize

func (cb *CellBuffer) Resize(w, h int)

Resize is used to resize the cells array, with different dimensions, while preserving the original contents. The cells will be invalidated so that they can be redrawn.

func (*CellBuffer) SetContent

func (cb *CellBuffer) SetContent(x int, y int,
    mainc rune, combc []rune, style Style)

SetContent sets the contents (primary rune, combining runes, and style) for a cell at a given location.

func (*CellBuffer) SetDirty

func (cb *CellBuffer) SetDirty(x, y int, dirty bool)

SetDirty is normally used to indicate that a cell has been displayed (in which case dirty is false), or to manually force a cell to be marked dirty.

func (*CellBuffer) Size

func (cb *CellBuffer) Size() (int, int)

Size returns the (width, height) in cells of the buffer.

type Color

Color represents a color. The low numeric values are the same as used by ECMA-48, and beyond that XTerm. A 24-bit RGB value may be used by adding in the ColorIsRGB flag. For Color names we use the W3C approved color names.

We use a 64-bit integer to allow future expansion if we want to add an 8-bit alpha, while still leaving us some room for extra options.

Note that on various terminals colors may be approximated however, or not supported at all. If no suitable representation for a color is known, the library will simply not set any color, deferring to whatever default attributes the terminal uses.

type Color uint64
const (
    // ColorDefault is used to leave the Color unchanged from whatever
    // system or terminal default may exist.  It's also the zero value.
    ColorDefault Color = 0

    // ColorValid is used to indicate the color value is actually
    // valid (initialized).  This is useful to permit the zero value
    // to be treated as the default.
    ColorValid Color = 1 << 32

    // ColorIsRGB is used to indicate that the numeric value is not
    // a known color constant, but rather an RGB value.  The lower
    // order 3 bytes are RGB.
    ColorIsRGB Color = 1 << 33

    // ColorSpecial is a flag used to indicate that the values have
    // special meaning, and live outside of the color space(s).
    ColorSpecial Color = 1 << 34
)

func FindColor

func FindColor(c Color, palette []Color) Color

FindColor attempts to find a given color, or the best match possible for it, from the palette given. This is an expensive operation, so results should be cached by the caller.

func FromImageColor

func FromImageColor(imageColor ic.Color) Color

FromImageColor converts an image/color.Color into tcell.Color. The alpha value is dropped, so it should be tracked separately if it is needed.

func GetColor

func GetColor(name string) Color

GetColor creates a Color from a color name (W3C name). A hex value may be supplied as a string in the format "#ffffff".

func NewHexColor

func NewHexColor(v int32) Color

NewHexColor returns a color using the given 24-bit RGB value.

func NewRGBColor

func NewRGBColor(r, g, b int32) Color

NewRGBColor returns a new color with the given red, green, and blue values. Each value must be represented in the range 0-255.

func PaletteColor

func PaletteColor(index int) Color

PaletteColor creates a color based on the palette index.

func (Color) Hex

func (c Color) Hex() int32

Hex returns the color's hexadecimal RGB 24-bit value with each component consisting of a single byte, R << 16 | G << 8 | B. If the color is unknown or unset, -1 is returned.

func (Color) IsRGB

func (c Color) IsRGB() bool

IsRGB is true if the color is an RGB specific value.

func (Color) RGB

func (c Color) RGB() (int32, int32, int32)

RGB returns the red, green, and blue components of the color, with each component represented as a value 0-255. In the event that the color cannot be broken up (not set usually), -1 is returned for each value.

func (Color) TrueColor

func (c Color) TrueColor() Color

TrueColor returns the true color (RGB) version of the provided color. This is useful for ensuring color accuracy when using named colors. This will override terminal theme colors.

func (Color) Valid

func (c Color) Valid() bool

Valid indicates the color is a valid value (has been set).

type CursorStyle

CursorStyle represents a given cursor style, which can include the shape and whether the cursor blinks or is solid. Support for changing this is not universal.

type CursorStyle int

type EncodingFallback

EncodingFallback describes how the system behaves when the locale requires a character set that we do not support. The system always supports UTF-8 and US-ASCII. On Windows consoles, UTF-16LE is also supported automatically. Other character sets must be added using the RegisterEncoding API. (A large group of nearly all of them can be added using the RegisterAll function in the encoding sub package.)

type EncodingFallback int

type Event

Event is a generic interface used for passing around Events. Concrete types follow.

type Event interface {
    // When reports the time when the event was generated.
    When() time.Time
}

type EventError

An EventError is an event representing some sort of error, and carries an error payload.

type EventError struct {
    // contains filtered or unexported fields
}

func NewEventError

func NewEventError(err error) *EventError

NewEventError creates an ErrorEvent with the given error payload.

func (*EventError) Error

func (ev *EventError) Error() string

Error implements the error.

func (*EventError) When

func (ev *EventError) When() time.Time

When returns the time when the event was created.

type EventHandler

EventHandler is anything that handles events. If the handler has consumed the event, it should return true. False otherwise.

type EventHandler interface {
    HandleEvent(Event) bool
}

type EventInterrupt

EventInterrupt is a generic wakeup event. Its can be used to to request a redraw. It can carry an arbitrary payload, as well.

type EventInterrupt struct {
    // contains filtered or unexported fields
}

func NewEventInterrupt

func NewEventInterrupt(data interface{}) *EventInterrupt

NewEventInterrupt creates an EventInterrupt with the given payload.

func (*EventInterrupt) Data

func (ev *EventInterrupt) Data() interface{}

Data is used to obtain the opaque event payload.

func (*EventInterrupt) When

func (ev *EventInterrupt) When() time.Time

When returns the time when this event was created.

type EventKey

EventKey represents a key press. Usually this is a key press followed by a key release, but since terminal programs don't have a way to report key release events, we usually get just one event. If a key is held down then the terminal may synthesize repeated key presses at some predefined rate. We have no control over that, nor visibility into it.

In some cases, we can have a modifier key, such as ModAlt, that can be generated with a key press. (This usually is represented by having the high bit set, or in some cases, by sending an ESC prior to the rune.)

If the value of Key() is KeyRune, then the actual key value will be available with the Rune() method. This will be the case for most keys. In most situations, the modifiers will not be set. For example, if the rune is 'A', this will be reported without the ModShift bit set, since really can't tell if the Shift key was pressed (it might have been CAPSLOCK, or a terminal that only can send capitals, or keyboard with separate capital letters from lower case letters).

Generally, terminal applications have far less visibility into keyboard activity than graphical applications. Hence, they should avoid depending overly much on availability of modifiers, or the availability of any specific keys.

type EventKey struct {
    // contains filtered or unexported fields
}

func NewEventKey

func NewEventKey(k Key, ch rune, mod ModMask) *EventKey

NewEventKey attempts to create a suitable event. It parses the various ASCII control sequences if KeyRune is passed for Key, but if the caller has more precise information it should set that specifically. Callers that aren't sure about modifier state (most) should just pass ModNone.

func (*EventKey) Key

func (ev *EventKey) Key() Key

Key returns a virtual key code. We use this to identify specific key codes, such as KeyEnter, etc. Most control and function keys are reported with unique Key values. Normal alphanumeric and punctuation keys will generally return KeyRune here; the specific key can be further decoded using the Rune() function.

func (*EventKey) Modifiers

func (ev *EventKey) Modifiers() ModMask

Modifiers returns the modifiers that were present with the key press. Note that not all platforms and terminals support this equally well, and some cases we will not not know for sure. Hence, applications should avoid using this in most circumstances.

func (*EventKey) Name

func (ev *EventKey) Name() string

Name returns a printable value or the key stroke. This can be used when printing the event, for example.

func (*EventKey) Rune

func (ev *EventKey) Rune() rune

Rune returns the rune corresponding to the key press, if it makes sense. The result is only defined if the value of Key() is KeyRune.

func (*EventKey) When

func (ev *EventKey) When() time.Time

When returns the time when this Event was created, which should closely match the time when the key was pressed.

type EventMouse

EventMouse is a mouse event. It is sent on either mouse up or mouse down events. It is also sent on mouse motion events - if the terminal supports it. We make every effort to ensure that mouse release events are delivered. Hence, click drag can be identified by a motion event with the mouse down, without any intervening button release. On some terminals only the initiating press and terminating release event will be delivered.

Mouse wheel events, when reported, may appear on their own as individual impulses; that is, there will normally not be a release event delivered for mouse wheel movements.

Most terminals cannot report the state of more than one button at a time -- and some cannot report motion events unless a button is pressed.

Applications can inspect the time between events to resolve double or triple clicks.

type EventMouse struct {
    // contains filtered or unexported fields
}

func NewEventMouse

func NewEventMouse(x, y int, btn ButtonMask, mod ModMask) *EventMouse

NewEventMouse is used to create a new mouse event. Applications shouldn't need to use this; its mostly for screen implementors.

func (*EventMouse) Buttons

func (ev *EventMouse) Buttons() ButtonMask

Buttons returns the list of buttons that were pressed or wheel motions.

func (*EventMouse) Modifiers

func (ev *EventMouse) Modifiers() ModMask

Modifiers returns a list of keyboard modifiers that were pressed with the mouse button(s).

func (*EventMouse) Position

func (ev *EventMouse) Position() (int, int)

Position returns the mouse position in character cells. The origin 0, 0 is at the upper left corner.

func (*EventMouse) When

func (ev *EventMouse) When() time.Time

When returns the time when this EventMouse was created.

type EventPaste

EventPaste is used to mark the start and end of a bracketed paste. An event with .Start() true will be sent to mark the start. Then a number of keys will be sent to indicate that the content is pasted in. At the end, an event with .Start() false will be sent.

type EventPaste struct {
    // contains filtered or unexported fields
}

func NewEventPaste

func NewEventPaste(start bool) *EventPaste

NewEventPaste returns a new EventPaste.

func (*EventPaste) End

func (ev *EventPaste) End() bool

End returns true if this is the end of a paste.

func (*EventPaste) Start

func (ev *EventPaste) Start() bool

Start returns true if this is the start of a paste.

func (*EventPaste) When

func (ev *EventPaste) When() time.Time

When returns the time when this EventPaste was created.

type EventResize

EventResize is sent when the window size changes.

type EventResize struct {
    // contains filtered or unexported fields
}

func NewEventResize

func NewEventResize(width, height int) *EventResize

NewEventResize creates an EventResize with the new updated window size, which is given in character cells.

func (*EventResize) Size

func (ev *EventResize) Size() (int, int)

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

func (*EventResize) When

func (ev *EventResize) When() time.Time

When returns the time when the Event was created.

type EventTime

EventTime is a simple base event class, suitable for easy reuse. It can be used to deliver actual timer events as well.

type EventTime struct {
    // contains filtered or unexported fields
}

func (*EventTime) SetEventNow

func (e *EventTime) SetEventNow()

SetEventNow sets the time of occurrence for the event to the current time.

func (*EventTime) SetEventTime

func (e *EventTime) SetEventTime(t time.Time)

SetEventTime sets the time of occurrence for the event.

func (*EventTime) When

func (e *EventTime) When() time.Time

When returns the time stamp when the event occurred.

type Key

Key is a generic value for representing keys, and especially special keys (function keys, cursor movement keys, etc.) For normal keys, like ASCII letters, we use KeyRune, and then expect the application to inspect the Rune() member of the EventKey.

type Key int16

This is the list of named keys. KeyRune is special however, in that it is a place holder key indicating that a printable character was sent. The actual value of the rune will be transported in the Rune of the associated EventKey.

const (
    KeyRune Key = iota + 256
    KeyUp
    KeyDown
    KeyRight
    KeyLeft
    KeyUpLeft
    KeyUpRight
    KeyDownLeft
    KeyDownRight
    KeyCenter
    KeyPgUp
    KeyPgDn
    KeyHome
    KeyEnd
    KeyInsert
    KeyDelete
    KeyHelp
    KeyExit
    KeyClear
    KeyCancel
    KeyPrint
    KeyPause
    KeyBacktab
    KeyF1
    KeyF2
    KeyF3
    KeyF4
    KeyF5
    KeyF6
    KeyF7
    KeyF8
    KeyF9
    KeyF10
    KeyF11
    KeyF12
    KeyF13
    KeyF14
    KeyF15
    KeyF16
    KeyF17
    KeyF18
    KeyF19
    KeyF20
    KeyF21
    KeyF22
    KeyF23
    KeyF24
    KeyF25
    KeyF26
    KeyF27
    KeyF28
    KeyF29
    KeyF30
    KeyF31
    KeyF32
    KeyF33
    KeyF34
    KeyF35
    KeyF36
    KeyF37
    KeyF38
    KeyF39
    KeyF40
    KeyF41
    KeyF42
    KeyF43
    KeyF44
    KeyF45
    KeyF46
    KeyF47
    KeyF48
    KeyF49
    KeyF50
    KeyF51
    KeyF52
    KeyF53
    KeyF54
    KeyF55
    KeyF56
    KeyF57
    KeyF58
    KeyF59
    KeyF60
    KeyF61
    KeyF62
    KeyF63
    KeyF64
)

These are the control keys. Note that they overlap with other keys, perhaps. For example, KeyCtrlH is the same as KeyBackspace.

const (
    KeyCtrlSpace Key = iota
    KeyCtrlA
    KeyCtrlB
    KeyCtrlC
    KeyCtrlD
    KeyCtrlE
    KeyCtrlF
    KeyCtrlG
    KeyCtrlH
    KeyCtrlI
    KeyCtrlJ
    KeyCtrlK
    KeyCtrlL
    KeyCtrlM
    KeyCtrlN
    KeyCtrlO
    KeyCtrlP
    KeyCtrlQ
    KeyCtrlR
    KeyCtrlS
    KeyCtrlT
    KeyCtrlU
    KeyCtrlV
    KeyCtrlW
    KeyCtrlX
    KeyCtrlY
    KeyCtrlZ
    KeyCtrlLeftSq // Escape
    KeyCtrlBackslash
    KeyCtrlRightSq
    KeyCtrlCarat
    KeyCtrlUnderscore
)

These are the defined ASCII values for key codes. They generally match with KeyCtrl values.

const (
    KeyNUL Key = iota
    KeySOH
    KeySTX
    KeyETX
    KeyEOT
    KeyENQ
    KeyACK
    KeyBEL
    KeyBS
    KeyTAB
    KeyLF
    KeyVT
    KeyFF
    KeyCR
    KeySO
    KeySI
    KeyDLE
    KeyDC1
    KeyDC2
    KeyDC3
    KeyDC4
    KeyNAK
    KeySYN
    KeyETB
    KeyCAN
    KeyEM
    KeySUB
    KeyESC
    KeyFS
    KeyGS
    KeyRS
    KeyUS
    KeyDEL Key = 0x7F
)

type ModMask

ModMask is a mask of modifier keys. Note that it will not always be possible to report modifier keys.

type ModMask int16

These are the modifiers keys that can be sent either with a key press, or a mouse event. Note that as of now, due to the confusion associated with Meta, and the lack of support for it on many/most platforms, the current implementations never use it. Instead, they use ModAlt, even for events that could possibly have been distinguished from ModAlt.

const (
    ModShift ModMask = 1 << iota
    ModCtrl
    ModAlt
    ModMeta
    ModNone ModMask = 0
)

type MouseFlags

MouseFlags are options to modify the handling of mouse events. Actual events can be ORed together.

type MouseFlags int

type Screen

Screen represents the physical (or emulated) screen. This can be a terminal window or a physical console. Platforms implement this differently.

type Screen interface {
    // Init initializes the screen for use.
    Init() error

    // Fini finalizes the screen also releasing resources.
    Fini()

    // Clear logically erases the screen.
    // This is effectively a short-cut for Fill(' ', StyleDefault).
    Clear()

    // Fill fills the screen with the given character and style.
    // The effect of filling the screen is not visible until Show
    // is called (or Sync).
    Fill(rune, Style)

    // SetCell is an older API, and will be removed.  Please use
    // SetContent instead; SetCell is implemented in terms of SetContent.
    SetCell(x int, y int, style Style, ch ...rune)

    // GetContent returns the contents at the given location.  If the
    // coordinates are out of range, then the values will be 0, nil,
    // StyleDefault.  Note that the contents returned are logical contents
    // and may not actually be what is displayed, but rather are what will
    // be displayed if Show() or Sync() is called.  The width is the width
    // in screen cells; most often this will be 1, but some East Asian
    // characters and emoji require two cells.
    GetContent(x, y int) (primary rune, combining []rune, style Style, width int)

    // SetContent sets the contents of the given cell location.  If
    // the coordinates are out of range, then the operation is ignored.
    //
    // The first rune is the primary non-zero width rune.  The array
    // that follows is a possible list of combining characters to append,
    // and will usually be nil (no combining characters.)
    //
    // The results are not displayed until Show() or Sync() is called.
    //
    // Note that wide (East Asian full width and emoji) runes occupy two cells,
    // and attempts to place character at next cell to the right will have
    // undefined effects.  Wide runes that are printed in the
    // last column will be replaced with a single width space on output.
    SetContent(x int, y int, primary rune, combining []rune, style Style)

    // SetStyle sets the default style to use when clearing the screen
    // or when StyleDefault is specified.  If it is also StyleDefault,
    // then whatever system/terminal default is relevant will be used.
    SetStyle(style Style)

    // ShowCursor is used to display the cursor at a given location.
    // If the coordinates -1, -1 are given or are otherwise outside the
    // dimensions of the screen, the cursor will be hidden.
    ShowCursor(x int, y int)

    // HideCursor is used to hide the cursor.  It's an alias for
    // ShowCursor(-1, -1).sim
    HideCursor()

    // SetCursorStyle is used to set the cursor style.  If the style
    // is not supported (or cursor styles are not supported at all),
    // then this will have no effect.
    SetCursorStyle(CursorStyle)

    // Size returns the screen size as width, height.  This changes in
    // response to a call to Clear or Flush.
    Size() (width, height int)

    // ChannelEvents is an infinite loop that waits for an event and
    // channels it into the user provided channel ch.  Closing the
    // quit channel and calling the Fini method are cancellation
    // signals.  When a cancellation signal is received the method
    // returns after closing ch.
    //
    // This method should be used as a goroutine.
    //
    // NOTE: PollEvent should not be called while this method is running.
    ChannelEvents(ch chan<- Event, quit <-chan struct{})

    // PollEvent waits for events to arrive.  Main application loops
    // must spin on this to prevent the application from stalling.
    // Furthermore, this will return nil if the Screen is finalized.
    PollEvent() Event

    // HasPendingEvent returns true if PollEvent would return an event
    // without blocking.  If the screen is stopped and PollEvent would
    // return nil, then the return value from this function is unspecified.
    // The purpose of this function is to allow multiple events to be collected
    // at once, to minimize screen redraws.
    HasPendingEvent() bool

    // PostEvent tries to post an event into the event stream.  This
    // can fail if the event queue is full.  In that case, the event
    // is dropped, and ErrEventQFull is returned.
    PostEvent(ev Event) error

    // Deprecated: PostEventWait is unsafe, and will be removed
    // in the future.
    //
    // PostEventWait is like PostEvent, but if the queue is full, it
    // blocks until there is space in the queue, making delivery
    // reliable.  However, it is VERY important that this function
    // never be called from within whatever event loop is polling
    // with PollEvent(), otherwise a deadlock may arise.
    //
    // For this reason, when using this function, the use of a
    // Goroutine is recommended to ensure no deadlock can occur.
    PostEventWait(ev Event)

    // EnableMouse enables the mouse.  (If your terminal supports it.)
    // If no flags are specified, then all events are reported, if the
    // terminal supports them.
    EnableMouse(...MouseFlags)

    // DisableMouse disables the mouse.
    DisableMouse()

    // EnablePaste enables bracketed paste mode, if supported.
    EnablePaste()

    // DisablePaste disables bracketed paste mode.
    DisablePaste()

    // HasMouse returns true if the terminal (apparently) supports a
    // mouse.  Note that the return value of true doesn't guarantee that
    // a mouse/pointing device is present; a false return definitely
    // indicates no mouse support is available.
    HasMouse() bool

    // Colors returns the number of colors.  All colors are assumed to
    // use the ANSI color map.  If a terminal is monochrome, it will
    // return 0.
    Colors() int

    // Show makes all the content changes made using SetContent() visible
    // on the display.
    //
    // It does so in the most efficient and least visually disruptive
    // manner possible.
    Show()

    // Sync works like Show(), but it updates every visible cell on the
    // physical display, assuming that it is not synchronized with any
    // internal model.  This may be both expensive and visually jarring,
    // so it should only be used when believed to actually be necessary.
    //
    // Typically, this is called as a result of a user-requested redraw
    // (e.g. to clear up on-screen corruption caused by some other program),
    // or during a resize event.
    Sync()

    // CharacterSet returns information about the character set.
    // This isn't the full locale, but it does give us the input/output
    // character set.  Note that this is just for diagnostic purposes,
    // we normally translate input/output to/from UTF-8, regardless of
    // what the user's environment is.
    CharacterSet() string

    // RegisterRuneFallback adds a fallback for runes that are not
    // part of the character set -- for example one could register
    // o as a fallback for ø.  This should be done cautiously for
    // characters that might be displayed ordinarily in language
    // specific text -- characters that could change the meaning of
    // written text would be dangerous.  The intention here is to
    // facilitate fallback characters in pseudo-graphical applications.
    //
    // If the terminal has fallbacks already in place via an alternate
    // character set, those are used in preference.  Also, standard
    // fallbacks for graphical characters in the alternate character set
    // terminfo string are registered implicitly.
    //
    // The display string should be the same width as original rune.
    // This makes it possible to register two character replacements
    // for full width East Asian characters, for example.
    //
    // It is recommended that replacement strings consist only of
    // 7-bit ASCII, since other characters may not display everywhere.
    RegisterRuneFallback(r rune, subst string)

    // UnregisterRuneFallback unmaps a replacement.  It will unmap
    // the implicit ASCII replacements for alternate characters as well.
    // When an unmapped char needs to be displayed, but no suitable
    // glyph is available, '?' is emitted instead.  It is not possible
    // to "disable" the use of alternate characters that are supported
    // by your terminal except by changing the terminal database.
    UnregisterRuneFallback(r rune)

    // CanDisplay returns true if the given rune can be displayed on
    // this screen.  Note that this is a best-guess effort -- whether
    // your fonts support the character or not may be questionable.
    // Mostly this is for folks who work outside of Unicode.
    //
    // If checkFallbacks is true, then if any (possibly imperfect)
    // fallbacks are registered, this will return true.  This will
    // also return true if the terminal can replace the glyph with
    // one that is visually indistinguishable from the one requested.
    CanDisplay(r rune, checkFallbacks bool) bool

    // Resize does nothing, since it's generally not possible to
    // ask a screen to resize, but it allows the Screen to implement
    // the View interface.
    Resize(int, int, int, int)

    // HasKey returns true if the keyboard is believed to have the
    // key.  In some cases a keyboard may have keys with this name
    // but no support for them, while in others a key may be reported
    // as supported but not actually be usable (such as some emulators
    // that hijack certain keys).  Its best not to depend to strictly
    // on this function, but it can be used for hinting when building
    // menus, displayed hot-keys, etc.  Note that KeyRune (literal
    // runes) is always true.
    HasKey(Key) bool

    // Suspend pauses input and output processing.  It also restores the
    // terminal settings to what they were when the application started.
    // This can be used to, for example, run a sub-shell.
    Suspend() error

    // Resume resumes after Suspend().
    Resume() error

    // Beep attempts to sound an OS-dependent audible alert and returns an error
    // when unsuccessful.
    Beep() error

    // SetSize attempts to resize the window.  It also invalidates the cells and
    // calls the resize function.  Note that if the window size is changed, it will
    // not be restored upon application exit.
    //
    // Many terminals cannot support this.  Perversely, the "modern" Windows Terminal
    // does not support application-initiated resizing, whereas the legacy terminal does.
    // Also, some emulators can support this but may have it disabled by default.
    SetSize(int, int)
}

func NewConsoleScreen

func NewConsoleScreen() (Screen, error)

NewConsoleScreen returns a console based screen. This platform doesn't have support for any, so it returns nil and a suitable error.

func NewScreen

func NewScreen() (Screen, error)

NewScreen returns a default Screen suitable for the user's terminal environment.

func NewTerminfoScreen

func NewTerminfoScreen() (Screen, error)

NewTerminfoScreen returns a Screen that uses the stock TTY interface and POSIX terminal control, combined with a terminfo description taken from the $TERM environment variable. It returns an error if the terminal is not supported for any reason.

For terminals that do not support dynamic resize events, the $LINES $COLUMNS environment variables can be set to the actual window size, otherwise defaults taken from the terminal database are used.

func NewTerminfoScreenFromTty

func NewTerminfoScreenFromTty(tty Tty) (Screen, error)

NewTerminfoScreenFromTty returns a Screen using a custom Tty implementation. If the passed in tty is nil, then a reasonable default (typically /dev/tty) is presumed, at least on UNIX hosts. (Windows hosts will typically fail this call altogether.)

func NewTerminfoScreenFromTtyTerminfo

func NewTerminfoScreenFromTtyTerminfo(tty Tty, ti *terminfo.Terminfo) (s Screen, e error)

NewTerminfoScreenFromTtyTerminfo returns a Screen using a custom Tty implementation and custom terminfo specification. If the passed in tty is nil, then a reasonable default (typically /dev/tty) is presumed, at least on UNIX hosts. (Windows hosts will typically fail this call altogether.) If passed terminfo is nil, then TERM environment variable is queried for terminal specification.

type SimCell

SimCell represents a simulated screen cell. The purpose of this is to track on screen content.

type SimCell struct {
    // Bytes is the actual character bytes.  Normally this is
    // rune data, but it could be be data in another encoding system.
    Bytes []byte

    // Style is the style used to display the data.
    Style Style

    // Runes is the list of runes, unadulterated, in UTF-8.
    Runes []rune
}

type SimulationScreen

SimulationScreen represents a screen simulation. This is intended to be a superset of normal Screens, but also adds some important interfaces for testing.

type SimulationScreen interface {
    // InjectKeyBytes injects a stream of bytes corresponding to
    // the native encoding (see charset).  It turns true if the entire
    // set of bytes were processed and delivered as KeyEvents, false
    // if any bytes were not fully understood.  Any bytes that are not
    // fully converted are discarded.
    InjectKeyBytes(buf []byte) bool

    // InjectKey injects a key event.  The rune is a UTF-8 rune, post
    // any translation.
    InjectKey(key Key, r rune, mod ModMask)

    // InjectMouse injects a mouse event.
    InjectMouse(x, y int, buttons ButtonMask, mod ModMask)

    // GetContents returns screen contents as an array of
    // cells, along with the physical width & height.   Note that the
    // physical contents will be used until the next time SetSize()
    // is called.
    GetContents() (cells []SimCell, width int, height int)

    // GetCursor returns the cursor details.
    GetCursor() (x int, y int, visible bool)

    Screen
}

func NewSimulationScreen

func NewSimulationScreen(charset string) SimulationScreen

NewSimulationScreen returns a SimulationScreen. Note that SimulationScreen is also a Screen.

type Style

Style represents a complete text style, including both foreground color, background color, and additional attributes such as "bold" or "underline".

Note that not all terminals can display all colors or attributes, and many might have specific incompatibilities between specific attributes and color combinations.

To use Style, just declare a variable of its type.

type Style struct {
    // contains filtered or unexported fields
}

StyleDefault represents a default style, based upon the context. It is the zero value.

var StyleDefault Style

func (Style) Attributes

func (s Style) Attributes(attrs AttrMask) Style

Attributes returns a new style based on s, with its attributes set as specified.

func (Style) Background

func (s Style) Background(c Color) Style

Background returns a new style based on s, with the background color set as requested. ColorDefault can be used to select the global default.

func (s Style) Blink(on bool) Style

Blink returns a new style based on s, with the blink attribute set as requested.

func (Style) Bold

func (s Style) Bold(on bool) Style

Bold returns a new style based on s, with the bold attribute set as requested.

func (Style) Decompose

func (s Style) Decompose() (fg Color, bg Color, attr AttrMask)

Decompose breaks a style up, returning the foreground, background, and other attributes. The URL if set is not included.

func (Style) Dim

func (s Style) Dim(on bool) Style

Dim returns a new style based on s, with the dim attribute set as requested.

func (Style) Foreground

func (s Style) Foreground(c Color) Style

Foreground returns a new style based on s, with the foreground color set as requested. ColorDefault can be used to select the global default.

func (Style) Italic

func (s Style) Italic(on bool) Style

Italic returns a new style based on s, with the italic attribute set as requested.

func (Style) Normal

func (s Style) Normal() Style

Normal returns the style with all attributes disabled.

func (Style) Reverse

func (s Style) Reverse(on bool) Style

Reverse returns a new style based on s, with the reverse attribute set as requested. (Reverse usually changes the foreground and background colors.)

func (Style) StrikeThrough

func (s Style) StrikeThrough(on bool) Style

StrikeThrough sets strikethrough mode.

func (Style) Underline

func (s Style) Underline(on bool) Style

Underline returns a new style based on s, with the underline attribute set as requested.

func (Style) Url

func (s Style) Url(url string) Style

Url returns a style with the Url set. If the provided Url is not empty, and the terminal supports it, text will typically be marked up as a clickable link to that Url. If the Url is empty, then this mode is turned off.

func (Style) UrlId

func (s Style) UrlId(id string) Style

UrlId returns a style with the UrlId set. If the provided UrlId is not empty, any marked up Url with this style will be given the UrlId also. If the terminal supports it, any text with the same UrlId will be grouped as if it were one Url, even if it spans multiple lines.

type Tty

Tty is an abstraction of a tty (traditionally "teletype"). This allows applications to provide for alternate backends, as there are situations where the traditional /dev/tty does not work, or where more flexible handling is required. This interface is for use with the terminfo-style based API. It extends the io.ReadWriter API. It is reasonable that the implementation might choose to use different underlying files for the Reader and Writer sides of this API, as part of it's internal implementation.

type Tty interface {
    // Start is used to activate the Tty for use.  Upon return the terminal should be
    // in raw mode, non-blocking, etc.  The implementation should take care of saving
    // any state that is required so that it may be restored when Stop is called.
    Start() error

    // Stop is used to stop using this Tty instance.  This may be a suspend, so that other
    // terminal based applications can run in the foreground.  Implementations should
    // restore any state collected at Start(), and return to ordinary blocking mode, etc.
    // Drain is called first to drain the input.  Once this is called, no more Read
    // or Write calls will be made until Start is called again.
    Stop() error

    // Drain is called before Stop, and ensures that the reader will wake up appropriately
    // if it was blocked.  This workaround is required for /dev/tty on certain UNIX systems
    // to ensure that Read() does not block forever.  This typically arranges for the tty driver
    // to send data immediately (e.g. VMIN and VTIME both set zero) and sets a deadline on input.
    // Implementations may reasonably make this a no-op.  There will still be control sequences
    // emitted between the time this is called, and when Stop is called.
    Drain() error

    // NotifyResize is used register a callback when the tty thinks the dimensions have
    // changed.  The standard UNIX implementation links this to a handler for SIGWINCH.
    // If the supplied callback is nil, then any handler should be unregistered.
    NotifyResize(cb func())

    // WindowSize is called to determine the terminal dimensions.  This might be determined
    // by an ioctl or other means.
    WindowSize() (width int, height int, err error)

    io.ReadWriteCloser
}

func NewDevTty

func NewDevTty() (Tty, error)

NewDevTty opens a /dev/tty based Tty.

func NewDevTtyFromDev

func NewDevTtyFromDev(dev string) (Tty, error)

NewDevTtyFromDev opens a tty device given a path. This can be useful to bind to other nodes.

func NewStdIoTty

func NewStdIoTty() (Tty, error)

NewStdioTty opens a tty using standard input/output.

Subdirectories

Name Synopsis
..
encoding Package encoding is used to provide a fairly complete set of encodings for tcell applications.
termbox Package termbox is a compatibility layer to allow tcell to emulate the github.com/nsf/termbox package.
terminfo
a
aixterm
alacritty
ansi
b
beterm
base Package base contains the base terminal descriptions that are likely to be needed by any stock application.
c
cygwin
d
dtterm
dynamic
e
emacs
extended Package extended contains an extended set of terminal descriptions.
f
foot
g
gnome
h
hpterm
k
konsole
kterm
l
linux
p
pcansi
r
rxvt
s
screen
simpleterm
sun
t
termite
tmux
v
vt100
vt102
vt220
vt320
vt400
vt420
vt52
w
wy50
wy60
wy99_ansi
x
xfce
xterm
xterm_kitty
xterm_termite
views