Skip to content

terminal/keys

import { … } from 'zidane-ui/terminal'ui/src/terminal/keys.ts

Functions#

macTerminalKeyFunction#

macOS text-editing keys in a terminal, the way Terminal.app and iTerm2's "Natural Text Editing" preset send them: the bytes a shell's line editor (zsh, bash/readline, fish) already understands by default.

⌘⌫ delete to line start (^U) ⌥⌫ delete word back (ESC DEL) ⌘⌦ delete to line end (^K) ⌥⌦ delete word forward (ESC d) ⌘← / ⌘→ line start / end (^A / ^E) ⌥← / ⌥→ word back / forward (ESC b / ESC f)

Returns null for everything else, which keeps its usual path.

TypeScript
function macTerminalKey(
  event: Pick<KeyboardEvent, 'key' | 'metaKey' | 'altKey' | 'ctrlKey' | 'shiftKey'>,
): string | null
Parameters
NameTypeDescription
eventPick<KeyboardEvent, 'key' | 'metaKey' | 'altKey' | 'ctrlKey' | 'shiftKey'>

The key and modifiers of a keydown.

string | null

ui/src/terminal/keys.ts:15