Documentation ¶
Index ¶
Constants ¶
const ( KeyBackspace = KeyBS KeyTab = KeyTAB KeyEsc = KeyESC KeyEscape = KeyESC KeyEnter = KeyCR KeyBackspace2 = KeyDEL )
These keys are aliases for other names.
Variables ¶
var KeyNames = map[Key]string{}/* 118 elements not displayed */
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.
Functions ¶
This section is empty.
Types ¶
type Console ¶
type Console struct {
// contains filtered or unexported fields
}
func (*Console) SetPretext ¶
type ConsoleInput ¶
type ConsoleInput struct {
// contains filtered or unexported fields
}
func NewConsoleInput ¶
func NewConsoleInput() *ConsoleInput
func (*ConsoleInput) Init ¶
func (ci *ConsoleInput) Init() error
func (*ConsoleInput) PollEvent ¶
func (ci *ConsoleInput) PollEvent() *EventKey
func (*ConsoleInput) Stop ¶
func (ci *ConsoleInput) Stop()
type EditBox ¶
type EditBox struct {
// contains filtered or unexported fields
}
func NewEditBox ¶
func (*EditBox) GetEnterText ¶
func (*EditBox) GetShowText ¶
type EventKey ¶
type EventKey struct {
// contains filtered or unexported fields
}
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.
func NewEventKey ¶
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 ¶
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) Name ¶
Name returns a printable value or the key stroke. This can be used when printing the event, for example.
type Key ¶
type Key int16
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.
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 )
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 ( 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 control keys. Note that they overlap with other keys, perhaps. For example, KeyCtrlH is the same as KeyBackspace.
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 )
These are the defined ASCII values for key codes. They generally match with KeyCtrl values.
type Terminfo ¶
type Terminfo struct { Name string Aliases []string Columns int // cols Lines int // lines Colors int // colors Bell string // bell Clear string // clear EnterCA string // smcup ExitCA string // rmcup ShowCursor string // cnorm HideCursor string // civis AttrOff string // sgr0 Underline string // smul Bold string // bold Blink string // blink Reverse string // rev Dim string // dim EnterKeypad string // smkx ExitKeypad string // rmkx SetFg string // setaf SetBg string // setab SetCursor string // cup CursorBack1 string // cub1 CursorUp1 string // cuu1 PadChar string // pad KeyBackspace string // kbs KeyF1 string // kf1 KeyF2 string // kf2 KeyF3 string // kf3 KeyF4 string // kf4 KeyF5 string // kf5 KeyF6 string // kf6 KeyF7 string // kf7 KeyF8 string // kf8 KeyF9 string // kf9 KeyF10 string // kf10 KeyF11 string // kf11 KeyF12 string // kf12 KeyF13 string // kf13 KeyF14 string // kf14 KeyF15 string // kf15 KeyF16 string // kf16 KeyF17 string // kf17 KeyF18 string // kf18 KeyF19 string // kf19 KeyF20 string // kf20 KeyF21 string // kf21 KeyF22 string // kf22 KeyF23 string // kf23 KeyF24 string // kf24 KeyF25 string // kf25 KeyF26 string // kf26 KeyF27 string // kf27 KeyF28 string // kf28 KeyF29 string // kf29 KeyF30 string // kf30 KeyF31 string // kf31 KeyF32 string // kf32 KeyF33 string // kf33 KeyF34 string // kf34 KeyF35 string // kf35 KeyF36 string // kf36 KeyF37 string // kf37 KeyF38 string // kf38 KeyF39 string // kf39 KeyF40 string // kf40 KeyF41 string // kf41 KeyF42 string // kf42 KeyF43 string // kf43 KeyF44 string // kf44 KeyF45 string // kf45 KeyF46 string // kf46 KeyF47 string // kf47 KeyF48 string // kf48 KeyF49 string // kf49 KeyF50 string // kf50 KeyF51 string // kf51 KeyF52 string // kf52 KeyF53 string // kf53 KeyF54 string // kf54 KeyF55 string // kf55 KeyF56 string // kf56 KeyF57 string // kf57 KeyF58 string // kf58 KeyF59 string // kf59 KeyF60 string // kf60 KeyF61 string // kf61 KeyF62 string // kf62 KeyF63 string // kf63 KeyF64 string // kf64 KeyInsert string // kich1 KeyDelete string // kdch1 KeyHome string // khome KeyEnd string // kend KeyHelp string // khlp KeyPgUp string // kpp KeyPgDn string // knp KeyUp string // kcuu1 KeyDown string // kcud1 KeyLeft string // kcub1 KeyRight string // kcuf1 KeyBacktab string // kcbt KeyExit string // kext KeyClear string // kclr KeyPrint string // kprt KeyCancel string // kcan Mouse string // kmous MouseMode string // XM AltChars string // acsc EnterAcs string // smacs ExitAcs string // rmacs EnableAcs string // enacs KeyShfRight string // kRIT KeyShfLeft string // kLFT KeyShfHome string // kHOM KeyShfEnd string // kEND SetFgBg string // setfgbg SetFgBgRGB string // setfgbgrgb SetFgRGB string // setfrgb SetBgRGB string // setbrgb KeyShfUp string // shift-up KeyShfDown string // shift-down KeyCtrlUp string // ctrl-up KeyCtrlDown string // ctrl-left KeyCtrlRight string // ctrl-right KeyCtrlLeft string // ctrl-left KeyMetaUp string // meta-up KeyMetaDown string // meta-left KeyMetaRight string // meta-right KeyMetaLeft string // meta-left KeyAltUp string // alt-up KeyAltDown string // alt-left KeyAltRight string // alt-right KeyAltLeft string // alt-left KeyCtrlHome string KeyCtrlEnd string KeyMetaHome string KeyMetaEnd string KeyAltHome string KeyAltEnd string KeyAltShfUp string KeyAltShfDown string KeyAltShfLeft string KeyAltShfRight string KeyMetaShfUp string KeyMetaShfDown string KeyMetaShfLeft string KeyMetaShfRight string KeyCtrlShfUp string KeyCtrlShfDown string KeyCtrlShfLeft string KeyCtrlShfRight string KeyCtrlShfHome string KeyCtrlShfEnd string KeyAltShfHome string KeyAltShfEnd string KeyMetaShfHome string KeyMetaShfEnd string }
Terminfo represents a terminfo entry. Note that we use friendly names in Go, but when we write out JSON, we use the same names as terminfo. The name, aliases and smous, rmous fields do not come from terminfo directly.