@narumitw/pi-starship 0.55.0 → 0.55.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/README.md +21 -36
  2. package/dist/chunks/{chunk-UX6PBXVK.js → chunk-JO5PH6FN.js} +28 -110
  3. package/dist/chunks/chunk-JO5PH6FN.js.map +7 -0
  4. package/dist/chunks/{chunk-P4XMFSQW.js → chunk-YWY5RIDQ.js} +3 -7
  5. package/dist/chunks/chunk-YWY5RIDQ.js.map +7 -0
  6. package/dist/chunks/{chunk-EOGXAMTA.js → chunk-ZQZSXXPI.js} +1 -1
  7. package/dist/chunks/chunk-ZQZSXXPI.js.map +7 -0
  8. package/dist/chunks/{cloud-BKHYWCTA.js → cloud-C4VU3TX3.js} +7 -14
  9. package/dist/chunks/cloud-C4VU3TX3.js.map +7 -0
  10. package/dist/chunks/{commands-53ZO2JUK.js → commands-ATILSUVK.js} +13 -42
  11. package/dist/chunks/commands-ATILSUVK.js.map +7 -0
  12. package/dist/chunks/{deployment-RKKOEQQ2.js → deployment-FMNTYRBW.js} +6 -21
  13. package/dist/chunks/deployment-FMNTYRBW.js.map +7 -0
  14. package/dist/chunks/{development-BERD42HW.js → development-OUYXDPBS.js} +4 -8
  15. package/dist/chunks/development-OUYXDPBS.js.map +7 -0
  16. package/dist/chunks/{execution-42JTEY3N.js → execution-HJOGLMWD.js} +3 -3
  17. package/dist/chunks/execution-HJOGLMWD.js.map +7 -0
  18. package/dist/chunks/{languages-RMP6DW7H.js → languages-WXMF4GOF.js} +6 -22
  19. package/dist/chunks/languages-WXMF4GOF.js.map +7 -0
  20. package/dist/chunks/{package-LG5H7BBM.js → package-YXRZQAOV.js} +5 -14
  21. package/dist/chunks/package-YXRZQAOV.js.map +7 -0
  22. package/dist/index.ts +38 -53
  23. package/dist/index.ts.map +2 -2
  24. package/package.json +60 -61
  25. package/skills/configuring-pi-starship/references/runtime-and-security.md +5 -1
  26. package/skills/configuring-pi-starship/scripts/apply.mjs +43 -47
  27. package/skills/configuring-pi-starship/scripts/config-path.mjs +3 -3
  28. package/skills/configuring-pi-starship/scripts/script-support.mjs +6 -6
  29. package/skills/configuring-pi-starship/scripts/validate.mjs +18 -18
  30. package/src/command-configuration.ts +267 -286
  31. package/src/command-contract.ts +6 -6
  32. package/src/command-inspector.ts +27 -27
  33. package/src/command-preset-picker.ts +45 -50
  34. package/src/command-preview.ts +153 -166
  35. package/src/commands.ts +588 -618
  36. package/src/config.ts +580 -660
  37. package/src/effective-config.ts +46 -48
  38. package/src/format/formatter.ts +211 -227
  39. package/src/format/style.ts +205 -216
  40. package/src/modules/activity.ts +74 -74
  41. package/src/modules/brand.ts +9 -9
  42. package/src/modules/cache.ts +18 -18
  43. package/src/modules/catalog.ts +79 -83
  44. package/src/modules/cloud.ts +54 -54
  45. package/src/modules/context.ts +27 -27
  46. package/src/modules/cost.ts +23 -23
  47. package/src/modules/deployment.ts +45 -45
  48. package/src/modules/development.ts +80 -81
  49. package/src/modules/directory.ts +89 -113
  50. package/src/modules/display.ts +9 -9
  51. package/src/modules/execution.ts +62 -69
  52. package/src/modules/extension-status.ts +59 -64
  53. package/src/modules/fill.ts +10 -10
  54. package/src/modules/git/branch.ts +26 -26
  55. package/src/modules/git/commit.ts +21 -23
  56. package/src/modules/git/metrics.ts +22 -22
  57. package/src/modules/git/runtime.ts +299 -334
  58. package/src/modules/git/state.ts +17 -17
  59. package/src/modules/git/status.ts +77 -79
  60. package/src/modules/git/worktree.ts +10 -12
  61. package/src/modules/github-pr.ts +20 -20
  62. package/src/modules/helpers.ts +3 -3
  63. package/src/modules/index.ts +21 -21
  64. package/src/modules/inspection.ts +101 -108
  65. package/src/modules/languages.ts +52 -59
  66. package/src/modules/model.ts +57 -67
  67. package/src/modules/package.ts +12 -12
  68. package/src/modules/provider.ts +22 -24
  69. package/src/modules/render.ts +124 -140
  70. package/src/modules/thinking.ts +27 -26
  71. package/src/modules/time.ts +10 -13
  72. package/src/modules/tokens.ts +13 -13
  73. package/src/modules/truncation.ts +14 -17
  74. package/src/modules/turn.ts +9 -9
  75. package/src/modules/types.ts +125 -132
  76. package/src/modules/workspace-helpers.ts +4 -7
  77. package/src/pi-starship.ts +567 -571
  78. package/src/presets/catalog.ts +113 -113
  79. package/src/runtime/cloud.ts +122 -150
  80. package/src/runtime/command.ts +106 -108
  81. package/src/runtime/deployment.ts +150 -179
  82. package/src/runtime/development.ts +107 -124
  83. package/src/runtime/execution.ts +110 -124
  84. package/src/runtime/github-pr.ts +223 -252
  85. package/src/runtime/helpers.ts +186 -199
  86. package/src/runtime/languages.ts +149 -180
  87. package/src/runtime/package.ts +74 -87
  88. package/src/runtime/refresh-controller.ts +82 -86
  89. package/src/runtime/types.ts +38 -38
  90. package/src/runtime/workspace.ts +108 -116
  91. package/src/usage.ts +40 -40
  92. package/dist/chunks/chunk-EOGXAMTA.js.map +0 -7
  93. package/dist/chunks/chunk-P4XMFSQW.js.map +0 -7
  94. package/dist/chunks/chunk-UX6PBXVK.js.map +0 -7
  95. package/dist/chunks/cloud-BKHYWCTA.js.map +0 -7
  96. package/dist/chunks/commands-53ZO2JUK.js.map +0 -7
  97. package/dist/chunks/deployment-RKKOEQQ2.js.map +0 -7
  98. package/dist/chunks/development-BERD42HW.js.map +0 -7
  99. package/dist/chunks/execution-42JTEY3N.js.map +0 -7
  100. package/dist/chunks/languages-RMP6DW7H.js.map +0 -7
  101. package/dist/chunks/package-LG5H7BBM.js.map +0 -7
