UNPKG

@teaui/core

Version:

A high-level terminal UI library for Node

48 lines (47 loc) 1.78 kB
import type { KeyName, NamedKey, Printable } from '@teaui/term'; /** * Modifier prefix combinations, always in the order C- A- G- S-. */ type ModifierPrefix = '' | 'C-' | 'A-' | 'G-' | 'S-' | 'C-A-' | 'C-G-' | 'C-S-' | 'A-G-' | 'A-S-' | 'G-S-' | 'C-A-G-' | 'C-A-S-' | 'C-G-S-' | 'A-G-S-' | 'C-A-G-S-'; /** * A key name with optional modifier prefixes, e.g. "C-a", "G-backspace", "C-G-S-up". * Provides autocomplete for known key+modifier combos while accepting any string. */ export type FullKeyName = `${ModifierPrefix}${NamedKey | Printable}` | (string & {}); export interface KeyEvent { type: 'key'; /** * "Probably" the letter (a-z, etc) that was pressed. Blank (or nonsensical) for meta characters (escape, arrow keys, etc) */ char: string; /** * Named key, like "enter", "a", "escape", etc, or the printable character */ name: KeyName; ctrl: boolean; alt: boolean; gui: boolean; shift: boolean; /** * The letter that was pressed, *plus* the modifiers (C-G-S- for control- gui- shift, always in that order) */ full: FullKeyName; } export type HotKeyDef = { char: string; ctrl?: boolean; alt?: boolean; gui?: boolean; shift?: boolean; }; export type HotKey = FullKeyName | HotKeyDef; /** * Convert a HotKey to a display string like 'C-x' suitable for Legend items. */ export declare function hotKeyToString(hotKey: HotKey): string; export declare function toHotKeyDef(hotKey: HotKey): HotKeyDef; export declare function mapKey(key: string): string; export declare function isKeyPrintable(event: KeyEvent): boolean; export declare const match: (key: HotKeyDef, event: KeyEvent) => boolean; export declare function styleTextForHotKey(text: string, key_: HotKey): string; export {};