@pi-unipi/ask-user 2.6.1 → 2.6.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 (2) hide show
  1. package/package.json +7 -3
  2. package/settings-tui.ts +18 -34
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-unipi/ask-user",
3
- "version": "2.6.1",
3
+ "version": "2.6.2",
4
4
  "description": "Structured user input tool for Pi coding agent — single-select, multi-select, freeform",
5
5
  "type": "module",
6
6
  "main": "index.ts",
@@ -48,8 +48,12 @@
48
48
  "typebox": "^1.1.38"
49
49
  },
50
50
  "pi": {
51
- "extensions": [],
52
- "skills": [],
51
+ "extensions": [
52
+ "./index.ts"
53
+ ],
54
+ "skills": [
55
+ "./skills"
56
+ ],
53
57
  "prompts": [],
54
58
  "themes": []
55
59
  }
package/settings-tui.ts CHANGED
@@ -6,26 +6,13 @@
6
6
  */
7
7
 
8
8
  import type { Component } from "@earendil-works/pi-tui";
9
- import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
10
- import { adaptiveInnerWidth, normalizeWidth, safeRepeat, shouldRenderBorder } from "@pi-unipi/core";
9
+ import { Key, matchesKey, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
10
+ import { adaptiveInnerWidth, normalizeWidth, safeRepeat, shouldRenderBorder, ansi, TOGGLE_ON, TOGGLE_OFF } from "@pi-unipi/core";
11
11
  import { getAskUserSettings, saveAskUserSettings, type AskUserSettings } from "./config.js";
12
12
 
13
13
  /** ANSI escape codes */
14
- const ansi = {
15
- reset: "\x1b[0m",
16
- bold: "\x1b[1m",
17
- dim: "\x1b[2m",
18
- // Colors
19
- cyan: "\x1b[36m",
20
- green: "\x1b[32m",
21
- yellow: "\x1b[33m",
22
- red: "\x1b[31m",
23
- gray: "\x1b[90m",
24
- };
25
14
 
26
15
  /** Toggle symbols */
27
- const TOGGLE_ON = `${ansi.green}●${ansi.reset}`;
28
- const TOGGLE_OFF = `${ansi.dim}○${ansi.reset}`;
29
16
 
30
17
  /** Setting items */
31
18
  interface SettingItem {
@@ -99,25 +86,22 @@ export class AskUserSettingsOverlay implements Component {
99
86
  * Handle keyboard input.
100
87
  */
101
88
  handleInput(data: string): void {
102
- switch (data) {
103
- case "\x1b[A": // Up
104
- case "k":
105
- this.selectedIndex = (this.selectedIndex - 1 + SETTINGS.length) % SETTINGS.length;
106
- break;
107
- case "\x1b[B": // Down
108
- case "j":
109
- this.selectedIndex = (this.selectedIndex + 1) % SETTINGS.length;
110
- break;
111
- case " ": // Space - toggle
112
- this.toggleSetting(SETTINGS[this.selectedIndex].key);
113
- break;
114
- case "\r": // Enter - save and close
115
- this.save();
116
- this.onClose?.();
117
- break;
118
- case "\x1b": // Escape - close without saving
119
- this.onClose?.();
120
- break;
89
+ if (matchesKey(data, Key.up) || data === "k") {
90
+ // Up
91
+ this.selectedIndex = (this.selectedIndex - 1 + SETTINGS.length) % SETTINGS.length;
92
+ } else if (matchesKey(data, Key.down) || data === "j") {
93
+ // Down
94
+ this.selectedIndex = (this.selectedIndex + 1) % SETTINGS.length;
95
+ } else if (matchesKey(data, Key.space)) {
96
+ // Space - toggle
97
+ this.toggleSetting(SETTINGS[this.selectedIndex].key);
98
+ } else if (matchesKey(data, Key.enter)) {
99
+ // Enter - save and close
100
+ this.save();
101
+ this.onClose?.();
102
+ } else if (matchesKey(data, Key.escape)) {
103
+ // Escape - close without saving
104
+ this.onClose?.();
121
105
  }
122
106
  }
123
107