@@ -2,40 +2,40 @@ import { stripVTControlCharacters } from "node:util";
2
2
  import type { StatuslineInspection } from "./modules/inspection.js";
3
3
 
4
4
  export function formatFooterExplanation(inspection: StatuslineInspection | undefined): string {
5
- if (!inspection) {
6
- return safeLines([
7
- "Footer inspection is unavailable until the TUI footer is ready.",
8
- "No collection work was started.",
9
- ]);
10
- }
11
- if (inspection.showing.length === 0) {
12
- return safeLines([
13
- "No modules are currently showing.",
14
- "Open Modules to inspect empty, disabled, or unreachable modules.",
15
- ]);
16
- }
17
- return safeLines(
18
- inspection.showing.flatMap((module, index) => [
19
- ...(index > 0 ? [""] : []),
20
- module.name,
21
- ...previewLines(module.preview),
22
- module.description,
23
- ]),
24
- );
5
+ if (!inspection) {
6
+ return safeLines([
7
+ "Footer inspection is unavailable until the TUI footer is ready.",
8
+ "No collection work was started.",
9
+ ]);
10
+ }
11
+ if (inspection.showing.length === 0) {
12
+ return safeLines([
13
+ "No modules are currently showing.",
14
+ "Open Modules to inspect empty, disabled, or unreachable modules.",
15
+ ]);
16
+ }
17
+ return safeLines(
18
+ inspection.showing.flatMap((module, index) => [
19
+ ...(index > 0 ? [""] : []),
20
+ module.name,
21
+ ...previewLines(module.preview),
22
+ module.description,
23
+ ]),
24
+ );
25
25
  }
