createKeybindRegistry
function createKeybindRegistry<S>(scopes): KeybindRegistry<S>;Create a static keybind registry from a scope→keybinds mapping.
The returned registry object exposes the raw data together with helper methods for command lookup, help generation, and scope queries.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
S extends string |
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
scopes | Record<S, KeybindDef[]> | A record mapping scope names to arrays of keybind definitions. |
Returns
Section titled “Returns”A frozen KeybindRegistry instance.
Example
Section titled “Example”import { createKeybindRegistry } from "@semos-labs/glyph";
const registry = createKeybindRegistry({ global: [ { key: "?", display: "?", description: "Show help", action: "openHelp", command: "help" }, { key: ":", display: ":", description: "Open command bar", action: "openCommand" }, { key: "q", display: "q", description: "Quit", action: "quit", command: "quit" }, ], list: [ { key: "j", display: "j / ↓", description: "Next item", action: "next" }, { key: "down", display: "j / ↓", description: "Next item", action: "next" }, { key: "k", display: "k / ↑", description: "Previous item", action: "prev" }, { key: "up", display: "k / ↑", description: "Previous item", action: "prev" }, { key: "return", display: "Enter", description: "Open item", action: "open" }, ],});KeybindDef
Section titled “KeybindDef”A single keybind definition within a scope.
Example
Section titled “Example”const def: KeybindDef = { key: "shift+d", display: "D", description: "Delete item", action: "delete", command: "delete",};Properties
Section titled “Properties”CommandDef
Section titled “CommandDef”A command entry extracted from the registry.
Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
action | string | Action identifier to dispatch. |
description | string | Description of the command. |
name | string | The command name (from KeybindDef.command). |
KeybindRegistry
A typed keybind registry with helper methods.
Created by createKeybindRegistry. Provides access to the raw scope→keybind mapping and convenience methods for command lookup, help generation, and more.
Example
Section titled “Example”const commands = registry.getAllCommands();const match = registry.findCommand("goto tomorrow");const help = registry.getKeybindsForHelp("timeline");Type Parameters
Section titled “Type Parameters”| Type Parameter | Default type |
|---|---|
S extends string | string |
Methods
Section titled “Methods”findCommand()
Section titled “findCommand()”findCommand(input): | { action: string; args?: string; name: string;} | null;Find a command by user input text.
Supports exact matches and parameterised commands (e.g. "goto <date>"
matches input "goto tomorrow" with args = "tomorrow").
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
input | string | Raw user input from the command bar. |
Returns
Section titled “Returns”| {
action: string;
args?: string;
name: string;
}
| null
Matched command with optional args, or null.
getAllCommands()
Section titled “getAllCommands()”getAllCommands(): CommandDef[];Collect every keybind that has a command field, sorted by name.
Returns
Section titled “Returns”Sorted array of command definitions.
getKeybindsForHelp()
Section titled “getKeybindsForHelp()”getKeybindsForHelp(context, options?): { keybinds: KeybindDef[]; title: string;}[];Build sections for a help dialog: context-specific, related sub-modes, then global keybinds.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
context | S | The primary scope to display. |
options? | HelpOptions<S> | Optional related scopes and titles. |
Returns
Section titled “Returns”{
keybinds: KeybindDef[];
title: string;
}[]
Ordered sections for rendering.
getKeybindsForScope()
Section titled “getKeybindsForScope()”getKeybindsForScope(scope): KeybindDef[];Get de-duplicated keybinds for a scope (unique by display).
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
scope | S | Scope name. |
Returns
Section titled “Returns”Keybinds with duplicate display values removed.
Properties
Section titled “Properties”| Property | Modifier | Type | Description |
|---|---|---|---|
scopes | readonly | Readonly<Record<S, KeybindDef[]>> | The raw scope→keybinds mapping. |
HelpOptions
Options for KeybindRegistry.getKeybindsForHelp.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
S extends string |