File size: 989 Bytes
4c76b0d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
38
/**
 * Utilities for formatting keybinding hints in the UI.
 */

import { getKeybindings, type Keybinding, type KeyId } from "@earendil-works/pi-tui";
import { interactiveAgentTheme as theme } from "../theme/theme.js";

function formatKeyPart(part: string): string {
  return process.platform === "darwin" && part.toLowerCase() === "alt" ? "option" : part;
}

function formatKeyText(key: string): string {
  return key
    .split("/")
    .map((k) =>
      k
        .split("+")
        .map((part) => formatKeyPart(part))
        .join("+"),
    )
    .join("/");
}

function formatKeys(keys: KeyId[]): string {
  if (keys.length === 0) {
    return "";
  }
  return formatKeyText(keys.join("/"));
}

export function keyText(keybinding: Keybinding): string {
  return formatKeys(getKeybindings().getKeys(keybinding));
}

export function keyHint(keybinding: Keybinding, description: string): string {
  return theme.fg("dim", keyText(keybinding)) + theme.fg("muted", ` ${description}`);
}