26
26
 
27
27
  function previewLines(preview: string): string[] {
28
- const lines = preview ? preview.split("\n") : ["(no text)"];
29
- return lines.map((line, index) => `${index === 0 ? "Value: " : " "}${line}`);
28
+ const lines = preview ? preview.split("\n") : ["(no text)"];
29
+ return lines.map((line, index) => `${index === 0 ? "Value: " : " "}${line}`);
30
30
  }
31
31
 
32
32
  function safeLines(lines: readonly string[]): string {
33
- return lines.map(safeDisplayText).join("\n");
33
+ return lines.map(safeDisplayText).join("\n");
34
34
  }
35
35
 
36
36
  function safeDisplayText(value: string): string {
37
- return Array.from(stripVTControlCharacters(value), (character) => {
38
- const codePoint = character.codePointAt(0) ?? 0;
39
- return codePoint <= 0x1f || (codePoint >= 0x7f && codePoint <= 0x9f) ? "" : character;
40
- }).join("");
37
+ return Array.from(stripVTControlCharacters(value), (character) => {
38
+ const codePoint = character.codePointAt(0) ?? 0;
39
+ return codePoint <= 0x1f || (codePoint >= 0x7f && codePoint <= 0x9f) ? "" : character;
40
+ }).join("");
41
41
  }
@@ -3,60 +3,55 @@ import { runLiveChoice } from "@narumitw/pi-tui-kit";
3
3
  import type { StarshipPreset } from "./presets/catalog.js";
4
4
 
5
5
  export type PresetPickerResult =
6
- | { kind: "apply"; presetId: StarshipPreset["id"] }
7
- | { kind: "customize"; presetId: StarshipPreset["id"] }
8
- | { kind: "back" }
9
- | { kind: "close" };
6
+ | { kind: "apply"; presetId: StarshipPreset["id"] }
7
+ | { kind: "customize"; presetId: StarshipPreset["id"] }
8
+ | { kind: "back" }
9
+ | { kind: "close" };
10
10
 
11
11
  export interface PresetPickerOptions {
12
- presets: readonly StarshipPreset[];
13
- activePresetId?: StarshipPreset["id"];
14
- initialPresetId?: StarshipPreset["id"];
15
- signal: AbortSignal;
16
- isCurrent(): boolean;
17
- preview(preset: StarshipPreset): void;
12
+ presets: readonly StarshipPreset[];
13
+ activePresetId?: StarshipPreset["id"];
14
+ initialPresetId?: StarshipPreset["id"];
15
+ signal: AbortSignal;
16
+ isCurrent(): boolean;
17
+ preview(preset: StarshipPreset): void;
18
18
  }
19
19
 
