@juicesharp/rpiv-ask-user-question 0.10.0 → 0.11.1
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.
- package/ask-user-question.ts +79 -35
- package/package.json +1 -1
package/ask-user-question.ts
CHANGED
|
@@ -113,41 +113,37 @@ export function registerAskUserQuestionTool(pi: ExtensionAPI): void {
|
|
|
113
113
|
handleInput: (data) => {
|
|
114
114
|
const currentItem = itemAt(selectionIndex, mainItems, chatItems);
|
|
115
115
|
const isInlineInputActive = !!currentItem?.isOther;
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
if (kb.matches(data, KEYBIND_CANCEL)) {
|
|
141
|
-
done(null);
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
if (isInlineInputActive) {
|
|
145
|
-
if (BACKSPACE_CHARS.has(data)) {
|
|
116
|
+
const action = dispatchQuestionInput(data, {
|
|
117
|
+
selectionIndex,
|
|
118
|
+
totalCount,
|
|
119
|
+
currentItem,
|
|
120
|
+
isInlineInputActive,
|
|
121
|
+
inputBuffer: mainList.getInputBuffer(),
|
|
122
|
+
keybindings: getKeybindings(),
|
|
123
|
+
});
|
|
124
|
+
switch (action.kind) {
|
|
125
|
+
case "nav":
|
|
126
|
+
if (isInlineInputActive) mainList.clearInputBuffer();
|
|
127
|
+
selectionIndex = action.nextIndex;
|
|
128
|
+
applySelection();
|
|
129
|
+
tui.requestRender();
|
|
130
|
+
return;
|
|
131
|
+
case "confirm":
|
|
132
|
+
done(action.choice);
|
|
133
|
+
return;
|
|
134
|
+
case "cancel":
|
|
135
|
+
done(null);
|
|
136
|
+
return;
|
|
137
|
+
case "backspace":
|
|
146
138
|
mainList.backspaceInput();
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
139
|
+
tui.requestRender();
|
|
140
|
+
return;
|
|
141
|
+
case "append":
|
|
142
|
+
mainList.appendInput(action.data);
|
|
143
|
+
tui.requestRender();
|
|
144
|
+
return;
|
|
145
|
+
case "ignore":
|
|
146
|
+
return;
|
|
151
147
|
}
|
|
152
148
|
},
|
|
153
149
|
};
|
|
@@ -177,7 +173,55 @@ export function wrapIndex(index: number, total: number): number {
|
|
|
177
173
|
return ((index % total) + total) % total;
|
|
178
174
|
}
|
|
179
175
|
|
|
180
|
-
|
|
176
|
+
export type QuestionInputAction =
|
|
177
|
+
| { kind: "nav"; nextIndex: number }
|
|
178
|
+
| { kind: "confirm"; choice: WrappingSelectItem }
|
|
179
|
+
| { kind: "cancel" }
|
|
180
|
+
| { kind: "backspace" }
|
|
181
|
+
| { kind: "append"; data: string }
|
|
182
|
+
| { kind: "ignore" };
|
|
183
|
+
|
|
184
|
+
export interface DispatchState {
|
|
185
|
+
selectionIndex: number;
|
|
186
|
+
totalCount: number;
|
|
187
|
+
currentItem: WrappingSelectItem | undefined;
|
|
188
|
+
isInlineInputActive: boolean;
|
|
189
|
+
inputBuffer: string;
|
|
190
|
+
keybindings: { matches(data: string, name: string): boolean };
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export function dispatchQuestionInput(data: string, state: DispatchState): QuestionInputAction {
|
|
194
|
+
const { keybindings: kb } = state;
|
|
195
|
+
if (kb.matches(data, KEYBIND_UP)) {
|
|
196
|
+
return { kind: "nav", nextIndex: wrapIndex(state.selectionIndex - 1, state.totalCount) };
|
|
197
|
+
}
|
|
198
|
+
if (kb.matches(data, KEYBIND_DOWN)) {
|
|
199
|
+
return { kind: "nav", nextIndex: wrapIndex(state.selectionIndex + 1, state.totalCount) };
|
|
200
|
+
}
|
|
201
|
+
if (kb.matches(data, KEYBIND_CONFIRM)) {
|
|
202
|
+
if (state.isInlineInputActive) {
|
|
203
|
+
return { kind: "confirm", choice: { label: state.inputBuffer, isOther: true } };
|
|
204
|
+
}
|
|
205
|
+
if (state.currentItem) {
|
|
206
|
+
return { kind: "confirm", choice: state.currentItem };
|
|
207
|
+
}
|
|
208
|
+
return { kind: "ignore" };
|
|
209
|
+
}
|
|
210
|
+
if (kb.matches(data, KEYBIND_CANCEL)) {
|
|
211
|
+
return { kind: "cancel" };
|
|
212
|
+
}
|
|
213
|
+
if (state.isInlineInputActive) {
|
|
214
|
+
if (BACKSPACE_CHARS.has(data)) {
|
|
215
|
+
return { kind: "backspace" };
|
|
216
|
+
}
|
|
217
|
+
if (data && !data.startsWith(ESC_SEQUENCE_PREFIX)) {
|
|
218
|
+
return { kind: "append", data };
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return { kind: "ignore" };
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export function buildDialogContainer(
|
|
181
225
|
theme: Theme,
|
|
182
226
|
params: QuestionParams,
|
|
183
227
|
mainList: WrappingSelect,
|
package/package.json
CHANGED