@shell-shock/preset-cli 0.4.1 → 0.4.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.
- package/README.md +1 -1
- package/dist/components/banner-function-declaration.cjs +1 -1
- package/dist/components/banner-function-declaration.d.cts +2 -2
- package/dist/components/banner-function-declaration.d.cts.map +1 -1
- package/dist/components/banner-function-declaration.mjs +1 -1
- package/dist/components/banner-function-declaration.mjs.map +1 -1
- package/dist/components/command-entry.cjs +18 -11
- package/dist/components/command-entry.d.cts +2 -2
- package/dist/components/command-entry.d.cts.map +1 -1
- package/dist/components/command-entry.d.mts.map +1 -1
- package/dist/components/command-entry.mjs +18 -11
- package/dist/components/command-entry.mjs.map +1 -1
- package/dist/components/command-router.d.cts +3 -3
- package/dist/components/prompts-builtin.cjs +67 -63
- package/dist/components/prompts-builtin.d.cts +8 -8
- package/dist/components/prompts-builtin.d.cts.map +1 -1
- package/dist/components/prompts-builtin.d.mts.map +1 -1
- package/dist/components/prompts-builtin.mjs +67 -63
- package/dist/components/prompts-builtin.mjs.map +1 -1
- package/package.json +9 -9
|
@@ -82,35 +82,6 @@ function BasePromptDeclarations() {
|
|
|
82
82
|
returnType: "string",
|
|
83
83
|
children: code`return " ".repeat(input.length); `
|
|
84
84
|
}),
|
|
85
|
-
createComponent(Spacing, {}),
|
|
86
|
-
code`
|
|
87
|
-
const DEFAULT_ICONS = process.platform === "win32" ? {
|
|
88
|
-
arrowUp: "↑",
|
|
89
|
-
arrowDown: "↓",
|
|
90
|
-
arrowLeft: "←",
|
|
91
|
-
arrowRight: "→",
|
|
92
|
-
radioOn: "(*)",
|
|
93
|
-
radioOff: "( )",
|
|
94
|
-
tick: "√",
|
|
95
|
-
cross: "×",
|
|
96
|
-
ellipsis: "...",
|
|
97
|
-
pointerSmall: "»",
|
|
98
|
-
line: "─",
|
|
99
|
-
pointer: ">"
|
|
100
|
-
} : {
|
|
101
|
-
arrowUp: "↑",
|
|
102
|
-
arrowDown: "↓",
|
|
103
|
-
arrowLeft: "←",
|
|
104
|
-
arrowRight: "→",
|
|
105
|
-
radioOn: "◉",
|
|
106
|
-
radioOff: "◯",
|
|
107
|
-
tick: "✔",
|
|
108
|
-
cross: "✖",
|
|
109
|
-
ellipsis: "…",
|
|
110
|
-
pointerSmall: "›",
|
|
111
|
-
line: "─",
|
|
112
|
-
pointer: "❯"
|
|
113
|
-
}; `,
|
|
114
85
|
createComponent(Spacing, {}),
|
|
115
86
|
createComponent(InterfaceDeclaration, {
|
|
116
87
|
"export": true,
|
|
@@ -488,12 +459,12 @@ function BasePromptDeclarations() {
|
|
|
488
459
|
"protected": true,
|
|
489
460
|
name: "status",
|
|
490
461
|
type: "string",
|
|
491
|
-
children: code`return this.
|
|
462
|
+
children: code`return this.isCompleted ? "" : \` \\n \${
|
|
492
463
|
colors.italic(
|
|
493
464
|
this.isError
|
|
494
|
-
? colors.text.prompt.description.error(splitText(this.errorMessage, "
|
|
495
|
-
: this.
|
|
496
|
-
? colors.text.prompt.description.active(this.description)
|
|
465
|
+
? colors.text.prompt.description.error(splitText(this.errorMessage, "3/4").join("\\n"))
|
|
466
|
+
: this.description
|
|
467
|
+
? colors.text.prompt.description.active(splitText(this.description, "3/4").join("\\n"))
|
|
497
468
|
: ""
|
|
498
469
|
)
|
|
499
470
|
}\`; `
|
|
@@ -812,20 +783,27 @@ function BasePromptDeclarations() {
|
|
|
812
783
|
createComponent(VarDeclaration, {
|
|
813
784
|
"export": true,
|
|
814
785
|
name: "CANCEL_SYMBOL",
|
|
815
|
-
doc: "A unique symbol used to indicate that a prompt was cancelled, which can be returned from a prompt
|
|
786
|
+
doc: "A unique symbol used to indicate that a prompt was cancelled, which can be returned from a prompt function to signal that the prompt interaction should be cancelled and any pending promises should be rejected with this symbol. This allows for a consistent way to handle prompt cancellations across different prompt types and interactions.",
|
|
816
787
|
children: code`Symbol("shell-shock:prompts:cancel"); `
|
|
817
788
|
}),
|
|
818
789
|
createComponent(Spacing, {}),
|
|
790
|
+
createComponent(TSDoc, {
|
|
791
|
+
heading: "A utility function to check if a given value is the {@link CANCEL_SYMBOL | cancel symbol}, which can be used to determine if a prompt interaction was cancelled based on the value returned from a prompt factory function. This function checks if the provided value is strictly equal to the {@link CANCEL_SYMBOL | CANCEL_SYMBOL}, allowing for a consistent way to handle prompt cancellations across different prompt types and interactions.",
|
|
792
|
+
get children() {
|
|
793
|
+
return [createComponent(TSDocParam, {
|
|
794
|
+
name: "value",
|
|
795
|
+
children: `The value to check.`
|
|
796
|
+
}), createComponent(TSDocReturns, { children: `A boolean indicating whether the provided value is the {@link CANCEL_SYMBOL | cancel symbol}, which can be used to determine if a prompt interaction was cancelled.` })];
|
|
797
|
+
}
|
|
798
|
+
}),
|
|
819
799
|
createComponent(FunctionDeclaration, {
|
|
820
800
|
name: "isCancel",
|
|
821
801
|
"export": true,
|
|
822
|
-
doc: "Checks if a given value is a {@link CANCEL_SYMBOL | cancel symbol}.",
|
|
823
802
|
parameters: [{
|
|
824
803
|
name: "value",
|
|
825
|
-
type: "any"
|
|
826
|
-
doc: "The value to check"
|
|
804
|
+
type: "any"
|
|
827
805
|
}],
|
|
828
|
-
returnType: "
|
|
806
|
+
returnType: "value is typeof CANCEL_SYMBOL",
|
|
829
807
|
children: code`return value === CANCEL_SYMBOL; `
|
|
830
808
|
})
|
|
831
809
|
];
|
|
@@ -874,6 +852,7 @@ function TextPromptDeclarations() {
|
|
|
874
852
|
createComponent(ClassField, {
|
|
875
853
|
name: "initialValue",
|
|
876
854
|
"protected": true,
|
|
855
|
+
override: true,
|
|
877
856
|
type: "string",
|
|
878
857
|
children: code`""; `
|
|
879
858
|
}),
|
|
@@ -1107,7 +1086,7 @@ function TextPromptDeclarations() {
|
|
|
1107
1086
|
get children() {
|
|
1108
1087
|
return [
|
|
1109
1088
|
createComponent(TSDocRemarks, { children: code`This function can be used to easily create and run a text prompt without needing to manually create an instance of the TextPrompt class and handle its events. The function accepts a configuration object that extends the base PromptFactoryConfig with additional options specific to text prompts, such as the initial value and mask function. The returned promise allows for easy handling of the prompt result using async/await syntax or traditional promise chaining.` }),
|
|
1110
|
-
createComponent(TSDocExample, { children: `import { text, isCancel } from "shell-shock
|
|
1089
|
+
createComponent(TSDocExample, { children: `import { text, isCancel } from "shell-shock:prompts";
|
|
1111
1090
|
|
|
1112
1091
|
async function run() {
|
|
1113
1092
|
const name = await text({
|
|
@@ -1159,6 +1138,10 @@ function SelectPromptDeclarations() {
|
|
|
1159
1138
|
createComponent(InterfaceDeclaration, {
|
|
1160
1139
|
name: "PromptOptionConfig",
|
|
1161
1140
|
doc: "Configuration for an option the user can select from the select prompt",
|
|
1141
|
+
typeParameters: [{
|
|
1142
|
+
name: "TValue",
|
|
1143
|
+
default: "string"
|
|
1144
|
+
}],
|
|
1162
1145
|
get children() {
|
|
1163
1146
|
return [
|
|
1164
1147
|
createComponent(InterfaceMember, {
|
|
@@ -1177,7 +1160,7 @@ function SelectPromptDeclarations() {
|
|
|
1177
1160
|
createComponent(Spacing, {}),
|
|
1178
1161
|
createComponent(InterfaceMember, {
|
|
1179
1162
|
name: "value",
|
|
1180
|
-
type: "
|
|
1163
|
+
type: "TValue",
|
|
1181
1164
|
doc: "The value of the option"
|
|
1182
1165
|
}),
|
|
1183
1166
|
createComponent(Spacing, {}),
|
|
@@ -1208,10 +1191,19 @@ function SelectPromptDeclarations() {
|
|
|
1208
1191
|
createComponent(InterfaceDeclaration, {
|
|
1209
1192
|
"export": true,
|
|
1210
1193
|
name: "PromptOption",
|
|
1211
|
-
"extends": "PromptOptionConfig",
|
|
1194
|
+
"extends": "PromptOptionConfig<TValue>",
|
|
1212
1195
|
doc: "An option the user can select from the select prompt",
|
|
1196
|
+
typeParameters: [{
|
|
1197
|
+
name: "TValue",
|
|
1198
|
+
default: "string"
|
|
1199
|
+
}],
|
|
1213
1200
|
get children() {
|
|
1214
1201
|
return [
|
|
1202
|
+
createComponent(InterfaceMember, {
|
|
1203
|
+
name: "label",
|
|
1204
|
+
type: "string",
|
|
1205
|
+
doc: "The message label for the option"
|
|
1206
|
+
}),
|
|
1215
1207
|
createComponent(InterfaceMember, {
|
|
1216
1208
|
name: "index",
|
|
1217
1209
|
type: "number",
|
|
@@ -1235,8 +1227,12 @@ function SelectPromptDeclarations() {
|
|
|
1235
1227
|
createComponent(Spacing, {}),
|
|
1236
1228
|
createComponent(InterfaceDeclaration, {
|
|
1237
1229
|
name: "SelectPromptConfig",
|
|
1238
|
-
"extends": "PromptConfig<
|
|
1230
|
+
"extends": "PromptConfig<TValue>",
|
|
1239
1231
|
doc: "An options object for configuring a select prompt",
|
|
1232
|
+
typeParameters: [{
|
|
1233
|
+
name: "TValue",
|
|
1234
|
+
default: "string"
|
|
1235
|
+
}],
|
|
1240
1236
|
get children() {
|
|
1241
1237
|
return [
|
|
1242
1238
|
createComponent(InterfaceMember, {
|
|
@@ -1248,7 +1244,7 @@ function SelectPromptDeclarations() {
|
|
|
1248
1244
|
createComponent(Spacing, {}),
|
|
1249
1245
|
createComponent(InterfaceMember, {
|
|
1250
1246
|
name: "options",
|
|
1251
|
-
type: "Array<string | PromptOptionConfig
|
|
1247
|
+
type: "Array<string | PromptOptionConfig<TValue>>",
|
|
1252
1248
|
doc: "The options available for the select prompt"
|
|
1253
1249
|
}),
|
|
1254
1250
|
createComponent(Spacing, {}),
|
|
@@ -1268,13 +1264,14 @@ function SelectPromptDeclarations() {
|
|
|
1268
1264
|
"extends": "Prompt<TValue>",
|
|
1269
1265
|
typeParameters: [{
|
|
1270
1266
|
name: "TValue",
|
|
1271
|
-
default: "
|
|
1267
|
+
default: "string"
|
|
1272
1268
|
}],
|
|
1273
1269
|
get children() {
|
|
1274
1270
|
return [
|
|
1275
1271
|
createComponent(ClassField, {
|
|
1276
1272
|
name: "initialValue",
|
|
1277
1273
|
"protected": true,
|
|
1274
|
+
override: true,
|
|
1278
1275
|
type: "TValue"
|
|
1279
1276
|
}),
|
|
1280
1277
|
createIntrinsic("hbr", {}),
|
|
@@ -1288,47 +1285,48 @@ function SelectPromptDeclarations() {
|
|
|
1288
1285
|
createComponent(ClassField, {
|
|
1289
1286
|
name: "options",
|
|
1290
1287
|
"protected": true,
|
|
1291
|
-
type: "PromptOption[]",
|
|
1288
|
+
type: "PromptOption<TValue>[]",
|
|
1292
1289
|
children: code`[]; `
|
|
1293
1290
|
}),
|
|
1294
1291
|
createComponent(Spacing, {}),
|
|
1295
|
-
code`constructor(config: SelectPromptConfig) {
|
|
1292
|
+
code`constructor(config: SelectPromptConfig<TValue>) {
|
|
1296
1293
|
super(config);
|
|
1297
1294
|
|
|
1298
1295
|
if (config.initialValue) {
|
|
1299
|
-
this.initialValue = config.initialValue;
|
|
1296
|
+
this.initialValue = config.initialValue as TValue;
|
|
1297
|
+
} else {
|
|
1298
|
+
this.initialValue = undefined as unknown as TValue;
|
|
1300
1299
|
}
|
|
1301
1300
|
|
|
1302
|
-
this.options = config.options.map(opt => {
|
|
1303
|
-
let option
|
|
1301
|
+
this.options = config.options.map((opt, index) => {
|
|
1302
|
+
let option = {} as Partial<PromptOption<TValue>>;
|
|
1304
1303
|
if (typeof opt === "string") {
|
|
1305
|
-
option = {
|
|
1304
|
+
option = { label: opt, value: opt as TValue, selected: false, disabled: false };
|
|
1306
1305
|
} else if (typeof opt === "object") {
|
|
1307
|
-
option = opt
|
|
1306
|
+
option = opt;
|
|
1308
1307
|
} else {
|
|
1309
1308
|
throw new Error(\`Invalid option provided to SelectPrompt at index #\${index}\`);
|
|
1310
1309
|
}
|
|
1311
1310
|
|
|
1312
1311
|
return {
|
|
1313
|
-
label: String(option.value),
|
|
1312
|
+
label: String(option.value) || "",
|
|
1314
1313
|
...option,
|
|
1315
|
-
index: -1,
|
|
1316
1314
|
description: option.description,
|
|
1317
1315
|
selected: !!option.selected || (this.initialValue !== undefined && option.value === this.initialValue),
|
|
1318
1316
|
disabled: !!option.disabled
|
|
1319
|
-
}
|
|
1317
|
+
} as PromptOption<TValue>;
|
|
1320
1318
|
}).sort((a, b) => a.label.localeCompare(b.label)).map((option, index) => ({ ...option, index }));
|
|
1321
1319
|
|
|
1322
1320
|
const selected = this.options.findIndex(option => option.selected);
|
|
1323
1321
|
if (selected > -1) {
|
|
1324
1322
|
this.cursor = selected;
|
|
1325
1323
|
if (this.options[this.cursor]) {
|
|
1326
|
-
this.initialValue = this.options[this.cursor].value;
|
|
1324
|
+
this.initialValue = this.options[this.cursor].value as TValue;
|
|
1327
1325
|
}
|
|
1328
1326
|
}
|
|
1329
1327
|
|
|
1330
1328
|
if (this.initialValue === undefined && this.options.length > 0 && this.options[0]) {
|
|
1331
|
-
this.initialValue = this.options[0].value;
|
|
1329
|
+
this.initialValue = this.options[0].value as TValue;
|
|
1332
1330
|
}
|
|
1333
1331
|
|
|
1334
1332
|
if (config.optionsPerPage) {
|
|
@@ -1341,9 +1339,9 @@ function SelectPromptDeclarations() {
|
|
|
1341
1339
|
createComponent(ClassPropertyGet, {
|
|
1342
1340
|
doc: "Returns the currently selected option",
|
|
1343
1341
|
name: "selectedOption",
|
|
1344
|
-
type: "PromptOption | null",
|
|
1342
|
+
type: "PromptOption<TValue> | null",
|
|
1345
1343
|
"protected": true,
|
|
1346
|
-
children: code`return this.options
|
|
1344
|
+
children: code`return this.options.find(option => option.selected) ?? null; `
|
|
1347
1345
|
}),
|
|
1348
1346
|
createComponent(Spacing, {}),
|
|
1349
1347
|
createComponent(ClassMethod, {
|
|
@@ -1462,6 +1460,7 @@ function SelectPromptDeclarations() {
|
|
|
1462
1460
|
createComponent(ClassMethod, {
|
|
1463
1461
|
doc: "A method to render the prompt",
|
|
1464
1462
|
name: "render",
|
|
1463
|
+
override: true,
|
|
1465
1464
|
"protected": true,
|
|
1466
1465
|
children: code`if (this.isInitial) {
|
|
1467
1466
|
this.output.write(cursor.hide);
|
|
@@ -1508,7 +1507,7 @@ function SelectPromptDeclarations() {
|
|
|
1508
1507
|
: this.cursor === index
|
|
1509
1508
|
? colors.bold(colors.underline(colors.text.prompt.input.active(this.options[index]!.label)))
|
|
1510
1509
|
: colors.text.prompt.input.inactive(this.options[index]!.label)
|
|
1511
|
-
} \${" ".repeat(spacing - this.options[index]!.label.length - (this.options[index]!.icon ? this.options[index]!.icon
|
|
1510
|
+
} \${" ".repeat(spacing - this.options[index]!.label.length - (this.options[index]!.icon ? this.options[index]!.icon!.length + 1 : 0))}\${
|
|
1512
1511
|
this.options[index]!.description && this.cursor === index
|
|
1513
1512
|
? colors.italic(colors.text.prompt.description.active(this.options[index]!.description))
|
|
1514
1513
|
: ""
|
|
@@ -1541,7 +1540,7 @@ function SelectPromptDeclarations() {
|
|
|
1541
1540
|
heading: "A function to create and run a select prompt, which returns a promise that resolves with the submitted value or rejects with a {@link CANCEL_SYMBOL | cancel symbol} if the prompt is cancelled.",
|
|
1542
1541
|
get children() {
|
|
1543
1542
|
return [
|
|
1544
|
-
createComponent(TSDocExample, { children: `import { select, isCancel } from "shell-shock
|
|
1543
|
+
createComponent(TSDocExample, { children: `import { select, isCancel } from "shell-shock:prompts";
|
|
1545
1544
|
|
|
1546
1545
|
async function run() {
|
|
1547
1546
|
const color = await select({
|
|
@@ -1649,6 +1648,7 @@ function NumericPromptDeclarations() {
|
|
|
1649
1648
|
createComponent(ClassField, {
|
|
1650
1649
|
name: "initialValue",
|
|
1651
1650
|
"protected": true,
|
|
1651
|
+
override: true,
|
|
1652
1652
|
type: "number",
|
|
1653
1653
|
children: code`0; `
|
|
1654
1654
|
}),
|
|
@@ -1743,6 +1743,7 @@ function NumericPromptDeclarations() {
|
|
|
1743
1743
|
createComponent(ClassMethod, {
|
|
1744
1744
|
doc: "A method to reset the prompt input",
|
|
1745
1745
|
name: "reset",
|
|
1746
|
+
override: true,
|
|
1746
1747
|
"protected": true,
|
|
1747
1748
|
children: code`super.reset();
|
|
1748
1749
|
this.currentInput = "";
|
|
@@ -1760,6 +1761,7 @@ function NumericPromptDeclarations() {
|
|
|
1760
1761
|
createComponent(ClassMethod, {
|
|
1761
1762
|
doc: "A method to handle keypress events and determine the corresponding action",
|
|
1762
1763
|
name: "keypress",
|
|
1764
|
+
override: true,
|
|
1763
1765
|
"protected": true,
|
|
1764
1766
|
parameters: [{
|
|
1765
1767
|
name: "char",
|
|
@@ -1869,7 +1871,7 @@ function NumericPromptDeclarations() {
|
|
|
1869
1871
|
heading: "A function to create and run a numeric prompt, which returns a promise that resolves with the submitted value or rejects with a {@link CANCEL_SYMBOL | cancel symbol} if the prompt is cancelled.",
|
|
1870
1872
|
get children() {
|
|
1871
1873
|
return [
|
|
1872
|
-
createComponent(TSDocExample, { children: `import { numeric, isCancel } from "shell-shock
|
|
1874
|
+
createComponent(TSDocExample, { children: `import { numeric, isCancel } from "shell-shock:prompts";
|
|
1873
1875
|
|
|
1874
1876
|
async function run() {
|
|
1875
1877
|
const age = await numeric({
|
|
@@ -1953,6 +1955,7 @@ function TogglePromptDeclarations() {
|
|
|
1953
1955
|
createComponent(ClassField, {
|
|
1954
1956
|
name: "initialValue",
|
|
1955
1957
|
"protected": true,
|
|
1958
|
+
override: true,
|
|
1956
1959
|
type: "boolean",
|
|
1957
1960
|
children: code`false; `
|
|
1958
1961
|
}),
|
|
@@ -2015,6 +2018,7 @@ function TogglePromptDeclarations() {
|
|
|
2015
2018
|
createComponent(ClassMethod, {
|
|
2016
2019
|
doc: "A method to handle keypress events and determine the corresponding action",
|
|
2017
2020
|
name: "keypress",
|
|
2021
|
+
override: true,
|
|
2018
2022
|
"protected": true,
|
|
2019
2023
|
parameters: [{
|
|
2020
2024
|
name: "char",
|
|
@@ -2098,7 +2102,7 @@ function TogglePromptDeclarations() {
|
|
|
2098
2102
|
heading: "A function to create and run a toggle prompt, which returns a promise that resolves with the submitted value or rejects with a {@link CANCEL_SYMBOL | cancel symbol} if the prompt is cancelled.",
|
|
2099
2103
|
get children() {
|
|
2100
2104
|
return [
|
|
2101
|
-
createComponent(TSDocExample, { children: `import { toggle, isCancel } from "shell-shock
|
|
2105
|
+
createComponent(TSDocExample, { children: `import { toggle, isCancel } from "shell-shock:prompts";
|
|
2102
2106
|
|
|
2103
2107
|
async function run() {
|
|
2104
2108
|
const likesIceCream = await toggle({
|
|
@@ -2170,7 +2174,7 @@ function PasswordPromptDeclaration() {
|
|
|
2170
2174
|
return [
|
|
2171
2175
|
createComponent(TSDocRemarks, { children: code`This function creates an instance of the TextPrompt class with the provided configuration options and a custom mask function to handle password input. It sets up event listeners for state updates, submission, and cancellation to handle the prompt interactions and return the appropriate results. The password prompt allows users to input text that is masked for privacy, making it suitable for scenarios like entering passwords or sensitive information.` }),
|
|
2172
2176
|
createComponent(Spacing, {}),
|
|
2173
|
-
createComponent(TSDocExample, { children: `import { password, isCancel } from "shell-shock
|
|
2177
|
+
createComponent(TSDocExample, { children: `import { password, isCancel } from "shell-shock:prompts";
|
|
2174
2178
|
|
|
2175
2179
|
async function run() {
|
|
2176
2180
|
const userPassword = await password({
|