Documentation
¶
Index ¶
- Constants
- Variables
- func SetFlags(f int)
- type BackgroundColorEvent
- type ClipboardEvent
- type CursorColorEvent
- type CursorPositionEvent
- type Driver
- type Event
- type ForegroundColorEvent
- type Key
- type KeyDownEvent
- type KeyMod
- type KeySym
- type KeyUpEvent
- type KittyKeyboardEvent
- type ModifyOtherKeysEvent
- type Mouse
- type MouseButton
- type MouseDownEvent
- type MouseMotionEvent
- type MouseUpEvent
- type MouseWheelEvent
- type MultiEvent
- type PasteEndEvent
- type PasteEvent
- type PasteStartEvent
- type PrimaryDeviceAttributesEvent
- type ReportModeEvent
- type TermcapEvent
- type UnknownApcEvent
- type UnknownCsiEvent
- type UnknownDcsEvent
- type UnknownEvent
- type UnknownOscEvent
- type UnknownSs3Event
- type WindowSizeEvent
Constants ¶
const ( // When this flag is set, the driver will treat both Ctrl+Space and Ctrl+@ // as the same key sequence. // // Historically, the ANSI specs generate NUL (0x00) on both the Ctrl+Space // and Ctrl+@ key sequences. This flag allows the driver to treat both as // the same key sequence. FlagCtrlAt = 1 << iota // When this flag is set, the driver will treat the Tab key and Ctrl+I as // the same key sequence. // // Historically, the ANSI specs generate HT (0x09) on both the Tab key and // Ctrl+I. This flag allows the driver to treat both as the same key // sequence. FlagCtrlI // When this flag is set, the driver will treat the Enter key and Ctrl+M as // the same key sequence. // // Historically, the ANSI specs generate CR (0x0D) on both the Enter key // and Ctrl+M. This flag allows the driver to treat both as the same key FlagCtrlM // When this flag is set, the driver will treat Escape and Ctrl+[ as // the same key sequence. // // Historically, the ANSI specs generate ESC (0x1B) on both the Escape key // and Ctrl+[. This flag allows the driver to treat both as the same key // sequence. FlagCtrlOpenBracket // When this flag is set, the driver will send a BS (0x08 byte) character // instead of a DEL (0x7F byte) character when the Backspace key is // pressed. // // The VT100 terminal has both a Backspace and a Delete key. The VT220 // terminal dropped the Backspace key and replaced it with the Delete key. // Both terminals send a DEL character when the Delete key is pressed. // Modern terminals and PCs later readded the Delete key but used a // different key sequence, and the Backspace key was standardized to send a // DEL character. FlagBackspace // When this flag is set, the driver will recognize the Find key instead of // treating it as a Home key. // // The Find key was part of the VT220 keyboard, and is no longer used in // modern day PCs. FlagFind // When this flag is set, the driver will recognize the Select key instead // of treating it as a End key. // // The Symbol key was part of the VT220 keyboard, and is no longer used in // modern day PCs. FlagSelect // When this flag is set, the driver will use Terminfo databases to // overwrite the default key sequences. FlagTerminfo // When this flag is set, the driver will preserve function keys (F13-F63) // as symbols. // // Since these keys are not part of today's standard 20th century keyboard, // we treat them as F1-F12 modifier keys i.e. ctrl/shift/alt + Fn combos. // Key definitions come from Terminfo, this flag is only useful when // FlagTerminfo is not set. FlagFKeys )
Flags to control the behavior of the parser.
Variables ¶
var ( // ErrUnknownEvent is returned when an unknown event is encountered. ErrUnknownEvent = fmt.Errorf("unknown event") // ErrEmpty is returned when the event buffer is empty. ErrEmpty = fmt.Errorf("empty event buffer") )
Functions ¶
Types ¶
type BackgroundColorEvent ¶
BackgroundColorEvent represents a background color change event.
func (BackgroundColorEvent) String ¶
func (e BackgroundColorEvent) String() string
String implements fmt.Stringer.
type ClipboardEvent ¶
type ClipboardEvent string
ClipboardEvent is a clipboard read event.
func (ClipboardEvent) String ¶
func (e ClipboardEvent) String() string
String returns the string representation of the clipboard event.
type CursorColorEvent ¶
CursorColorEvent represents a cursor color change event.
func (CursorColorEvent) String ¶
func (e CursorColorEvent) String() string
String implements fmt.Stringer.
type CursorPositionEvent ¶
type CursorPositionEvent struct { // Row is the row number. Row int // Column is the column number. Column int }
CursorPositionEvent represents a cursor position event.
type Driver ¶
type Driver struct {
// contains filtered or unexported fields
}
Driver represents an ANSI terminal input Driver. It reads input events and parses ANSI sequences from the terminal input buffer.
func NewDriver ¶
NewDriver returns a new ANSI input driver. This driver uses ANSI control codes compatible with VT100/VT200 terminals, and XTerm. It supports reading Terminfo databases to overwrite the default key sequences.
func (*Driver) ReadEvents ¶
ReadEvents reads input events from the terminal.
It reads the events available in the input buffer and returns them.
type Event ¶
type Event interface{}
Event represents a terminal input event.
func ParseSequence ¶
ParseSequence finds the first recognized event sequence and returns it along with its length.
It will return zero and nil no sequence is recognized or when the buffer is empty. If a sequence is not supported, an UnknownEvent is returned.
type ForegroundColorEvent ¶
ForegroundColorEvent represents a foreground color change event.
func (ForegroundColorEvent) String ¶
func (e ForegroundColorEvent) String() string
String implements fmt.Stringer.
type KeyMod ¶
type KeyMod uint16
KeyMod represents modifier keys.
const ( Shift KeyMod = 1 << iota Alt Ctrl Meta Hyper Super // Windows/Command keys CapsLock NumLock ScrollLock // Defined in Windows API only )
Modifier keys.
func (KeyMod) HasCapsLock ¶
HasCapsLock reports whether the CapsLock key is enabled.
func (KeyMod) HasNumLock ¶
HasNumLock reports whether the NumLock key is enabled.
func (KeyMod) HasScrollLock ¶
HasScrollLock reports whether the ScrollLock key is enabled.
type KeySym ¶
type KeySym int
KeySym is a keyboard symbol.
const ( KeyNone KeySym = iota KeyBackspace KeyTab KeyEnter KeyEscape KeySpace KeyDelete KeyUp KeyDown KeyRight KeyLeft KeyBegin KeyFind KeyInsert KeySelect KeyPgUp KeyPgDown KeyHome KeyEnd KeyKpEnter KeyKpEqual KeyKpMultiply KeyKpPlus KeyKpComma KeyKpMinus KeyKpDecimal KeyKpDivide KeyKp0 KeyKp1 KeyKp2 KeyKp3 KeyKp4 KeyKp5 KeyKp6 KeyKp7 KeyKp8 KeyKp9 // The following are keys defined in the Kitty keyboard protocol. // TODO: Investigate the names of these keys KeyKpSep KeyKpUp KeyKpDown KeyKpLeft KeyKpRight KeyKpPgUp KeyKpPgDown KeyKpHome KeyKpEnd KeyKpInsert KeyKpDelete KeyKpBegin 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 KeyCapsLock KeyScrollLock KeyNumLock KeyPrintScreen KeyPause KeyMenu KeyMediaPlay KeyMediaPause KeyMediaPlayPause KeyMediaReverse KeyMediaStop KeyMediaFastForward KeyMediaRewind KeyMediaNext KeyMediaPrev KeyMediaRecord KeyLowerVol KeyRaiseVol KeyMute KeyLeftShift KeyLeftAlt KeyLeftCtrl KeyLeftSuper KeyLeftHyper KeyLeftMeta KeyRightShift KeyRightAlt KeyRightCtrl KeyRightSuper KeyRightHyper KeyRightMeta KeyIsoLevel3Shift KeyIsoLevel5Shift )
Symbol constants.
type KittyKeyboardEvent ¶
type KittyKeyboardEvent int
KittyKeyboardEvent represents Kitty keyboard progressive enhancement flags.
func (KittyKeyboardEvent) IsDisambiguateEscapeCodes ¶
func (e KittyKeyboardEvent) IsDisambiguateEscapeCodes() bool
IsDisambiguateEscapeCodes returns true if the DisambiguateEscapeCodes flag is set.
func (KittyKeyboardEvent) IsReportAllKeys ¶
func (e KittyKeyboardEvent) IsReportAllKeys() bool
IsReportAllKeys returns true if the ReportAllKeys flag is set.
func (KittyKeyboardEvent) IsReportAlternateKeys ¶
func (e KittyKeyboardEvent) IsReportAlternateKeys() bool
IsReportAlternateKeys returns true if the ReportAlternateKeys flag is set.
func (KittyKeyboardEvent) IsReportAssociatedKeys ¶
func (e KittyKeyboardEvent) IsReportAssociatedKeys() bool
IsReportAssociatedKeys returns true if the ReportAssociatedKeys flag is set.
func (KittyKeyboardEvent) IsReportEventTypes ¶
func (e KittyKeyboardEvent) IsReportEventTypes() bool
IsReportEventTypes returns true if the ReportEventTypes flag is set.
type ModifyOtherKeysEvent ¶
type ModifyOtherKeysEvent uint8
ModifyOtherKeysEvent represents a modifyOtherKeys event.
0: disable 1: enable mode 1 2: enable mode 2
See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Functions-using-CSI-_-ordered-by-the-final-character_s_ See: https://invisible-island.net/xterm/manpage/xterm.html#VT100-Widget-Resources:modifyOtherKeys
type Mouse ¶
type Mouse struct {
X, Y int
Button MouseButton
Mod KeyMod
}
Mouse represents a Mouse event.
type MouseButton ¶
type MouseButton byte
MouseButton represents the button that was pressed during a mouse event.
const ( MouseNone MouseButton = iota MouseLeft MouseMiddle MouseRight MouseWheelUp MouseWheelDown MouseWheelLeft MouseWheelRight MouseBackward MouseForward MouseExtra1 MouseExtra2 )
Mouse event buttons
This is based on X11 mouse button codes.
1 = left button 2 = middle button (pressing the scroll wheel) 3 = right button 4 = turn scroll wheel up 5 = turn scroll wheel down 6 = push scroll wheel left 7 = push scroll wheel right 8 = 4th button (aka browser backward button) 9 = 5th button (aka browser forward button) 10 11
Other buttons are not supported.
type MouseDownEvent ¶
type MouseDownEvent Mouse
MouseDownEvent represents a mouse button down event.
func (MouseDownEvent) String ¶
func (e MouseDownEvent) String() string
String implements fmt.Stringer.
type MouseMotionEvent ¶
type MouseMotionEvent Mouse
MouseMotionEvent represents a mouse motion event.
func (MouseMotionEvent) String ¶
func (e MouseMotionEvent) String() string
String implements fmt.Stringer.
type MouseWheelEvent ¶
type MouseWheelEvent Mouse
MouseWheelEvent represents a mouse wheel event.
func (MouseWheelEvent) String ¶
func (e MouseWheelEvent) String() string
String implements fmt.Stringer.
type PasteEndEvent ¶
type PasteEndEvent struct{}
PasteEvent is an event that is emitted when a terminal receives pasted text.
type PasteEvent ¶
type PasteEvent string
PasteEvent is an event that is emitted when a terminal receives pasted text using bracketed-paste.
type PasteStartEvent ¶
type PasteStartEvent struct{}
PasteStartEvent is an event that is emitted when a terminal enters bracketed-paste mode.
type PrimaryDeviceAttributesEvent ¶
type PrimaryDeviceAttributesEvent []uint
PrimaryDeviceAttributesEvent represents a primary device attributes event.
type ReportModeEvent ¶
type ReportModeEvent struct { // Mode is the mode number. Mode int // Value is the mode value. Value int }
ReportModeEvent represents a report mode event for sequence DECRPM.
type TermcapEvent ¶
TermcapEvent represents a Termcap response event. Termcap responses are generated by the terminal in response to RequestTermcap (XTGETTCAP) requests.
See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
type UnknownApcEvent ¶
type UnknownApcEvent string
UnknownApcEvent represents an unknown APC sequence event.
func (UnknownApcEvent) String ¶
func (e UnknownApcEvent) String() string
String implements fmt.Stringer.
type UnknownCsiEvent ¶
type UnknownCsiEvent string
UnknownCsiEvent represents an unknown CSI sequence event.
func (UnknownCsiEvent) String ¶
func (e UnknownCsiEvent) String() string
String implements fmt.Stringer.
type UnknownDcsEvent ¶
type UnknownDcsEvent string
UnknownDcsEvent represents an unknown DCS sequence event.
func (UnknownDcsEvent) String ¶
func (e UnknownDcsEvent) String() string
String implements fmt.Stringer.
type UnknownOscEvent ¶
type UnknownOscEvent string
UnknownOscEvent represents an unknown OSC sequence event.
func (UnknownOscEvent) String ¶
func (e UnknownOscEvent) String() string
String implements fmt.Stringer.
type UnknownSs3Event ¶
type UnknownSs3Event string
UnknownSs3Event represents an unknown SS3 sequence event.
func (UnknownSs3Event) String ¶
func (e UnknownSs3Event) String() string
String implements fmt.Stringer.
type WindowSizeEvent ¶
type WindowSizeEvent struct {
Width, Height int
}
WindowSizeEvent represents a window resize event.
func (WindowSizeEvent) String ¶
func (e WindowSizeEvent) String() string
String implements fmt.Stringer.