Documentation
¶
Index ¶
Constants ¶
const ( Shift = 1 << 63 Ctrl = 1 << 62 Alt = 1 << 61 )
Modifiers keys.
const ( Tab = 'i' | Ctrl Escape = '[' | Ctrl )
Common control sequences better known by their name than letter+Ctrl combination.
const CursesVersion = `ncurses-6.5.20240511`
CursesVersion is the version of curses this data was generated with, as [implementation]-[version].
Variables ¶
var Keys = map[*caps.Cap]Key{ caps.TableStrs[55]: Backspace, caps.TableStrs[59]: Delete, caps.TableStrs[61]: Down, caps.TableStrs[66]: F1, caps.TableStrs[67]: F10, caps.TableStrs[68]: F2, caps.TableStrs[69]: F3, caps.TableStrs[70]: F4, caps.TableStrs[71]: F5, caps.TableStrs[72]: F6, caps.TableStrs[73]: F7, caps.TableStrs[74]: F8, caps.TableStrs[75]: F9, caps.TableStrs[76]: Home, caps.TableStrs[77]: Insert, caps.TableStrs[79]: Left, caps.TableStrs[81]: PageDown, caps.TableStrs[82]: PageUp, caps.TableStrs[83]: Right, caps.TableStrs[87]: Up, caps.TableStrs[148]: BackTab, caps.TableStrs[164]: End, caps.TableStrs[165]: Enter, caps.TableStrs[191]: ShiftDelete, caps.TableStrs[194]: ShiftEnd, caps.TableStrs[199]: ShiftHome, caps.TableStrs[200]: ShiftInsert, caps.TableStrs[201]: ShiftLeft, caps.TableStrs[210]: ShiftRight, caps.TableStrs[216]: F11, caps.TableStrs[217]: F12, caps.TableStrs[355]: Mouse, }
Keys maps caps.Cap to Key constants
Functions ¶
This section is empty.
Types ¶
type Key ¶
type Key uint64
Key represents a keypress. This is formatted as follows:
- First 32 bits → rune (int32)
- Next 16 bits → Named key constant.
- Bits 49-61 → Currently unused.
- Bit 62 → Alt
- Bit 63 → Ctrl
- Bit 64 → Shift
The upshot of this is that you can now use a single value to test for all combinations:
switch Key(0x61) { case 'a': // 'a' w/o modifiers case 'a' | keys.Ctrl: // 'a' with control case 'a' | keys.Ctrl | keys.Shift: // 'a' with shift and control case keys.Up: // Arrow up case keys.Up | keys.Ctrl: // Arrow up with control }
Which is nicer than using two or three different variables to signal various things.
Letters are always in lower-case; use keys.Shift to test for upper case.
Control sequences (0x00-0x1f, 0x1f), are used sent as key + Ctrl. So this:
switch k { case 0x09: }
Won't work. you need to use:
switch k { case 'i' | key.Ctrl: }
Or better yet:
ti := termfo.New("") ... switch k { case ti.Keys[keys.Tab]: }
This just makes more sense, because people press "<C-a>" not "Start of heading".
It's better to use the variables from the terminfo, in case it's something different. Especially with things like Shift and Ctrl modifiers this can differ.
Note that support for multiple modifier keys is flaky across terminals.
const ( // Special key used to signal errors. UnknownSequence Key = iota + (1 << 32) ShiftLeft PageUp Insert ShiftInsert Up Right F1 ShiftRight F2 ShiftHome F3 Delete PageDown F4 F10 F11 ShiftDelete F5 Down Mouse F12 ShiftEnd F6 Enter Left F7 End F8 F9 Backspace BackTab Home )
List of all key sequences we know about. This excludes most obscure ones not present on modern devices.
func (Key) Name ¶
Name gets the key name. This doesn't show if any modifiers are set; use String() for that.
func (Key) WithoutMods ¶
WithoutMods returns a copy of k without any modifier keys set.