keys

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// The protocol defines special codes for these
	KittyKeyEscape    = 27
	KittyKeyEnter     = 13
	KittyKeyTab       = 9
	KittyKeyBackspace = 127

	// There are a bunch of keys that have irregular encodings; we use our
	// own internal codes for these
	/////////////////////////////////////////////////////////////////////
	// Navigation Keys
	KittyKeyHome     = 0xE000 + 1 // 1 H or 7 ~
	KittyKeyInsert   = 0xE000 + 2
	KittyKeyDelete   = 0xE000 + 3
	KittyKeyEnd      = 0xE000 + 4 // 1 F or 8 ~
	KittyKeyPageUp   = 0xE000 + 5
	KittyKeyPageDown = 0xE000 + 6
	KittyKeyUp       = 0xE000 + 65 // 1 A
	KittyKeyDown     = 0xE000 + 66 // 1 B
	KittyKeyRight    = 0xE000 + 67 // 1 C
	KittyKeyLeft     = 0xE000 + 68 // 1 D

	// Function Keys F1-F12
	KittyKeyF1  = 0xE000 + 112 // 1 P or 11 ~
	KittyKeyF2  = 0xE000 + 113 // 1 Q or 12 ~
	KittyKeyF3  = 0xE000 + 114 // 13 ~
	KittyKeyF4  = 0xE000 + 115 // 1 S or 14 ~
	KittyKeyF5  = 0xE000 + 116 // 15 ~
	KittyKeyF6  = 0xE000 + 117 // 17 ~
	KittyKeyF7  = 0xE000 + 118 // 18 ~
	KittyKeyF8  = 0xE000 + 119 // 19 ~
	KittyKeyF9  = 0xE000 + 120 // 20 ~
	KittyKeyF10 = 0xE000 + 121 // 21 ~
	KittyKeyF11 = 0xE000 + 122 // 23 ~
	KittyKeyF12 = 0xE000 + 123 // 24 ~

	// The rest of the keys all have fixed codes
	// Lock/System Keys
	KittyCapsLock    = 57358
	KittyScrollLock  = 57359
	KittyNumLock     = 57360
	KittyPrintScreen = 57361
	KittyPause       = 57362
	KittyMenu        = 57363

	// Function Keys F13-F35
	KittyKeyF13 = 57376
	KittyKeyF14 = 57377
	KittyKeyF15 = 57378
	KittyKeyF16 = 57379
	KittyKeyF17 = 57380
	KittyKeyF18 = 57381
	KittyKeyF19 = 57382
	KittyKeyF20 = 57383
	KittyKeyF21 = 57384
	KittyKeyF22 = 57385
	KittyKeyF23 = 57386
	KittyKeyF24 = 57387
	KittyKeyF25 = 57388
	KittyKeyF26 = 57389
	KittyKeyF27 = 57390
	KittyKeyF28 = 57391
	KittyKeyF29 = 57392
	KittyKeyF30 = 57393
	KittyKeyF31 = 57394
	KittyKeyF32 = 57395
	KittyKeyF33 = 57396
	KittyKeyF34 = 57397
	KittyKeyF35 = 57398

	// Keypad Keys
	KittyKP0         = 57399
	KittyKP1         = 57400
	KittyKP2         = 57401
	KittyKP3         = 57402
	KittyKP4         = 57403
	KittyKP5         = 57404
	KittyKP6         = 57405
	KittyKP7         = 57406
	KittyKP8         = 57407
	KittyKP9         = 57408
	KittyKPDecimal   = 57409
	KittyKPDivide    = 57410
	KittyKPMultiply  = 57411
	KittyKPSubtract  = 57412
	KittyKPAdd       = 57413
	KittyKPEnter     = 57414
	KittyKPEqual     = 57415
	KittyKPSeparator = 57416
	KittyKPLeft      = 57417
	KittyKPRight     = 57418
	KittyKPUp        = 57419
	KittyKPDown      = 57420
	KittyKPPageUp    = 57421
	KittyKPPageDown  = 57422
	KittyKPHome      = 57423
	KittyKPEnd       = 57424
	KittyKPInsert    = 57425
	KittyKPDelete    = 57426
	KittyKPBegin     = 57427

	// Media Keys
	KittyMediaPlay        = 57428
	KittyMediaPause       = 57429
	KittyMediaPlayPause   = 57430
	KittyMediaReverse     = 57431
	KittyMediaStop        = 57432
	KittyMediaFastForward = 57433
	KittyMediaRewind      = 57434
	KittyMediaTrackNext   = 57435
	KittyMediaTrackPrev   = 57436
	KittyMediaRecord      = 57437
	KittyLowerVolume      = 57438
	KittyRaiseVolume      = 57439
	KittyMuteVolume       = 57440

	// Modifier Keys
	KittyLeftShift    = 57441
	KittyLeftControl  = 57442
	KittyLeftAlt      = 57443
	KittyLeftSuper    = 57444
	KittyLeftHyper    = 57445
	KittyLeftMeta     = 57446
	KittyRightShift   = 57447
	KittyRightControl = 57448
	KittyRightAlt     = 57449
	KittyRightSuper   = 57450
	KittyRightHyper   = 57451
	KittyRightMeta    = 57452
)
View Source
const (
	// Special key code that indicates this Key only consists of content in
	// the Text field and nothing else. This is supported in bubbletea, so
	// we need to handle it somehow for backwards compatibility.
	KeyText = KittyKeyF12 + 1
)

