@shell-shock/plugin-prompts 0.3.51 → 0.3.52
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/dist/components/index.cjs +1 -0
- package/dist/components/index.d.cts +2 -2
- package/dist/components/index.d.mts +2 -2
- package/dist/components/index.mjs +2 -2
- package/dist/components/prompts-builtin.cjs +459 -55
- package/dist/components/prompts-builtin.d.cts +14 -11
- package/dist/components/prompts-builtin.d.cts.map +1 -1
- package/dist/components/prompts-builtin.d.mts +14 -11
- package/dist/components/prompts-builtin.d.mts.map +1 -1
- package/dist/components/prompts-builtin.mjs +459 -56
- package/dist/components/prompts-builtin.mjs.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/types/plugin.d.cts.map +1 -1
- package/dist/types/plugin.d.mts.map +1 -1
- package/package.json +12 -12
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { createComponent, createIntrinsic, mergeProps } from "@alloy-js/core/jsx-runtime";
|
|
2
2
|
import { Show, code, splitProps } from "@alloy-js/core";
|
|
3
3
|
import { FunctionDeclaration, VarDeclaration } from "@alloy-js/typescript";
|
|
4
|
-
import { ReflectionKind } from "@powerlines/deepkit/vendor/type";
|
|
5
4
|
import { Spacing } from "@powerlines/plugin-alloy/core/components/spacing";
|
|
6
5
|
import { BuiltinFile } from "@powerlines/plugin-alloy/typescript/components/builtin-file";
|
|
7
6
|
import { ClassDeclaration, ClassField, ClassMethod, ClassPropertyGet } from "@powerlines/plugin-alloy/typescript/components/class-declaration";
|
|
@@ -88,7 +87,7 @@ function BasePromptDeclarations() {
|
|
|
88
87
|
createComponent(Spacing, {}),
|
|
89
88
|
createComponent(InterfaceMember, {
|
|
90
89
|
name: "errorMessage",
|
|
91
|
-
|
|
90
|
+
required: false,
|
|
92
91
|
type: "string",
|
|
93
92
|
doc: "If the prompt is in an error state, this will contain the error message to display"
|
|
94
93
|
}),
|
|
@@ -126,14 +125,14 @@ function BasePromptDeclarations() {
|
|
|
126
125
|
return [
|
|
127
126
|
createComponent(InterfaceMember, {
|
|
128
127
|
name: "input",
|
|
129
|
-
|
|
128
|
+
required: false,
|
|
130
129
|
type: "NodeJS.ReadStream",
|
|
131
130
|
doc: "The readable stream to use for prompt input, defaults to process.stdin"
|
|
132
131
|
}),
|
|
133
132
|
createComponent(Spacing, {}),
|
|
134
133
|
createComponent(InterfaceMember, {
|
|
135
134
|
name: "output",
|
|
136
|
-
|
|
135
|
+
required: false,
|
|
137
136
|
type: "NodeJS.WriteStream",
|
|
138
137
|
doc: "The writable stream to use for prompt output, defaults to process.stdout"
|
|
139
138
|
}),
|
|
@@ -146,63 +145,63 @@ function BasePromptDeclarations() {
|
|
|
146
145
|
createComponent(Spacing, {}),
|
|
147
146
|
createComponent(InterfaceMember, {
|
|
148
147
|
name: "description",
|
|
149
|
-
|
|
148
|
+
required: false,
|
|
150
149
|
type: "string",
|
|
151
150
|
doc: "The prompt description message to display"
|
|
152
151
|
}),
|
|
153
152
|
createComponent(Spacing, {}),
|
|
154
153
|
createComponent(InterfaceMember, {
|
|
155
154
|
name: "initialValue",
|
|
156
|
-
|
|
155
|
+
required: false,
|
|
157
156
|
type: "TValue",
|
|
158
157
|
doc: "The initial value of the prompt"
|
|
159
158
|
}),
|
|
160
159
|
createComponent(Spacing, {}),
|
|
161
160
|
createComponent(InterfaceMember, {
|
|
162
161
|
name: "validate",
|
|
163
|
-
|
|
162
|
+
required: false,
|
|
164
163
|
type: "(value: TValue) => boolean | string | null | undefined | Promise<boolean | string | null | undefined>",
|
|
165
164
|
doc: "A validation function that returns true if the input is valid, false or a string error message if the input is invalid"
|
|
166
165
|
}),
|
|
167
166
|
createComponent(Spacing, {}),
|
|
168
167
|
createComponent(InterfaceMember, {
|
|
169
168
|
name: "parse",
|
|
170
|
-
|
|
169
|
+
required: false,
|
|
171
170
|
type: "PromptParser<TValue>",
|
|
172
171
|
doc: "A function that parses the input value and returns the parsed result or throws an error if the input is invalid"
|
|
173
172
|
}),
|
|
174
173
|
createComponent(Spacing, {}),
|
|
175
174
|
createComponent(InterfaceMember, {
|
|
176
175
|
name: "format",
|
|
177
|
-
|
|
176
|
+
required: false,
|
|
178
177
|
type: "PromptFormatter<TValue>",
|
|
179
178
|
doc: "A function that formats the input value and returns the formatted result or throws an error if the input is invalid"
|
|
180
179
|
}),
|
|
181
180
|
createComponent(Spacing, {}),
|
|
182
181
|
createComponent(InterfaceMember, {
|
|
183
182
|
name: "mask",
|
|
184
|
-
|
|
183
|
+
required: false,
|
|
185
184
|
type: "(input: string) => string",
|
|
186
185
|
doc: "A function that masks the input value and returns the masked result. This can be used to create password inputs or other sensitive input types where the actual input value should not be displayed. If not provided, the prompt will display the input as is without masking."
|
|
187
186
|
}),
|
|
188
187
|
createComponent(Spacing, {}),
|
|
189
188
|
createComponent(InterfaceMember, {
|
|
190
189
|
name: "maskCompleted",
|
|
191
|
-
|
|
190
|
+
required: false,
|
|
192
191
|
type: "(input: string) => string",
|
|
193
192
|
doc: "A function that masks the value submitted by the user so that it can then be used in the console output or elsewhere without exposing sensitive information. If not provided, the prompt will use the same mask function for both input and submitted value masking."
|
|
194
193
|
}),
|
|
195
194
|
createComponent(Spacing, {}),
|
|
196
195
|
createComponent(InterfaceMember, {
|
|
197
196
|
name: "defaultErrorMessage",
|
|
198
|
-
|
|
197
|
+
required: false,
|
|
199
198
|
type: "string",
|
|
200
199
|
doc: "The default error message to display when validation fails"
|
|
201
200
|
}),
|
|
202
201
|
createComponent(Spacing, {}),
|
|
203
202
|
createComponent(InterfaceMember, {
|
|
204
203
|
name: "timeout",
|
|
205
|
-
|
|
204
|
+
required: false,
|
|
206
205
|
type: "number",
|
|
207
206
|
doc: "The timeout duration in milliseconds for the prompt. If none is provided, the prompt will not time out."
|
|
208
207
|
})
|
|
@@ -230,8 +229,7 @@ function BasePromptDeclarations() {
|
|
|
230
229
|
createComponent(ClassField, {
|
|
231
230
|
name: "value",
|
|
232
231
|
isPrivateMember: true,
|
|
233
|
-
|
|
234
|
-
type: "TValue"
|
|
232
|
+
type: "TValue | undefined"
|
|
235
233
|
}),
|
|
236
234
|
createIntrinsic("hbr", {}),
|
|
237
235
|
createComponent(ClassField, {
|
|
@@ -913,21 +911,21 @@ function BasePromptDeclarations() {
|
|
|
913
911
|
return [
|
|
914
912
|
createComponent(InterfaceMember, {
|
|
915
913
|
name: "onState",
|
|
916
|
-
|
|
914
|
+
required: false,
|
|
917
915
|
type: "(state: PromptState<TValue>) => any",
|
|
918
916
|
doc: "A function that is called when the prompt state changes, useful for updating the prompt message or other properties dynamically"
|
|
919
917
|
}),
|
|
920
918
|
createComponent(Spacing, {}),
|
|
921
919
|
createComponent(InterfaceMember, {
|
|
922
920
|
name: "onSubmit",
|
|
923
|
-
|
|
921
|
+
required: false,
|
|
924
922
|
type: "(value: TValue) => any",
|
|
925
923
|
doc: "A function that is called when the prompt is submitted, useful for handling the submitted value or performing actions based on the prompt state"
|
|
926
924
|
}),
|
|
927
925
|
createComponent(Spacing, {}),
|
|
928
926
|
createComponent(InterfaceMember, {
|
|
929
927
|
name: "onCancel",
|
|
930
|
-
|
|
928
|
+
required: false,
|
|
931
929
|
type: "(event: any) => any",
|
|
932
930
|
doc: "A function that is called when the prompt is canceled, useful for handling the canceled value or performing actions based on the prompt state"
|
|
933
931
|
})
|
|
@@ -976,14 +974,14 @@ function TextPromptDeclarations() {
|
|
|
976
974
|
return [
|
|
977
975
|
createComponent(InterfaceMember, {
|
|
978
976
|
name: "initialValue",
|
|
979
|
-
|
|
977
|
+
required: false,
|
|
980
978
|
type: "string",
|
|
981
979
|
doc: "The initial value of the prompt"
|
|
982
980
|
}),
|
|
983
981
|
createComponent(Spacing, {}),
|
|
984
982
|
createComponent(InterfaceMember, {
|
|
985
983
|
name: "mask",
|
|
986
|
-
|
|
984
|
+
required: false,
|
|
987
985
|
type: "(input: string) => string",
|
|
988
986
|
doc: "A function that masks the input value and returns the masked result"
|
|
989
987
|
})
|
|
@@ -1230,15 +1228,15 @@ function SelectPromptDeclarations() {
|
|
|
1230
1228
|
return [
|
|
1231
1229
|
createComponent(InterfaceMember, {
|
|
1232
1230
|
name: "label",
|
|
1233
|
-
|
|
1234
|
-
|
|
1231
|
+
schema: { type: "string" },
|
|
1232
|
+
required: false,
|
|
1235
1233
|
doc: "The message label for the option"
|
|
1236
1234
|
}),
|
|
1237
1235
|
createComponent(Spacing, {}),
|
|
1238
1236
|
createComponent(InterfaceMember, {
|
|
1239
1237
|
name: "icon",
|
|
1240
|
-
|
|
1241
|
-
|
|
1238
|
+
schema: { type: "string" },
|
|
1239
|
+
required: false,
|
|
1242
1240
|
doc: "An icon for the option"
|
|
1243
1241
|
}),
|
|
1244
1242
|
createComponent(Spacing, {}),
|
|
@@ -1250,22 +1248,22 @@ function SelectPromptDeclarations() {
|
|
|
1250
1248
|
createComponent(Spacing, {}),
|
|
1251
1249
|
createComponent(InterfaceMember, {
|
|
1252
1250
|
name: "description",
|
|
1253
|
-
|
|
1254
|
-
|
|
1251
|
+
schema: { type: "string" },
|
|
1252
|
+
required: false,
|
|
1255
1253
|
doc: "The description of the option"
|
|
1256
1254
|
}),
|
|
1257
1255
|
createComponent(Spacing, {}),
|
|
1258
1256
|
createComponent(InterfaceMember, {
|
|
1259
1257
|
name: "selected",
|
|
1260
|
-
|
|
1261
|
-
|
|
1258
|
+
schema: { type: "boolean" },
|
|
1259
|
+
required: false,
|
|
1262
1260
|
doc: "Whether the option is selected"
|
|
1263
1261
|
}),
|
|
1264
1262
|
createComponent(Spacing, {}),
|
|
1265
1263
|
createComponent(InterfaceMember, {
|
|
1266
1264
|
name: "disabled",
|
|
1267
|
-
|
|
1268
|
-
|
|
1265
|
+
schema: { type: "boolean" },
|
|
1266
|
+
required: false,
|
|
1269
1267
|
doc: "Whether the option is disabled"
|
|
1270
1268
|
})
|
|
1271
1269
|
];
|
|
@@ -1321,7 +1319,7 @@ function SelectPromptDeclarations() {
|
|
|
1321
1319
|
return [
|
|
1322
1320
|
createComponent(InterfaceMember, {
|
|
1323
1321
|
name: "hint",
|
|
1324
|
-
|
|
1322
|
+
required: false,
|
|
1325
1323
|
type: "string",
|
|
1326
1324
|
doc: "A hint to display to the user"
|
|
1327
1325
|
}),
|
|
@@ -1334,7 +1332,7 @@ function SelectPromptDeclarations() {
|
|
|
1334
1332
|
createComponent(Spacing, {}),
|
|
1335
1333
|
createComponent(InterfaceMember, {
|
|
1336
1334
|
name: "optionsPerPage",
|
|
1337
|
-
|
|
1335
|
+
required: false,
|
|
1338
1336
|
type: "number",
|
|
1339
1337
|
doc: "The number of options to display per page, defaults to 8"
|
|
1340
1338
|
})
|
|
@@ -1680,6 +1678,416 @@ run(); ` }),
|
|
|
1680
1678
|
];
|
|
1681
1679
|
}
|
|
1682
1680
|
/**
|
|
1681
|
+
* Declarations for a multi-select prompt that allows users to choose multiple options from a list, with support for disabled options, bulk selection shortcuts, and required validation. This prompt type is useful for scenarios where users need to select one or more values from a predefined set.
|
|
1682
|
+
*/
|
|
1683
|
+
function MultiSelectPromptDeclarations() {
|
|
1684
|
+
return [
|
|
1685
|
+
createComponent(InterfaceDeclaration, {
|
|
1686
|
+
name: "MultiSelectPromptConfig",
|
|
1687
|
+
"extends": "PromptConfig<TValue[]>",
|
|
1688
|
+
doc: "An options object for configuring a multi-select prompt",
|
|
1689
|
+
typeParameters: [{
|
|
1690
|
+
name: "TValue",
|
|
1691
|
+
default: "string"
|
|
1692
|
+
}],
|
|
1693
|
+
get children() {
|
|
1694
|
+
return [
|
|
1695
|
+
createComponent(InterfaceMember, {
|
|
1696
|
+
name: "options",
|
|
1697
|
+
type: "Array<string | PromptOptionConfig<TValue>>",
|
|
1698
|
+
doc: "The options available for the multi-select prompt"
|
|
1699
|
+
}),
|
|
1700
|
+
createComponent(Spacing, {}),
|
|
1701
|
+
createComponent(InterfaceMember, {
|
|
1702
|
+
name: "required",
|
|
1703
|
+
required: false,
|
|
1704
|
+
type: "boolean",
|
|
1705
|
+
doc: "Whether at least one option must be selected, defaults to true"
|
|
1706
|
+
}),
|
|
1707
|
+
createComponent(Spacing, {}),
|
|
1708
|
+
createComponent(InterfaceMember, {
|
|
1709
|
+
name: "initialValue",
|
|
1710
|
+
required: false,
|
|
1711
|
+
type: "TValue[]",
|
|
1712
|
+
doc: "The initial selected values"
|
|
1713
|
+
}),
|
|
1714
|
+
createComponent(Spacing, {}),
|
|
1715
|
+
createComponent(InterfaceMember, {
|
|
1716
|
+
name: "cursorAt",
|
|
1717
|
+
required: false,
|
|
1718
|
+
type: "TValue",
|
|
1719
|
+
doc: "A value indicating which option should be focused initially"
|
|
1720
|
+
}),
|
|
1721
|
+
createComponent(Spacing, {}),
|
|
1722
|
+
createComponent(InterfaceMember, {
|
|
1723
|
+
name: "optionsPerPage",
|
|
1724
|
+
required: false,
|
|
1725
|
+
type: "number",
|
|
1726
|
+
doc: "The number of options to display per page, defaults to 8"
|
|
1727
|
+
})
|
|
1728
|
+
];
|
|
1729
|
+
}
|
|
1730
|
+
}),
|
|
1731
|
+
createComponent(Spacing, {}),
|
|
1732
|
+
createComponent(ClassDeclaration, {
|
|
1733
|
+
name: "MultiSelectPrompt",
|
|
1734
|
+
doc: "A prompt for selecting multiple options from a list",
|
|
1735
|
+
"extends": "Prompt<TValue[]>",
|
|
1736
|
+
typeParameters: [{
|
|
1737
|
+
name: "TValue",
|
|
1738
|
+
default: "string"
|
|
1739
|
+
}],
|
|
1740
|
+
get children() {
|
|
1741
|
+
return [
|
|
1742
|
+
createComponent(ClassField, {
|
|
1743
|
+
name: "initialValue",
|
|
1744
|
+
"protected": true,
|
|
1745
|
+
override: true,
|
|
1746
|
+
type: "TValue[]",
|
|
1747
|
+
children: code`[]; `
|
|
1748
|
+
}),
|
|
1749
|
+
createIntrinsic("hbr", {}),
|
|
1750
|
+
createComponent(ClassField, {
|
|
1751
|
+
name: "required",
|
|
1752
|
+
"protected": true,
|
|
1753
|
+
type: "boolean",
|
|
1754
|
+
children: code`true; `
|
|
1755
|
+
}),
|
|
1756
|
+
createIntrinsic("hbr", {}),
|
|
1757
|
+
createComponent(ClassField, {
|
|
1758
|
+
name: "optionsPerPage",
|
|
1759
|
+
"protected": true,
|
|
1760
|
+
type: "number",
|
|
1761
|
+
children: code`8; `
|
|
1762
|
+
}),
|
|
1763
|
+
createIntrinsic("hbr", {}),
|
|
1764
|
+
createComponent(ClassField, {
|
|
1765
|
+
name: "options",
|
|
1766
|
+
"protected": true,
|
|
1767
|
+
type: "PromptOption<TValue>[]",
|
|
1768
|
+
children: code`[]; `
|
|
1769
|
+
}),
|
|
1770
|
+
createIntrinsic("hbr", {}),
|
|
1771
|
+
createComponent(ClassField, {
|
|
1772
|
+
name: "cursorHidden",
|
|
1773
|
+
"protected": true,
|
|
1774
|
+
override: true,
|
|
1775
|
+
type: "boolean",
|
|
1776
|
+
children: code`true; `
|
|
1777
|
+
}),
|
|
1778
|
+
createComponent(Spacing, {}),
|
|
1779
|
+
code`constructor(config: MultiSelectPromptConfig<TValue>) {
|
|
1780
|
+
super(config);
|
|
1781
|
+
|
|
1782
|
+
this.required = config.required ?? true;
|
|
1783
|
+
this.initialValue = Array.isArray(config.initialValue) ? [...config.initialValue] : [];
|
|
1784
|
+
|
|
1785
|
+
if (config.optionsPerPage) {
|
|
1786
|
+
this.optionsPerPage = config.optionsPerPage;
|
|
1787
|
+
}
|
|
1788
|
+
|
|
1789
|
+
this.options = config.options.map((opt, index) => {
|
|
1790
|
+
let option = {} as Partial<PromptOption<TValue>>;
|
|
1791
|
+
if (typeof opt === "string") {
|
|
1792
|
+
option = {
|
|
1793
|
+
label: opt,
|
|
1794
|
+
value: opt as TValue,
|
|
1795
|
+
selected: this.initialValue.includes(opt as TValue),
|
|
1796
|
+
disabled: false
|
|
1797
|
+
};
|
|
1798
|
+
} else if (typeof opt === "object" && opt !== null) {
|
|
1799
|
+
option = {
|
|
1800
|
+
...opt,
|
|
1801
|
+
selected: this.initialValue.includes(opt.value as TValue) || !!opt.selected
|
|
1802
|
+
};
|
|
1803
|
+
} else {
|
|
1804
|
+
throw new Error("Invalid option provided to MultiSelectPrompt at index #" + index);
|
|
1805
|
+
}
|
|
1806
|
+
|
|
1807
|
+
return {
|
|
1808
|
+
label: option.label || String(option.value),
|
|
1809
|
+
...option,
|
|
1810
|
+
description: option.description,
|
|
1811
|
+
selected: !!option.selected,
|
|
1812
|
+
disabled: !!option.disabled,
|
|
1813
|
+
index
|
|
1814
|
+
} as PromptOption<TValue>;
|
|
1815
|
+
});
|
|
1816
|
+
|
|
1817
|
+
if (config.cursorAt !== undefined) {
|
|
1818
|
+
const index = this.options.findIndex(option => option.value === config.cursorAt);
|
|
1819
|
+
if (index > -1) {
|
|
1820
|
+
this.cursor = index;
|
|
1821
|
+
}
|
|
1822
|
+
}
|
|
1823
|
+
|
|
1824
|
+
if (this.options[this.cursor]?.disabled) {
|
|
1825
|
+
this.moveCursor(this.findNextEnabled(this.cursor, 1));
|
|
1826
|
+
} else {
|
|
1827
|
+
this.changeValue(this.getSelectedValues());
|
|
1828
|
+
}
|
|
1829
|
+
|
|
1830
|
+
this.sync();
|
|
1831
|
+
}
|
|
1832
|
+
|
|
1833
|
+
protected getAction(key: Key): string | false {
|
|
1834
|
+
let action = super.getAction(key);
|
|
1835
|
+
if (!action) {
|
|
1836
|
+
if (key.name === "j") action = "down";
|
|
1837
|
+
if (key.name === "k") action = "up";
|
|
1838
|
+
if (key.name === "a") action = "toggleAll";
|
|
1839
|
+
if (key.name === "i") action = "toggleInvert";
|
|
1840
|
+
if (key.name === "space") action = "toggleCurrent";
|
|
1841
|
+
}
|
|
1842
|
+
|
|
1843
|
+
return action || false;
|
|
1844
|
+
}
|
|
1845
|
+
|
|
1846
|
+
protected override async submit() {
|
|
1847
|
+
const selectedValues = this.getSelectedValues();
|
|
1848
|
+
if (this.required && selectedValues.length === 0) {
|
|
1849
|
+
this.error(
|
|
1850
|
+
"Please select at least one option. Press <space> to toggle and <enter> to submit."
|
|
1851
|
+
);
|
|
1852
|
+
this.bell();
|
|
1853
|
+
return;
|
|
1854
|
+
}
|
|
1855
|
+
|
|
1856
|
+
this.changeValue(selectedValues);
|
|
1857
|
+
await super.submit();
|
|
1858
|
+
}
|
|
1859
|
+
|
|
1860
|
+
protected toggleCurrent() {
|
|
1861
|
+
const option = this.options[this.cursor];
|
|
1862
|
+
if (!option || option.disabled) {
|
|
1863
|
+
this.bell();
|
|
1864
|
+
return;
|
|
1865
|
+
}
|
|
1866
|
+
|
|
1867
|
+
option.selected = !option.selected;
|
|
1868
|
+
this.changeValue(this.getSelectedValues());
|
|
1869
|
+
this.sync();
|
|
1870
|
+
}
|
|
1871
|
+
|
|
1872
|
+
protected toggleAll() {
|
|
1873
|
+
const enabled = this.options.filter(option => !option.disabled);
|
|
1874
|
+
const areAllSelected = enabled.every(option => option.selected);
|
|
1875
|
+
for (const option of enabled) {
|
|
1876
|
+
option.selected = !areAllSelected;
|
|
1877
|
+
}
|
|
1878
|
+
|
|
1879
|
+
this.changeValue(this.getSelectedValues());
|
|
1880
|
+
this.sync();
|
|
1881
|
+
}
|
|
1882
|
+
|
|
1883
|
+
protected toggleInvert() {
|
|
1884
|
+
for (const option of this.options) {
|
|
1885
|
+
if (!option.disabled) {
|
|
1886
|
+
option.selected = !option.selected;
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
|
|
1890
|
+
this.changeValue(this.getSelectedValues());
|
|
1891
|
+
this.sync();
|
|
1892
|
+
}
|
|
1893
|
+
|
|
1894
|
+
protected findNextEnabled(from: number, direction: 1 | -1): number {
|
|
1895
|
+
if (this.options.length === 0) {
|
|
1896
|
+
return 0;
|
|
1897
|
+
}
|
|
1898
|
+
|
|
1899
|
+
let index = from;
|
|
1900
|
+
for (let i = 0; i < this.options.length; i++) {
|
|
1901
|
+
index = (index + direction + this.options.length) % this.options.length;
|
|
1902
|
+
if (!this.options[index]?.disabled) {
|
|
1903
|
+
return index;
|
|
1904
|
+
}
|
|
1905
|
+
}
|
|
1906
|
+
|
|
1907
|
+
return from;
|
|
1908
|
+
}
|
|
1909
|
+
|
|
1910
|
+
protected getSelectedValues(): TValue[] {
|
|
1911
|
+
return this.options
|
|
1912
|
+
.filter(option => option.selected)
|
|
1913
|
+
.map(option => option.value as TValue);
|
|
1914
|
+
}
|
|
1915
|
+
|
|
1916
|
+
protected next() {
|
|
1917
|
+
this.moveCursor(this.findNextEnabled(this.cursor, 1));
|
|
1918
|
+
this.sync();
|
|
1919
|
+
}
|
|
1920
|
+
|
|
1921
|
+
protected up() {
|
|
1922
|
+
this.moveCursor(this.findNextEnabled(this.cursor, -1));
|
|
1923
|
+
this.sync();
|
|
1924
|
+
}
|
|
1925
|
+
|
|
1926
|
+
protected down() {
|
|
1927
|
+
this.moveCursor(this.findNextEnabled(this.cursor, 1));
|
|
1928
|
+
this.sync();
|
|
1929
|
+
}
|
|
1930
|
+
|
|
1931
|
+
protected first() {
|
|
1932
|
+
this.moveCursor(this.findNextEnabled(0, 1));
|
|
1933
|
+
this.sync();
|
|
1934
|
+
}
|
|
1935
|
+
|
|
1936
|
+
protected last() {
|
|
1937
|
+
this.moveCursor(this.findNextEnabled(this.options.length - 1, -1));
|
|
1938
|
+
this.sync();
|
|
1939
|
+
}
|
|
1940
|
+
|
|
1941
|
+
protected override moveCursor(count: number) {
|
|
1942
|
+
this.cursor = count;
|
|
1943
|
+
this.changeValue(this.getSelectedValues());
|
|
1944
|
+
this.sync();
|
|
1945
|
+
}
|
|
1946
|
+
|
|
1947
|
+
protected override onRender() {
|
|
1948
|
+
const spacing = Math.max(...this.options.map(option => option.label?.length || 0), 0) + 2;
|
|
1949
|
+
const startIndex = Math.max(
|
|
1950
|
+
Math.min(
|
|
1951
|
+
this.options.length - this.optionsPerPage,
|
|
1952
|
+
this.cursor - Math.floor(this.optionsPerPage / 2)
|
|
1953
|
+
),
|
|
1954
|
+
0
|
|
1955
|
+
);
|
|
1956
|
+
const endIndex = Math.min(startIndex + this.optionsPerPage, this.options.length);
|
|
1957
|
+
|
|
1958
|
+
let output = "";
|
|
1959
|
+
if (!this.isCompleted) {
|
|
1960
|
+
output += " \\\n";
|
|
1961
|
+
|
|
1962
|
+
for (let index = startIndex; index < endIndex; index++) {
|
|
1963
|
+
const option = this.options[index]!;
|
|
1964
|
+
const active = this.cursor === index;
|
|
1965
|
+
const selected = !!option.selected;
|
|
1966
|
+
const disabled = !!option.disabled;
|
|
1967
|
+
|
|
1968
|
+
const pointer = disabled
|
|
1969
|
+
? active
|
|
1970
|
+
? bold(textColors.prompt.input.disabled(">"))
|
|
1971
|
+
: index === startIndex
|
|
1972
|
+
? borderColors.app.divider.tertiary("↑")
|
|
1973
|
+
: index === endIndex - 1
|
|
1974
|
+
? borderColors.app.divider.tertiary("↓")
|
|
1975
|
+
: " "
|
|
1976
|
+
: active
|
|
1977
|
+
? bold(textColors.prompt.input.active(">"))
|
|
1978
|
+
: index === startIndex
|
|
1979
|
+
? borderColors.app.divider.tertiary("↑")
|
|
1980
|
+
: index === endIndex - 1
|
|
1981
|
+
? borderColors.app.divider.tertiary("↓")
|
|
1982
|
+
: " ";
|
|
1983
|
+
|
|
1984
|
+
const marker = isUnicodeSupported ? (selected ? "🗹" : "☐") : (selected ? "[x]" : "[ ]");
|
|
1985
|
+
const markerText = disabled
|
|
1986
|
+
? active
|
|
1987
|
+
? bold(textColors.prompt.input.disabled(marker))
|
|
1988
|
+
: textColors.prompt.input.disabled(marker)
|
|
1989
|
+
: active
|
|
1990
|
+
? bold(textColors.prompt.input.active(marker))
|
|
1991
|
+
: textColors.prompt.input.inactive(marker);
|
|
1992
|
+
|
|
1993
|
+
const labelText = disabled
|
|
1994
|
+
? active
|
|
1995
|
+
? bold(underline(textColors.prompt.input.disabled(option.label)))
|
|
1996
|
+
: strikethrough(textColors.prompt.input.disabled(option.label))
|
|
1997
|
+
: active
|
|
1998
|
+
? bold(underline(textColors.prompt.input.active(option.label)))
|
|
1999
|
+
: selected
|
|
2000
|
+
? textColors.prompt.input.active(option.label)
|
|
2001
|
+
: textColors.prompt.input.inactive(option.label);
|
|
2002
|
+
|
|
2003
|
+
output +=
|
|
2004
|
+
pointer +
|
|
2005
|
+
" " +
|
|
2006
|
+
markerText +
|
|
2007
|
+
" " +
|
|
2008
|
+
labelText +
|
|
2009
|
+
" " +
|
|
2010
|
+
" ".repeat(Math.max(0, spacing - option.label.length)) +
|
|
2011
|
+
(option.description && active
|
|
2012
|
+
? italic(textColors.prompt.description.active(option.description))
|
|
2013
|
+
: "") +
|
|
2014
|
+
" \\\n";
|
|
2015
|
+
}
|
|
2016
|
+
} else {
|
|
2017
|
+
const selected = this.options.filter(option => option.selected);
|
|
2018
|
+
this.displayValue =
|
|
2019
|
+
selected.length > 0
|
|
2020
|
+
? selected.map(option => option.label).join(", ")
|
|
2021
|
+
: "(none)";
|
|
2022
|
+
output += super.onRender();
|
|
2023
|
+
}
|
|
2024
|
+
|
|
2025
|
+
return output;
|
|
2026
|
+
}`
|
|
2027
|
+
];
|
|
2028
|
+
}
|
|
2029
|
+
}),
|
|
2030
|
+
createComponent(Spacing, {}),
|
|
2031
|
+
createComponent(TSDoc, { heading: "A type definition for the configuration options to pass to the multi-select prompt, which extends the base PromptConfig with additional options specific to multi-select prompts." }),
|
|
2032
|
+
createComponent(TypeDeclaration, {
|
|
2033
|
+
"export": true,
|
|
2034
|
+
name: "MultiSelectConfig",
|
|
2035
|
+
children: code`PromptFactoryConfig<string[]> & MultiSelectPromptConfig; `
|
|
2036
|
+
}),
|
|
2037
|
+
createComponent(Spacing, {}),
|
|
2038
|
+
createComponent(TSDoc, {
|
|
2039
|
+
heading: "A function to create and run a multi-select prompt, which returns a promise that resolves with the submitted values or a {@link CANCEL_SYMBOL | cancel symbol} if the prompt is cancelled.",
|
|
2040
|
+
get children() {
|
|
2041
|
+
return [
|
|
2042
|
+
createComponent(TSDocExample, { children: `import { multiselect, isCancel } from "shell-shock:prompts";
|
|
2043
|
+
|
|
2044
|
+
async function run() {
|
|
2045
|
+
const tools = await multiselect({
|
|
2046
|
+
message: "Select tools",
|
|
2047
|
+
options: [
|
|
2048
|
+
{ value: "eslint", label: "ESLint" },
|
|
2049
|
+
{ value: "prettier", label: "Prettier" },
|
|
2050
|
+
{ value: "vitest", label: "Vitest", disabled: true }
|
|
2051
|
+
]
|
|
2052
|
+
});
|
|
2053
|
+
|
|
2054
|
+
if (isCancel(tools)) {
|
|
2055
|
+
console.log("Prompt was cancelled");
|
|
2056
|
+
return;
|
|
2057
|
+
}
|
|
2058
|
+
|
|
2059
|
+
console.log("Selected tools:", tools.join(", "));
|
|
2060
|
+
}
|
|
2061
|
+
|
|
2062
|
+
run(); ` }),
|
|
2063
|
+
createComponent(Spacing, {}),
|
|
2064
|
+
createComponent(TSDocParam, {
|
|
2065
|
+
name: "config",
|
|
2066
|
+
children: `The configuration options to pass to the multi-select prompt`
|
|
2067
|
+
}),
|
|
2068
|
+
createComponent(TSDocReturns, { children: `A promise that resolves with the selected values or a {@link CANCEL_SYMBOL | cancel symbol} if the prompt is cancelled` })
|
|
2069
|
+
];
|
|
2070
|
+
}
|
|
2071
|
+
}),
|
|
2072
|
+
createComponent(FunctionDeclaration, {
|
|
2073
|
+
name: "multiselect",
|
|
2074
|
+
"export": true,
|
|
2075
|
+
parameters: [{
|
|
2076
|
+
name: "config",
|
|
2077
|
+
type: "MultiSelectConfig"
|
|
2078
|
+
}],
|
|
2079
|
+
returnType: "Promise<string[] | symbol>",
|
|
2080
|
+
children: code`return new Promise<string[] | symbol>((response, reject) => {
|
|
2081
|
+
const prompt = new MultiSelectPrompt(config);
|
|
2082
|
+
|
|
2083
|
+
prompt.on("state", state => config.onState?.(state));
|
|
2084
|
+
prompt.on("submit", value => response(value));
|
|
2085
|
+
prompt.on("cancel", event => response(CANCEL_SYMBOL));
|
|
2086
|
+
});`
|
|
2087
|
+
})
|
|
2088
|
+
];
|
|
2089
|
+
}
|
|
2090
|
+
/**
|
|
1683
2091
|
* A component that renders the declarations for the built-in numeric prompt, which allows users to input and select numeric values with various configuration options such as floating point support, precision, increment, and min/max values.
|
|
1684
2092
|
*/
|
|
1685
2093
|
function NumericPromptDeclarations() {
|
|
@@ -1692,35 +2100,35 @@ function NumericPromptDeclarations() {
|
|
|
1692
2100
|
return [
|
|
1693
2101
|
createComponent(InterfaceMember, {
|
|
1694
2102
|
name: "isFloat",
|
|
1695
|
-
|
|
2103
|
+
required: false,
|
|
1696
2104
|
type: "boolean",
|
|
1697
2105
|
doc: "Whether the prompt should accept floating point numbers"
|
|
1698
2106
|
}),
|
|
1699
2107
|
createComponent(Spacing, {}),
|
|
1700
2108
|
createComponent(InterfaceMember, {
|
|
1701
2109
|
name: "precision",
|
|
1702
|
-
|
|
2110
|
+
required: false,
|
|
1703
2111
|
type: "number",
|
|
1704
2112
|
doc: "The number of decimal places to round the input to, defaults to 2"
|
|
1705
2113
|
}),
|
|
1706
2114
|
createComponent(Spacing, {}),
|
|
1707
2115
|
createComponent(InterfaceMember, {
|
|
1708
2116
|
name: "increment",
|
|
1709
|
-
|
|
2117
|
+
required: false,
|
|
1710
2118
|
type: "number",
|
|
1711
2119
|
doc: "The increment value for the number prompt, defaults to 1"
|
|
1712
2120
|
}),
|
|
1713
2121
|
createComponent(Spacing, {}),
|
|
1714
2122
|
createComponent(InterfaceMember, {
|
|
1715
2123
|
name: "min",
|
|
1716
|
-
|
|
2124
|
+
required: false,
|
|
1717
2125
|
type: "number",
|
|
1718
2126
|
doc: "The minimum value for the number prompt, defaults to -Infinity"
|
|
1719
2127
|
}),
|
|
1720
2128
|
createComponent(Spacing, {}),
|
|
1721
2129
|
createComponent(InterfaceMember, {
|
|
1722
2130
|
name: "max",
|
|
1723
|
-
|
|
2131
|
+
required: false,
|
|
1724
2132
|
type: "number",
|
|
1725
2133
|
doc: "The maximum value for the number prompt, defaults to Infinity"
|
|
1726
2134
|
})
|
|
@@ -2070,14 +2478,14 @@ function TogglePromptDeclarations() {
|
|
|
2070
2478
|
return [
|
|
2071
2479
|
createComponent(InterfaceMember, {
|
|
2072
2480
|
name: "trueMessage",
|
|
2073
|
-
|
|
2481
|
+
required: false,
|
|
2074
2482
|
type: "string",
|
|
2075
2483
|
doc: "The message for the true state of the prompt"
|
|
2076
2484
|
}),
|
|
2077
2485
|
createComponent(Spacing, {}),
|
|
2078
2486
|
createComponent(InterfaceMember, {
|
|
2079
2487
|
name: "falseMessage",
|
|
2080
|
-
|
|
2488
|
+
required: false,
|
|
2081
2489
|
type: "string",
|
|
2082
2490
|
doc: "The message for the false state of the prompt"
|
|
2083
2491
|
}),
|
|
@@ -2326,16 +2734,14 @@ function ConfirmPromptDeclarations() {
|
|
|
2326
2734
|
heading: "The message for the \\`Yes\\` state of the prompt",
|
|
2327
2735
|
get children() {
|
|
2328
2736
|
return createComponent(TSDocDefaultValue, {
|
|
2329
|
-
|
|
2330
|
-
return ReflectionKind.string;
|
|
2331
|
-
},
|
|
2737
|
+
type: "string",
|
|
2332
2738
|
defaultValue: "Yes"
|
|
2333
2739
|
});
|
|
2334
2740
|
}
|
|
2335
2741
|
}),
|
|
2336
2742
|
createComponent(InterfaceMember, {
|
|
2337
2743
|
name: "yesMessage",
|
|
2338
|
-
|
|
2744
|
+
required: false,
|
|
2339
2745
|
type: "string"
|
|
2340
2746
|
}),
|
|
2341
2747
|
createComponent(Spacing, {}),
|
|
@@ -2343,16 +2749,14 @@ function ConfirmPromptDeclarations() {
|
|
|
2343
2749
|
heading: "The \\`Yes\\` option when choosing between yes/no",
|
|
2344
2750
|
get children() {
|
|
2345
2751
|
return createComponent(TSDocDefaultValue, {
|
|
2346
|
-
|
|
2347
|
-
return ReflectionKind.string;
|
|
2348
|
-
},
|
|
2752
|
+
type: "string",
|
|
2349
2753
|
defaultValue: "1"
|
|
2350
2754
|
});
|
|
2351
2755
|
}
|
|
2352
2756
|
}),
|
|
2353
2757
|
createComponent(InterfaceMember, {
|
|
2354
2758
|
name: "yesOption",
|
|
2355
|
-
|
|
2759
|
+
required: false,
|
|
2356
2760
|
type: "string"
|
|
2357
2761
|
}),
|
|
2358
2762
|
createComponent(Spacing, {}),
|
|
@@ -2360,16 +2764,14 @@ function ConfirmPromptDeclarations() {
|
|
|
2360
2764
|
heading: "The message for the \\`No\\` state of the prompt",
|
|
2361
2765
|
get children() {
|
|
2362
2766
|
return createComponent(TSDocDefaultValue, {
|
|
2363
|
-
|
|
2364
|
-
return ReflectionKind.string;
|
|
2365
|
-
},
|
|
2767
|
+
type: "string",
|
|
2366
2768
|
defaultValue: "(Y/n)"
|
|
2367
2769
|
});
|
|
2368
2770
|
}
|
|
2369
2771
|
}),
|
|
2370
2772
|
createComponent(InterfaceMember, {
|
|
2371
2773
|
name: "noMessage",
|
|
2372
|
-
|
|
2774
|
+
required: false,
|
|
2373
2775
|
type: "string"
|
|
2374
2776
|
}),
|
|
2375
2777
|
createComponent(Spacing, {}),
|
|
@@ -2377,16 +2779,14 @@ function ConfirmPromptDeclarations() {
|
|
|
2377
2779
|
heading: "The \\`No\\` option when choosing between yes/no",
|
|
2378
2780
|
get children() {
|
|
2379
2781
|
return createComponent(TSDocDefaultValue, {
|
|
2380
|
-
|
|
2381
|
-
return ReflectionKind.string;
|
|
2382
|
-
},
|
|
2782
|
+
type: "string",
|
|
2383
2783
|
defaultValue: "(y/N)"
|
|
2384
2784
|
});
|
|
2385
2785
|
}
|
|
2386
2786
|
}),
|
|
2387
2787
|
createComponent(InterfaceMember, {
|
|
2388
2788
|
name: "noOption",
|
|
2389
|
-
|
|
2789
|
+
required: false,
|
|
2390
2790
|
type: "string"
|
|
2391
2791
|
})
|
|
2392
2792
|
];
|
|
@@ -2715,6 +3115,7 @@ function PromptsBuiltin(props) {
|
|
|
2715
3115
|
"splitText",
|
|
2716
3116
|
"error"
|
|
2717
3117
|
],
|
|
3118
|
+
utils: ["isUnicodeSupported"],
|
|
2718
3119
|
env: [
|
|
2719
3120
|
"env",
|
|
2720
3121
|
"isCI",
|
|
@@ -2734,6 +3135,8 @@ function PromptsBuiltin(props) {
|
|
|
2734
3135
|
createComponent(Spacing, {}),
|
|
2735
3136
|
createComponent(SelectPromptDeclarations, {}),
|
|
2736
3137
|
createComponent(Spacing, {}),
|
|
3138
|
+
createComponent(MultiSelectPromptDeclarations, {}),
|
|
3139
|
+
createComponent(Spacing, {}),
|
|
2737
3140
|
createComponent(NumericPromptDeclarations, {}),
|
|
2738
3141
|
createComponent(Spacing, {}),
|
|
2739
3142
|
createComponent(TogglePromptDeclarations, {}),
|
|
@@ -2756,5 +3159,5 @@ function PromptsBuiltin(props) {
|
|
|
2756
3159
|
}
|
|
2757
3160
|
|
|
2758
3161
|
//#endregion
|
|
2759
|
-
export { BasePromptDeclarations, ConfirmPromptDeclarations, NumericPromptDeclarations, PasswordPromptDeclaration, PromptsBuiltin, SelectPromptDeclarations, TextPromptDeclarations, TogglePromptDeclarations, WaitForKeyPressDeclaration };
|
|
3162
|
+
export { BasePromptDeclarations, ConfirmPromptDeclarations, MultiSelectPromptDeclarations, NumericPromptDeclarations, PasswordPromptDeclaration, PromptsBuiltin, SelectPromptDeclarations, TextPromptDeclarations, TogglePromptDeclarations, WaitForKeyPressDeclaration };
|
|
2760
3163
|
//# sourceMappingURL=prompts-builtin.mjs.map
|