@pokit/prompter-clack 0.0.40 → 0.0.43
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.
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* Copies the autocomplete function from @clack/prompts but uses a patched
|
|
5
5
|
* AutocompletePrompt that wraps the cursor instead of clamping it.
|
|
6
6
|
*
|
|
7
|
-
* Upstream
|
|
8
|
-
* TODO: Remove this file once
|
|
7
|
+
* Upstream tracking: https://github.com/bombshell-dev/clack/issues
|
|
8
|
+
* TODO: Remove this file once cursor wrapping is available upstream.
|
|
9
9
|
*/
|
|
10
10
|
import type { Writable } from 'node:stream';
|
|
11
11
|
interface Option<Value> {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"autocomplete-prompt.d.ts","sourceRoot":"","sources":["../src/autocomplete-prompt.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAaH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"autocomplete-prompt.d.ts","sourceRoot":"","sources":["../src/autocomplete-prompt.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAaH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAuL5C,UAAU,MAAM,CAAC,KAAK;IACpB,KAAK,EAAE,KAAK,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAyBD,MAAM,WAAW,gBAAgB,CAAC,KAAK;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,KAAK,CAAC;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,EAAE,GAAG,SAAS,KAAK,MAAM,GAAG,KAAK,GAAG,SAAS,CAAC;IAC9E,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,OAAO,CAAC;IAC5D,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,KAAK,CAAC,EAAE,OAAO,aAAa,EAAE,QAAQ,CAAC;IACvC,MAAM,CAAC,EAAE,QAAQ,CAAC;CACnB;AAED,eAAO,MAAM,mBAAmB,GAAI,KAAK,EAAE,MAAM,gBAAgB,CAAC,KAAK,CAAC,KAuG5C,OAAO,CAAC,KAAK,GAAG,MAAM,CACjD,CAAC"}
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* Copies the autocomplete function from @clack/prompts but uses a patched
|
|
5
5
|
* AutocompletePrompt that wraps the cursor instead of clamping it.
|
|
6
6
|
*
|
|
7
|
-
* Upstream
|
|
8
|
-
* TODO: Remove this file once
|
|
7
|
+
* Upstream tracking: https://github.com/bombshell-dev/clack/issues
|
|
8
|
+
* TODO: Remove this file once cursor wrapping is available upstream.
|
|
9
9
|
*/
|
|
10
10
|
import { Prompt } from '@clack/core';
|
|
11
11
|
import { limitOptions, symbol, S_BAR, S_BAR_END, S_RADIO_ACTIVE, S_RADIO_INACTIVE, } from '@clack/prompts';
|
|
@@ -60,9 +60,7 @@ class PatchedAutocompletePrompt extends Prompt {
|
|
|
60
60
|
this.#filterFn = opts.filter ?? defaultFilter;
|
|
61
61
|
let initialValues;
|
|
62
62
|
if (opts.initialValue && Array.isArray(opts.initialValue)) {
|
|
63
|
-
initialValues = this.multiple
|
|
64
|
-
? opts.initialValue
|
|
65
|
-
: opts.initialValue.slice(0, 1);
|
|
63
|
+
initialValues = this.multiple ? opts.initialValue : opts.initialValue.slice(0, 1);
|
|
66
64
|
}
|
|
67
65
|
else if (!this.multiple && this.options.length > 0) {
|
|
68
66
|
initialValues = [this.options[0].value];
|
|
@@ -95,7 +93,7 @@ class PatchedAutocompletePrompt extends Prompt {
|
|
|
95
93
|
if (isUpKey || isDownKey) {
|
|
96
94
|
const length = this.filteredOptions.length;
|
|
97
95
|
if (length > 0) {
|
|
98
|
-
this.#cursor = ((this.#cursor + (isUpKey ? -1 : 1)) % length + length) % length;
|
|
96
|
+
this.#cursor = (((this.#cursor + (isUpKey ? -1 : 1)) % length) + length) % length;
|
|
99
97
|
}
|
|
100
98
|
this.focusedValue = this.filteredOptions[this.#cursor]?.value;
|
|
101
99
|
if (!this.multiple) {
|
|
@@ -188,8 +186,7 @@ export const patchedAutocomplete = (opts) => {
|
|
|
188
186
|
options: opts.options,
|
|
189
187
|
initialValue: opts.initialValue ? [opts.initialValue] : undefined,
|
|
190
188
|
initialUserInput: opts.initialUserInput,
|
|
191
|
-
filter: opts.filter ??
|
|
192
|
-
((search, opt) => getFilteredOption(search, opt)),
|
|
189
|
+
filter: opts.filter ?? ((search, opt) => getFilteredOption(search, opt)),
|
|
193
190
|
signal: opts.signal,
|
|
194
191
|
input: opts.input,
|
|
195
192
|
output: opts.output,
|
|
@@ -207,9 +204,7 @@ export const patchedAutocomplete = (opts) => {
|
|
|
207
204
|
return `${headings.join('\n')}\n${color.gray(S_BAR)}${label}`;
|
|
208
205
|
}
|
|
209
206
|
case 'cancel': {
|
|
210
|
-
const userInputText = userInput
|
|
211
|
-
? ` ${color.strikethrough(color.dim(userInput))}`
|
|
212
|
-
: '';
|
|
207
|
+
const userInputText = userInput ? ` ${color.strikethrough(color.dim(userInput))}` : '';
|
|
213
208
|
return `${headings.join('\n')}\n${color.gray(S_BAR)}${userInputText}`;
|
|
214
209
|
}
|
|
215
210
|
default: {
|
|
@@ -238,10 +233,7 @@ export const patchedAutocomplete = (opts) => {
|
|
|
238
233
|
`${color.dim('Enter:')} confirm`,
|
|
239
234
|
`${color.dim('Type:')} to search`,
|
|
240
235
|
];
|
|
241
|
-
const footers = [
|
|
242
|
-
`${guidePrefix}${instructions.join(' • ')}`,
|
|
243
|
-
guidePrefixEnd,
|
|
244
|
-
];
|
|
236
|
+
const footers = [`${guidePrefix}${instructions.join(' • ')}`, guidePrefixEnd];
|
|
245
237
|
const displayOptions = this.filteredOptions.length === 0
|
|
246
238
|
? []
|
|
247
239
|
: limitOptions({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pokit/prompter-clack",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.43",
|
|
4
4
|
"description": "Clack-based prompter adapter for pok CLI applications",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@types/bun": "latest"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@pokit/core": "0.0.
|
|
56
|
+
"@pokit/core": "0.0.43"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"bun": ">=1.0.0"
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* Copies the autocomplete function from @clack/prompts but uses a patched
|
|
5
5
|
* AutocompletePrompt that wraps the cursor instead of clamping it.
|
|
6
6
|
*
|
|
7
|
-
* Upstream
|
|
8
|
-
* TODO: Remove this file once
|
|
7
|
+
* Upstream tracking: https://github.com/bombshell-dev/clack/issues
|
|
8
|
+
* TODO: Remove this file once cursor wrapping is available upstream.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import type { Key } from 'node:readline';
|
|
@@ -45,16 +45,16 @@ function defaultFilter<T extends OptionLike>(input: string, option: T): boolean
|
|
|
45
45
|
return label.toLowerCase().includes(input.toLowerCase());
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
interface AutocompletePromptOptions<T extends OptionLike>
|
|
49
|
-
|
|
48
|
+
interface AutocompletePromptOptions<T extends OptionLike> extends PromptOptions<
|
|
49
|
+
T['value'] | T['value'][],
|
|
50
|
+
PatchedAutocompletePrompt<T>
|
|
51
|
+
> {
|
|
50
52
|
options: T[] | ((this: PatchedAutocompletePrompt<T>) => T[]);
|
|
51
53
|
filter?: FilterFunction<T>;
|
|
52
54
|
multiple?: boolean;
|
|
53
55
|
}
|
|
54
56
|
|
|
55
|
-
class PatchedAutocompletePrompt<T extends OptionLike> extends Prompt<
|
|
56
|
-
T['value'] | T['value'][]
|
|
57
|
-
> {
|
|
57
|
+
class PatchedAutocompletePrompt<T extends OptionLike> extends Prompt<T['value'] | T['value'][]> {
|
|
58
58
|
filteredOptions: T[];
|
|
59
59
|
multiple: boolean;
|
|
60
60
|
isNavigating = false;
|
|
@@ -98,9 +98,7 @@ class PatchedAutocompletePrompt<T extends OptionLike> extends Prompt<
|
|
|
98
98
|
|
|
99
99
|
let initialValues: unknown[] | undefined;
|
|
100
100
|
if (opts.initialValue && Array.isArray(opts.initialValue)) {
|
|
101
|
-
initialValues = this.multiple
|
|
102
|
-
? opts.initialValue
|
|
103
|
-
: opts.initialValue.slice(0, 1);
|
|
101
|
+
initialValues = this.multiple ? opts.initialValue : opts.initialValue.slice(0, 1);
|
|
104
102
|
} else if (!this.multiple && this.options.length > 0) {
|
|
105
103
|
initialValues = [this.options[0].value];
|
|
106
104
|
}
|
|
@@ -139,7 +137,7 @@ class PatchedAutocompletePrompt<T extends OptionLike> extends Prompt<
|
|
|
139
137
|
if (isUpKey || isDownKey) {
|
|
140
138
|
const length = this.filteredOptions.length;
|
|
141
139
|
if (length > 0) {
|
|
142
|
-
this.#cursor = ((this.#cursor + (isUpKey ? -1 : 1)) % length + length) % length;
|
|
140
|
+
this.#cursor = (((this.#cursor + (isUpKey ? -1 : 1)) % length) + length) % length;
|
|
143
141
|
}
|
|
144
142
|
this.focusedValue = this.filteredOptions[this.#cursor]?.value;
|
|
145
143
|
if (!this.multiple) {
|
|
@@ -252,9 +250,7 @@ export const patchedAutocomplete = <Value>(opts: AutocompleteOpts<Value>) => {
|
|
|
252
250
|
options: opts.options,
|
|
253
251
|
initialValue: opts.initialValue ? [opts.initialValue] : undefined,
|
|
254
252
|
initialUserInput: opts.initialUserInput,
|
|
255
|
-
filter:
|
|
256
|
-
opts.filter ??
|
|
257
|
-
((search: string, opt: Option<Value>) => getFilteredOption(search, opt)),
|
|
253
|
+
filter: opts.filter ?? ((search: string, opt: Option<Value>) => getFilteredOption(search, opt)),
|
|
258
254
|
signal: opts.signal,
|
|
259
255
|
input: opts.input,
|
|
260
256
|
output: opts.output,
|
|
@@ -274,9 +270,7 @@ export const patchedAutocomplete = <Value>(opts: AutocompleteOpts<Value>) => {
|
|
|
274
270
|
return `${headings.join('\n')}\n${color.gray(S_BAR)}${label}`;
|
|
275
271
|
}
|
|
276
272
|
case 'cancel': {
|
|
277
|
-
const userInputText = userInput
|
|
278
|
-
? ` ${color.strikethrough(color.dim(userInput))}`
|
|
279
|
-
: '';
|
|
273
|
+
const userInputText = userInput ? ` ${color.strikethrough(color.dim(userInput))}` : '';
|
|
280
274
|
return `${headings.join('\n')}\n${color.gray(S_BAR)}${userInputText}`;
|
|
281
275
|
}
|
|
282
276
|
default: {
|
|
@@ -320,10 +314,7 @@ export const patchedAutocomplete = <Value>(opts: AutocompleteOpts<Value>) => {
|
|
|
320
314
|
`${color.dim('Type:')} to search`,
|
|
321
315
|
];
|
|
322
316
|
|
|
323
|
-
const footers = [
|
|
324
|
-
`${guidePrefix}${instructions.join(' • ')}`,
|
|
325
|
-
guidePrefixEnd,
|
|
326
|
-
];
|
|
317
|
+
const footers = [`${guidePrefix}${instructions.join(' • ')}`, guidePrefixEnd];
|
|
327
318
|
|
|
328
319
|
const displayOptions =
|
|
329
320
|
this.filteredOptions.length === 0
|