Variables

This section is empty.

Functions

func GenerateKittyDisableSequence

func GenerateKittyDisableSequence() string

GenerateKittyDisableSequence generates the escape sequence to disable Kitty protocol

func GenerateKittyEnableSequence

func GenerateKittyEnableSequence(flags emu.KeyProtocol) string

GenerateKittyEnableSequence generates the escape sequence to enable Kitty protocol

func Read

func Read(b []byte) (event any, w int)

Read attempts to read a key or mouse event. event can be one of: - Key - Mouse - UnknownCSISequenceEvent - UnknownInputEvent

Types

type Key

type Key struct {
	Code    rune
	Shifted rune
	Base    rune
	Type    KeyEventType // Press/repeat/release
	Mod     KeyModifiers // Combined modifier flags
	Text    string
}

Key contains information about a keypress using Kitty protocol structure.

The fields in this structure have meanings as defined by the Kitty keyboard protocol: https://sw.kovidgoyal.net/kitty/keyboard-protocol/#an-overview

func FromHuman

func FromHuman(human string) (key Key, ok bool)

FromHuman translates human-readable key specifiers (such as "ctrl+a", "up", etc) into Keys.

func (Key) Bytes

func (k Key) Bytes(
	mode emu.ModeFlag,
	protocol emu.KeyProtocol,
) (data []byte, ok bool)

func (Key) HasAlt

func (k Key) HasAlt() bool

HasAlt returns true if Alt modifier is present

func (Key) HasCtrl

func (k Key) HasCtrl() bool

HasCtrl returns true if Ctrl modifier is present

func (Key) HasHyper

func (k Key) HasHyper() bool

HasHyper returns true if Hyper modifier is present

func (Key) HasMeta

func (k Key) HasMeta() bool

HasMeta returns true if Meta modifier is present

func (Key) HasModifier

func (k Key) HasModifier(mod KeyModifiers) bool

HasModifier checks if a specific Kitty modifier is present

func (Key) HasShift

func (k Key) HasShift() bool

HasShift returns true if Shift modifier is present

func (Key) HasSuper

func (k Key) HasSuper() bool

HasSuper returns true if Super modifier is present

func (Key) IsPress

func (k Key) IsPress() bool

IsPress returns true if this is a key press event (default for legacy keys)

func (Key) IsRelease

func (k Key) IsRelease() bool

IsRelease returns true if this is a key release event

func (Key) IsRepeat

func (k Key) IsRepeat() bool

IsRepeat returns true if this is a key repeat event

func (Key) String

func (k Key) String() (str string)

String returns a friendly string representation for a key. It's safe (and encouraged) for use in key comparison.

k := Key{KeyCode: KittyKeyEnter}
fmt.Println(k)
// Output: enter

func (Key) Tea

func (k Key) Tea() (msg tea.KeyMsg, ok bool)

type KeyEventType

type KeyEventType int

KeyEventType represents the type of key event (press/repeat/release)

const (
	KeyEventPress KeyEventType = iota
	KeyEventRepeat
	KeyEventRelease
)

func (KeyEventType) String

func (k KeyEventType) String() string

type KeyModifiers

type KeyModifiers int

KeyModifiers represents Kitty protocol modifier flags

const (
	KeyModShift KeyModifiers = 1 << iota
	KeyModAlt
	KeyModCtrl
	KeyModSuper
	KeyModHyper
	KeyModMeta
	KeyModCapsLock
	KeyModNumLock
)

type Mouse

type Mouse struct {
	geom.Vec2
	Type   MouseEventType
	Button MouseButton
	Down   bool
	Alt    bool
	Ctrl   bool
}

Mouse represents a mouse event, which could be a click, a scroll wheel movement, a cursor movement, or a combination.

func (Mouse) Bytes

func (m Mouse) Bytes() []byte

func (Mouse) String

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

String returns a string representation of a mouse event.

func (Mouse) X10Bytes

func (m Mouse) X10Bytes() []byte

type MouseButton

type MouseButton int
const (
	MouseLeft MouseButton = iota
	MouseRight
	MouseMiddle
	MouseWheelUp
	MouseWheelDown
	MouseWheelRight
	MouseWheelLeft
)

type MouseEventType

type MouseEventType int

MouseEventType indicates the type of mouse event occurring.

const (
	MouseUnknown MouseEventType = iota
	MousePress
	MouseMotion
)

Mouse event types.

type UnknownCSISequenceEvent

type UnknownCSISequenceEvent []byte

UnknownCSISequenceEvent is reported by the input reader when an unrecognized CSI sequence is detected on the input. Currently, it is not handled further by bubbletea. However, having this event makes it possible to troubleshoot invalid inputs.

func (UnknownCSISequenceEvent) String

func (u UnknownCSISequenceEvent) String() string

type UnknownInputEvent

type UnknownInputEvent byte

UnknownInputEvent is reported by the input reader when an invalid utf-8 byte is detected on the input. Currently, it is not handled further by keys. However, having this event makes it possible to troubleshoot invalid inputs.

func (UnknownInputEvent) String

func (u UnknownInputEvent) String() string

Jump to

Keyboard shortcuts

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