20
20
  export async function showPresetPicker(
21
- ctx: ExtensionCommandContext,
22
- options: PresetPickerOptions,
21
+ ctx: ExtensionCommandContext,
22
+ options: PresetPickerOptions,
23
23
  ): Promise<PresetPickerResult> {
24
- const current =
25
- options.presets.find((preset) => preset.id === options.activePresetId)?.label ??
26
- "Custom configuration";
27
- const result = await runLiveChoice(ctx, {
28
- title: `Presets · current: ${current}`,
29
- items: options.presets.map((preset) => ({
30
- id: preset.id,
31
- label: preset.label,
32
- description:
33
- preset.id === options.activePresetId
34
- ? `Currently applied · ${preset.description}`
35
- : preset.description,
36
- details: [
37
- `Selected: ${preset.label} · ${preset.requiresNerdFont ? "requires Nerd Font" : "font-safe"}`,
38
- ],
39
- confirmationDisabled: preset.id === options.activePresetId,
40
- confirmationDisabledReason: "Already applied; press e to customize",
41
- })),
42
- currentItemId: options.activePresetId,
43
- initialItemId: options.initialPresetId ?? options.activePresetId,
44
- viewportSize: Math.min(options.presets.length, 10),
45
- hint: "back",
46
- navigationLabel: "live preview",
47
- confirmLabel: "apply",
48
- shortcuts: [{ id: "customize", keys: ["e", "shift+e"], label: "customize" }],
49
- onSelectionChange: ({ item }) => {
50
- const preset = options.presets.find((candidate) => candidate.id === item.id);
51
- if (preset) options.preview(preset);
52
- },
53
- signal: options.signal,
54
- isCurrent: options.isCurrent,
55
- });
56
- if (result.kind === "selected") return { kind: "apply", presetId: result.itemId };
57
- if (result.kind === "shortcut") {
58
- return { kind: "customize", presetId: result.itemId };
59
- }
60
- if (result.kind === "closed" && result.reason === "back") return { kind: "back" };
61
- return { kind: "close" };
24
+ const current =
25
+ options.presets.find((preset) => preset.id === options.activePresetId)?.label ?? "Custom configuration";
26
+ const result = await runLiveChoice(ctx, {
27
+ title: `Presets · current: ${current}`,
28
+ items: options.presets.map((preset) => ({
29
+ id: preset.id,
30
+ label: preset.label,
31
+ description:
32
+ preset.id === options.activePresetId ? `Currently applied · ${preset.description}` : preset.description,
33
+ details: [`Selected: ${preset.label} · ${preset.requiresNerdFont ? "requires Nerd Font" : "font-safe"}`],
34
+ confirmationDisabled: preset.id === options.activePresetId,
35
+ confirmationDisabledReason: "Already applied; press e to customize",
36
+ })),
37
+ currentItemId: options.activePresetId,
38
+ initialItemId: options.initialPresetId ?? options.activePresetId,
39
+ viewportSize: Math.min(options.presets.length, 10),
40
+ hint: "back",
41
+ navigationLabel: "live preview",
42
+ confirmLabel: "apply",
43
+ shortcuts: [{ id: "customize", keys: ["e", "shift+e"], label: "customize" }],
44
+ onSelectionChange: ({ item }) => {
45
+ const preset = options.presets.find((candidate) => candidate.id === item.id);
46
+ if (preset) options.preview(preset);
47
+ },
48
+ signal: options.signal,
49
+ isCurrent: options.isCurrent,
50
+ });
51
+ if (result.kind === "selected") return { kind: "apply", presetId: result.itemId };
52
+ if (result.kind === "shortcut") {
53
+ return { kind: "customize", presetId: result.itemId };
54
+ }
55
+ if (result.kind === "closed" && result.reason === "back") return { kind: "back" };
56
+ return { kind: "close" };
62
57
  }
@@ -6,199 +6,186 @@ import { runCustomInteraction } from "@narumitw/pi-tui-kit";
6
6
  const RESERVED_HOST_ROWS = 3;
7
7
 
8
8
  export interface PreviewMenuItem<Value extends string> {
9
- value: Value;
10
- label: string;
9
+ value: Value;
10
+ label: string;
11
11
  }
12
12
 
13
13
  export type PreviewMenuResult<Value extends string> =
14
- | { kind: "selected"; value: Value }
15
- | { kind: "cancelled" }
16
- | { kind: "closed" };
14
+ | { kind: "selected"; value: Value }
15
+ | { kind: "cancelled" }
16
+ | { kind: "closed" };
17
17
 
