input

package
v0.0.0-...-8135bef Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 6, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
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

func SetFlags

func SetFlags(f int)

SetFlags sets the flags for the parser. This will control the behavior of ParseSequence.

Types

type BackgroundColorEvent

type BackgroundColorEvent struct{ color.Color }

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

type CursorColorEvent struct{ color.Color }

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

func NewDriver(r io.Reader, term string, flags int) (*Driver, error)

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) Cancel

func (d *Driver) Cancel() bool

Cancel cancels the underlying reader.

func (*Driver) Close

func (d *Driver) Close() error

Close closes the underlying reader.

func (*Driver) ReadEvents

func (d *Driver) ReadEvents() ([]Event, error)

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

func ParseSequence(buf []byte) (n int, e Event)

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

type ForegroundColorEvent struct{ color.Color }

ForegroundColorEvent represents a foreground color change event.

func (ForegroundColorEvent) String

func (e ForegroundColorEvent) String() string

String implements fmt.Stringer.

type Key

type Key struct {
	Sym      KeySym
	Rune     rune
	AltRune  rune
	BaseRune rune
	IsRepeat bool
	Mod      KeyMod
}

Key represents a key event.

func (Key) String

func (k Key) String() string

String implements fmt.Stringer.

type KeyDownEvent

type KeyDownEvent Key

KeyDownEvent represents a key down event.

func (KeyDownEvent) String

func (k KeyDownEvent) 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

func (m KeyMod) HasCapsLock() bool

HasCapsLock reports whether the CapsLock key is enabled.

func (KeyMod) HasNumLock

func (m KeyMod) HasNumLock() bool

HasNumLock reports whether the NumLock key is enabled.

func (KeyMod) HasScrollLock

func (m KeyMod) HasScrollLock() bool

HasScrollLock reports whether the ScrollLock key is enabled.

func (KeyMod) IsAlt

func (m KeyMod) IsAlt() bool

IsAlt reports whether the Alt modifier is set.

func (KeyMod) IsCtrl

func (m KeyMod) IsCtrl() bool

IsCtrl reports whether the Ctrl modifier is set.

func (KeyMod) IsHyper

func (m KeyMod) IsHyper() bool

IsHyper reports whether the Hyper modifier is set.

func (KeyMod) IsMeta

func (m KeyMod) IsMeta() bool

IsMeta reports whether the Meta modifier is set.

func (KeyMod) IsShift

func (m KeyMod) IsShift() bool

IsShift reports whether the Shift modifier is set.

func (KeyMod) IsSuper

func (m KeyMod) IsSuper() bool

IsSuper reports whether the Super modifier is set.

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.

func (KeySym) String

func (k KeySym) String() string

String implements fmt.Stringer.

type KeyUpEvent

type KeyUpEvent Key

KeyUpEvent represents a key up event.

func (KeyUpEvent) String

func (k KeyUpEvent) String() string

String implements fmt.Stringer.

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 Mouse

type Mouse struct {
	X, Y   int
	Button MouseButton
	Mod    KeyMod
}

Mouse represents a Mouse event.

func (Mouse) String

func (m Mouse) String() (s string)

String implements fmt.Stringer.

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 MouseUpEvent

type MouseUpEvent Mouse

MouseUpEvent represents a mouse button up event.

func (MouseUpEvent) String

func (e MouseUpEvent) 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 MultiEvent

type MultiEvent []Event

MultiEvent represents multiple events.

func (MultiEvent) String

func (e MultiEvent) 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.

See: https://vt100.net/docs/vt510-rm/DECRPM.html

type TermcapEvent

type TermcapEvent struct {
	Values  map[string]string
	IsValid bool
}

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 UnknownEvent

type UnknownEvent string

UnknownEvent represents an unknown event.

func (UnknownEvent) String

func (e UnknownEvent) 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL