-
Notifications
You must be signed in to change notification settings - Fork 234
Expand file tree
/
Copy pathpanel-keys.ts
More file actions
37 lines (33 loc) · 1.2 KB
/
Copy pathpanel-keys.ts
File metadata and controls
37 lines (33 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { matchesKey } from "@earendil-works/pi-tui";
/** The `tui.select.*` keybinding ids the adapter panels resolve. */
export type PanelSelectKeybinding =
| "tui.select.up"
| "tui.select.down"
| "tui.select.confirm";
/** Structural subset of pi-tui's `KeybindingsManager` (which satisfies it). */
export interface PanelKeybindings {
matches(data: string, keybinding: PanelSelectKeybinding): boolean;
}
/**
* Key matchers for list navigation: user's `tui.select.*` bindings when a
* manager is provided, otherwise the previous hardcoded defaults.
*/
export interface PanelKeys {
selectUp(data: string): boolean;
selectDown(data: string): boolean;
selectConfirm(data: string): boolean;
}
export function createPanelKeys(keybindings?: PanelKeybindings): PanelKeys {
if (keybindings) {
return {
selectUp: (data) => keybindings.matches(data, "tui.select.up"),
selectDown: (data) => keybindings.matches(data, "tui.select.down"),
selectConfirm: (data) => keybindings.matches(data, "tui.select.confirm"),
};
}
return {
selectUp: (data) => matchesKey(data, "up"),
selectDown: (data) => matchesKey(data, "down"),
selectConfirm: (data) => matchesKey(data, "return"),
};
}