18
18
  export async function showPreviewActionMenu<Value extends string>(
19
- ctx: ExtensionCommandContext,
20
- title: string,
21
- body: (width: number) => readonly string[],
22
- items: readonly PreviewMenuItem<Value>[],
23
- signal?: AbortSignal,
24
- isCurrent: () => boolean = () => !signal?.aborted,
19
+ ctx: ExtensionCommandContext,
20
+ title: string,
21
+ body: (width: number) => readonly string[],
22
+ items: readonly PreviewMenuItem<Value>[],
23
+ signal?: AbortSignal,
24
+ isCurrent: () => boolean = () => !signal?.aborted,
25
25
  ): Promise<PreviewMenuResult<Value> | undefined> {
26
- if (signal?.aborted || !isCurrent()) return { kind: "closed" };
27
- const result = await runCustomInteraction<PreviewMenuResult<Value>>(ctx, {
28
- signal,
29
- isCurrent,
30
- create: ({ tui, theme, keybindings, complete }) => {
31
- let selectedIndex = 0;
32
- let scrollOffset = 0;
33
- let lastMaximumScroll = 0;
34
- let lastViewportSize = 1;
35
- let disposed = false;
26
+ if (signal?.aborted || !isCurrent()) return { kind: "closed" };
27
+ const result = await runCustomInteraction<PreviewMenuResult<Value>>(ctx, {
28
+ signal,
29
+ isCurrent,
30
+ create: ({ tui, theme, keybindings, complete }) => {
31
+ let selectedIndex = 0;
32
+ let scrollOffset = 0;
33
+ let lastMaximumScroll = 0;
34
+ let lastViewportSize = 1;
35
+ let disposed = false;
36
36
 
37
- const requestRender = () => {
38
- if (!disposed) tui.requestRender();
39
- };
40
- const moveSelection = (delta: number) => {
41
- if (items.length === 0) return;
42
- selectedIndex = (selectedIndex + delta + items.length) % items.length;
43
- requestRender();
44
- };
45
- const movePreview = (offset: number) => {
46
- scrollOffset = Math.max(0, Math.min(offset, lastMaximumScroll));
47
- requestRender();
48
- };
37
+ const requestRender = () => {
38
+ if (!disposed) tui.requestRender();
39
+ };
40
+ const moveSelection = (delta: number) => {
41
+ if (items.length === 0) return;
42
+ selectedIndex = (selectedIndex + delta + items.length) % items.length;
43
+ requestRender();
44
+ };
45
+ const movePreview = (offset: number) => {
46
+ scrollOffset = Math.max(0, Math.min(offset, lastMaximumScroll));
47
+ requestRender();
48
+ };
49
49
 
50
- return {
51
- render(width: number): string[] {
52
- const safeWidth = Math.max(1, width);
53
- const terminalRows = Number.isFinite(tui.terminal.rows)
54
- ? Math.floor(tui.terminal.rows)
55
- : 24;
56
- const availableRows = Math.max(1, terminalRows - RESERVED_HOST_ROWS);
57
- const bodyLines = body(safeWidth).flatMap((line) =>
58
- line ? wrapTextWithAnsi(line, safeWidth) : [""],
59
- );
60
- const layout = allocateLayout(availableRows, items.length, bodyLines.length);
61
- lastViewportSize = layout.previewRows;
62
- lastMaximumScroll = Math.max(0, bodyLines.length - layout.previewRows);
63
- scrollOffset = Math.max(0, Math.min(scrollOffset, lastMaximumScroll));
64
- const actionStart = actionWindowStart(selectedIndex, items.length, layout.actionRows);
65
- const actionLines = items
66
- .slice(actionStart, actionStart + layout.actionRows)
67
- .map((item, index) => {
68
- const absoluteIndex = actionStart + index;
69
- const prefix = absoluteIndex === selectedIndex ? "→ " : " ";
70
- return theme.fg(
71
- absoluteIndex === selectedIndex ? "accent" : "text",
72
- `${prefix}${safeDisplayText(item.label)}`,
73
- );
74
- });
75
- const position = layout.positionRows
76
- ? [theme.fg("dim", previewPosition(scrollOffset, layout.previewRows, bodyLines.length))]
77
- : [];
78
- const lines = [
79
- ...(layout.titleRows ? [theme.fg("accent", theme.bold(safeDisplayText(title)))] : []),
80
- ...bodyLines.slice(scrollOffset, scrollOffset + layout.previewRows),
81
- ...position,
82
- ...actionLines,
83
- ...(layout.hintRows ? [theme.fg("dim", previewHint(keybindings))] : []),
84
- ];
85
- return lines.map((line) => truncateToWidth(line, safeWidth, ""));
86
- },
87
- invalidate() {},
88
- handleInput(data: string) {
89
- if (disposed) return;
90
- if (matchesKey(data, Key.ctrl("c"))) {
91
- complete({ kind: "closed" });
92
- } else if (keybindings.matches(data, "tui.select.cancel")) {
93
- complete({ kind: "cancelled" });
94
- } else if (keybindings.matches(data, "tui.select.up")) {
95
- moveSelection(-1);
96
- } else if (keybindings.matches(data, "tui.select.down")) {
97
- moveSelection(1);
98
- } else if (keybindings.matches(data, "tui.select.pageUp")) {
99
- movePreview(scrollOffset - lastViewportSize);
100
- } else if (keybindings.matches(data, "tui.select.pageDown")) {
101
- movePreview(scrollOffset + lastViewportSize);
102
- } else if (matchesKey(data, Key.home)) {
103
- movePreview(0);
104
- } else if (matchesKey(data, Key.end)) {
105
- movePreview(lastMaximumScroll);
106
- } else if (keybindings.matches(data, "tui.select.confirm")) {
107
- const item = items[selectedIndex];
108
- if (item) complete({ kind: "selected", value: item.value });
109
- }
110
- },
111
- dispose() {
112
- if (disposed) return;
113
- disposed = true;
114
- },
115
- };
116
- },
117
- });
118
- if (result.kind === "completed") return result.value;
119
- if (result.kind === "error") throw result.error;
120
- if (result.kind === "stale" && (signal?.aborted || !isCurrent())) return { kind: "closed" };
121
- return undefined;
50
+ return {
51
+ render(width: number): string[] {
52
+ const safeWidth = Math.max(1, width);
53
+ const terminalRows = Number.isFinite(tui.terminal.rows) ? Math.floor(tui.terminal.rows) : 24;
54
+ const availableRows = Math.max(1, terminalRows - RESERVED_HOST_ROWS);
55
+ const bodyLines = body(safeWidth).flatMap((line) => (line ? wrapTextWithAnsi(line, safeWidth) : [""]));
56
+ const layout = allocateLayout(availableRows, items.length, bodyLines.length);
57
+ lastViewportSize = layout.previewRows;
58
+ lastMaximumScroll = Math.max(0, bodyLines.length - layout.previewRows);
59
+ scrollOffset = Math.max(0, Math.min(scrollOffset, lastMaximumScroll));
60
+ const actionStart = actionWindowStart(selectedIndex, items.length, layout.actionRows);
61
+ const actionLines = items.slice(actionStart, actionStart + layout.actionRows).map((item, index) => {
62
+ const absoluteIndex = actionStart + index;
63
+ const prefix = absoluteIndex === selectedIndex ? "→ " : " ";
64
+ return theme.fg(
65
+ absoluteIndex === selectedIndex ? "accent" : "text",
66
+ `${prefix}${safeDisplayText(item.label)}`,
67
+ );
68
+ });
69
+ const position = layout.positionRows
70
+ ? [theme.fg("dim", previewPosition(scrollOffset, layout.previewRows, bodyLines.length))]
71
+ : [];
72
+ const lines = [
73
+ ...(layout.titleRows ? [theme.fg("accent", theme.bold(safeDisplayText(title)))] : []),
74
+ ...bodyLines.slice(scrollOffset, scrollOffset + layout.previewRows),
75
+ ...position,
76
+ ...actionLines,
77
+ ...(layout.hintRows ? [theme.fg("dim", previewHint(keybindings))] : []),
78
+ ];
79
+ return lines.map((line) => truncateToWidth(line, safeWidth, ""));
80
+ },
81
+ invalidate() {},
82
+ handleInput(data: string) {
83
+ if (disposed) return;
84
+ if (matchesKey(data, Key.ctrl("c"))) {
85
+ complete({ kind: "closed" });
86
+ } else if (keybindings.matches(data, "tui.select.cancel")) {
87
+ complete({ kind: "cancelled" });
88
+ } else if (keybindings.matches(data, "tui.select.up")) {
89
+ moveSelection(-1);
90
+ } else if (keybindings.matches(data, "tui.select.down")) {
91
+ moveSelection(1);
92
+ } else if (keybindings.matches(data, "tui.select.pageUp")) {
93
+ movePreview(scrollOffset - lastViewportSize);
94
+ } else if (keybindings.matches(data, "tui.select.pageDown")) {
95
+ movePreview(scrollOffset + lastViewportSize);
96
+ } else if (matchesKey(data, Key.home)) {
97
+ movePreview(0);
98
+ } else if (matchesKey(data, Key.end)) {
99
+ movePreview(lastMaximumScroll);
100
+ } else if (keybindings.matches(data, "tui.select.confirm")) {
101
+ const item = items[selectedIndex];
102
+ if (item) complete({ kind: "selected", value: item.value });
103
+ }
104
+ },
105
+ dispose() {
106
+ if (disposed) return;
107
+ disposed = true;
108
+ },
109
+ };
110
+ },
111
+ });
112
+ if (result.kind === "completed") return result.value;
113
+ if (result.kind === "error") throw result.error;
114
+ if (result.kind === "stale" && (signal?.aborted || !isCurrent())) return { kind: "closed" };
115
+ return undefined;
122
116
  }
123
117
 
124
118
  interface PreviewLayout {
125
- titleRows: number;
126
- previewRows: number;
127
- positionRows: number;
128
- actionRows: number;
129
- hintRows: number;
119
+ titleRows: number;
120
+ previewRows: number;
121
+ positionRows: number;
122
+ actionRows: number;
123
+ hintRows: number;
130
124
  }
131
125
 
132
- function allocateLayout(
133
- availableRows: number,
134
- actionCount: number,
135
- bodyLineCount: number,
136
- ): PreviewLayout {
137
- if (availableRows === 1) {
138
- return { titleRows: 0, previewRows: 0, positionRows: 0, actionRows: 1, hintRows: 0 };
139
- }
140
- const titleRows = availableRows >= 3 ? 1 : 0;
141
- const hintRows = availableRows >= 3 ? 1 : 0;
142
- const minimumPreviewRows = bodyLineCount > 0 && availableRows >= 4 ? 1 : 0;
143
- const availableActionRows = Math.max(
144
- 1,
145
- availableRows - titleRows - hintRows - minimumPreviewRows,
146
- );
147
- const actionRows = Math.min(Math.max(1, actionCount), availableActionRows);
148
- let previewRows = Math.max(0, availableRows - titleRows - hintRows - actionRows);
149
- const positionRows = previewRows >= 2 && bodyLineCount > previewRows ? 1 : 0;
150
- previewRows -= positionRows;
151
- return { titleRows, previewRows, positionRows, actionRows, hintRows };
126
+ function allocateLayout(availableRows: number, actionCount: number, bodyLineCount: number): PreviewLayout {
127
+ if (availableRows === 1) {
128
+ return { titleRows: 0, previewRows: 0, positionRows: 0, actionRows: 1, hintRows: 0 };
129
+ }
130
+ const titleRows = availableRows >= 3 ? 1 : 0;
131
+ const hintRows = availableRows >= 3 ? 1 : 0;
132
+ const minimumPreviewRows = bodyLineCount > 0 && availableRows >= 4 ? 1 : 0;
133
+ const availableActionRows = Math.max(1, availableRows - titleRows - hintRows - minimumPreviewRows);
134
+ const actionRows = Math.min(Math.max(1, actionCount), availableActionRows);
135
+ let previewRows = Math.max(0, availableRows - titleRows - hintRows - actionRows);
136
+ const positionRows = previewRows >= 2 && bodyLineCount > previewRows ? 1 : 0;
137
+ previewRows -= positionRows;
138
+ return { titleRows, previewRows, positionRows, actionRows, hintRows };
152
139
  }
153
140
 
154
141
  function actionWindowStart(selectedIndex: number, itemCount: number, viewportSize: number): number {
155
- if (itemCount <= viewportSize) return 0;
156
- return Math.max(0, Math.min(selectedIndex, itemCount - viewportSize));
142
+ if (itemCount <= viewportSize) return 0;
143
+ return Math.max(0, Math.min(selectedIndex, itemCount - viewportSize));
157
144
  }
158
145
 
159
146
  function previewPosition(offset: number, viewportSize: number, lineCount: number): string {
160
- if (lineCount === 0) return "0/0";
161
- return `${offset + 1}-${Math.min(lineCount, offset + viewportSize)}/${lineCount}`;
147
+ if (lineCount === 0) return "0/0";
148
+ return `${offset + 1}-${Math.min(lineCount, offset + viewportSize)}/${lineCount}`;
162
149
  }
163
150
 
164
151
  function previewHint(keybindings: Pick<KeybindingsManager, "getKeys">): string {
165
- const up = bindingText(keybindings, "tui.select.up");
166
- const down = bindingText(keybindings, "tui.select.down");
167
- const confirm = bindingText(keybindings, "tui.select.confirm");
168
- const cancel = bindingText(keybindings, "tui.select.cancel", "ctrl+c");
169
- const pageUp = bindingText(keybindings, "tui.select.pageUp");
170
- const pageDown = bindingText(keybindings, "tui.select.pageDown");
171
- return [
172
- ...(up || down ? [`${[up, down].filter(Boolean).join("/")} navigate`] : []),
173
- ...(confirm ? [`${confirm} select`] : []),
174
- ...(cancel ? [`${cancel} discard`] : []),
175
- "ctrl+c close",
176
- ...(pageUp || pageDown ? [`${[pageUp, pageDown].filter(Boolean).join("/")} preview`] : []),
177
- ].join(" • ");
152
+ const up = bindingText(keybindings, "tui.select.up");
153
+ const down = bindingText(keybindings, "tui.select.down");
154
+ const confirm = bindingText(keybindings, "tui.select.confirm");
155
+ const cancel = bindingText(keybindings, "tui.select.cancel", "ctrl+c");
156
+ const pageUp = bindingText(keybindings, "tui.select.pageUp");
157
+ const pageDown = bindingText(keybindings, "tui.select.pageDown");
158
+ return [
159
+ ...(up || down ? [`${[up, down].filter(Boolean).join("/")} navigate`] : []),
160
+ ...(confirm ? [`${confirm} select`] : []),
161
+ ...(cancel ? [`${cancel} discard`] : []),
162
+ "ctrl+c close",
163
+ ...(pageUp || pageDown ? [`${[pageUp, pageDown].filter(Boolean).join("/")} preview`] : []),
164
+ ].join(" • ");
178
165
  }
179
166
 
180
167
  function bindingText(
181
- keybindings: Pick<KeybindingsManager, "getKeys">,
182
- binding: Parameters<KeybindingsManager["getKeys"]>[0],
183
- excluded?: string,
168
+ keybindings: Pick<KeybindingsManager, "getKeys">,
169
+ binding: Parameters<KeybindingsManager["getKeys"]>[0],
170
+ excluded?: string,
184
171
  ): string {
185
- return keybindings
186
- .getKeys(binding)
187
- .filter((key) => key !== excluded)
188
- .map((key) => {
189
- if (key === "up") return "↑";
190
- if (key === "down") return "↓";
191
- if (key === "escape") return "esc";
192
- if (key === "return") return "enter";
193
- return safeDisplayText(key);
194
- })
195
- .join("/");
172
+ return keybindings
173
+ .getKeys(binding)
174
+ .filter((key) => key !== excluded)
175
+ .map((key) => {
176
+ if (key === "up") return "↑";
177
+ if (key === "down") return "↓";
178
+ if (key === "escape") return "esc";
179
+ if (key === "return") return "enter";
180
+ return safeDisplayText(key);
181
+ })
182
+ .join("/");
196
183
  }
197
184
 
198
185
  function safeDisplayText(value: string): string {
199
- return Array.from(stripVTControlCharacters(value), (character) => {
200
- const codePoint = character.codePointAt(0) ?? 0;
201
- const control = codePoint <= 0x1f || (codePoint >= 0x7f && codePoint <= 0x9f);
202
- return control ? "" : character;
203
- }).join("");
186
+ return Array.from(stripVTControlCharacters(value), (character) => {
187
+ const codePoint = character.codePointAt(0) ?? 0;
188
+ const control = codePoint <= 0x1f || (codePoint >= 0x7f && codePoint <= 0x9f);
189
+ return control ? "" : character;
190
+ }).join("");
204
191
  }