@shell-shock/plugin-prompts 0.3.0 → 0.3.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/dist/components/index.cjs +2 -1
- 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 +80 -35
- package/dist/components/prompts-builtin.d.cts +2 -1
- package/dist/components/prompts-builtin.d.cts.map +1 -1
- package/dist/components/prompts-builtin.d.mts +2 -1
- package/dist/components/prompts-builtin.d.mts.map +1 -1
- package/dist/components/prompts-builtin.mjs +79 -35
- package/dist/components/prompts-builtin.mjs.map +1 -1
- package/package.json +9 -9
|
@@ -7,4 +7,5 @@ exports.PasswordPromptDeclaration = require_components_prompts_builtin.PasswordP
|
|
|
7
7
|
exports.PromptsBuiltin = require_components_prompts_builtin.PromptsBuiltin;
|
|
8
8
|
exports.SelectPromptDeclarations = require_components_prompts_builtin.SelectPromptDeclarations;
|
|
9
9
|
exports.TextPromptDeclarations = require_components_prompts_builtin.TextPromptDeclarations;
|
|
10
|
-
exports.TogglePromptDeclarations = require_components_prompts_builtin.TogglePromptDeclarations;
|
|
10
|
+
exports.TogglePromptDeclarations = require_components_prompts_builtin.TogglePromptDeclarations;
|
|
11
|
+
exports.WaitForKeyPressDeclaration = require_components_prompts_builtin.WaitForKeyPressDeclaration;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { BasePromptDeclarations, ConfirmPromptDeclarations, NumericPromptDeclarations, PasswordPromptDeclaration, PromptsBuiltin, PromptsBuiltinProps, SelectPromptDeclarations, TextPromptDeclarations, TogglePromptDeclarations } from "./prompts-builtin.cjs";
|
|
2
|
-
export { BasePromptDeclarations, ConfirmPromptDeclarations, NumericPromptDeclarations, PasswordPromptDeclaration, PromptsBuiltin, PromptsBuiltinProps, SelectPromptDeclarations, TextPromptDeclarations, TogglePromptDeclarations };
|
|
1
|
+
import { BasePromptDeclarations, ConfirmPromptDeclarations, NumericPromptDeclarations, PasswordPromptDeclaration, PromptsBuiltin, PromptsBuiltinProps, SelectPromptDeclarations, TextPromptDeclarations, TogglePromptDeclarations, WaitForKeyPressDeclaration } from "./prompts-builtin.cjs";
|
|
2
|
+
export { BasePromptDeclarations, ConfirmPromptDeclarations, NumericPromptDeclarations, PasswordPromptDeclaration, PromptsBuiltin, PromptsBuiltinProps, SelectPromptDeclarations, TextPromptDeclarations, TogglePromptDeclarations, WaitForKeyPressDeclaration };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { BasePromptDeclarations, ConfirmPromptDeclarations, NumericPromptDeclarations, PasswordPromptDeclaration, PromptsBuiltin, PromptsBuiltinProps, SelectPromptDeclarations, TextPromptDeclarations, TogglePromptDeclarations } from "./prompts-builtin.mjs";
|
|
2
|
-
export { BasePromptDeclarations, ConfirmPromptDeclarations, NumericPromptDeclarations, PasswordPromptDeclaration, PromptsBuiltin, PromptsBuiltinProps, SelectPromptDeclarations, TextPromptDeclarations, TogglePromptDeclarations };
|
|
1
|
+
import { BasePromptDeclarations, ConfirmPromptDeclarations, NumericPromptDeclarations, PasswordPromptDeclaration, PromptsBuiltin, PromptsBuiltinProps, SelectPromptDeclarations, TextPromptDeclarations, TogglePromptDeclarations, WaitForKeyPressDeclaration } from "./prompts-builtin.mjs";
|
|
2
|
+
export { BasePromptDeclarations, ConfirmPromptDeclarations, NumericPromptDeclarations, PasswordPromptDeclaration, PromptsBuiltin, PromptsBuiltinProps, SelectPromptDeclarations, TextPromptDeclarations, TogglePromptDeclarations, WaitForKeyPressDeclaration };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { BasePromptDeclarations, ConfirmPromptDeclarations, NumericPromptDeclarations, PasswordPromptDeclaration, PromptsBuiltin, SelectPromptDeclarations, TextPromptDeclarations, TogglePromptDeclarations } from "./prompts-builtin.mjs";
|
|
1
|
+
import { BasePromptDeclarations, ConfirmPromptDeclarations, NumericPromptDeclarations, PasswordPromptDeclaration, PromptsBuiltin, SelectPromptDeclarations, TextPromptDeclarations, TogglePromptDeclarations, WaitForKeyPressDeclaration } from "./prompts-builtin.mjs";
|
|
2
2
|
|
|
3
|
-
export { BasePromptDeclarations, ConfirmPromptDeclarations, NumericPromptDeclarations, PasswordPromptDeclaration, PromptsBuiltin, SelectPromptDeclarations, TextPromptDeclarations, TogglePromptDeclarations };
|
|
3
|
+
export { BasePromptDeclarations, ConfirmPromptDeclarations, NumericPromptDeclarations, PasswordPromptDeclaration, PromptsBuiltin, SelectPromptDeclarations, TextPromptDeclarations, TogglePromptDeclarations, WaitForKeyPressDeclaration };
|
|
@@ -369,21 +369,21 @@ function BasePromptDeclarations() {
|
|
|
369
369
|
}),
|
|
370
370
|
(0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
|
|
371
371
|
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
|
|
372
|
-
name: "
|
|
372
|
+
name: "validate",
|
|
373
373
|
"protected": true,
|
|
374
374
|
type: "(value: TValue) => boolean | string | null | undefined | Promise<boolean | string | null | undefined>",
|
|
375
375
|
children: __alloy_js_core.code`() => true; `
|
|
376
376
|
}),
|
|
377
377
|
(0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
|
|
378
378
|
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
|
|
379
|
-
name: "
|
|
379
|
+
name: "parse",
|
|
380
380
|
"protected": true,
|
|
381
381
|
type: "PromptParser<TValue>",
|
|
382
382
|
children: __alloy_js_core.code`(value: string) => value as TValue; `
|
|
383
383
|
}),
|
|
384
384
|
(0, __alloy_js_core_jsx_runtime.createIntrinsic)("hbr", {}),
|
|
385
385
|
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassField, {
|
|
386
|
-
name: "
|
|
386
|
+
name: "format",
|
|
387
387
|
"protected": true,
|
|
388
388
|
type: "PromptFormatter<TValue>",
|
|
389
389
|
children: __alloy_js_core.code`(value: TValue) => String(value); `
|
|
@@ -440,13 +440,13 @@ function BasePromptDeclarations() {
|
|
|
440
440
|
this.description = config.description;
|
|
441
441
|
}
|
|
442
442
|
if (config.validate) {
|
|
443
|
-
this.
|
|
443
|
+
this.validate = config.validate;
|
|
444
444
|
}
|
|
445
445
|
if (config.parse) {
|
|
446
|
-
this.
|
|
446
|
+
this.parse = config.parse.bind(this);
|
|
447
447
|
}
|
|
448
448
|
if (config.format) {
|
|
449
|
-
this.
|
|
449
|
+
this.format = config.format.bind(this);
|
|
450
450
|
}
|
|
451
451
|
|
|
452
452
|
if (config.maskCompleted) {
|
|
@@ -516,7 +516,7 @@ function BasePromptDeclarations() {
|
|
|
516
516
|
"protected": true,
|
|
517
517
|
name: "isPlaceholder",
|
|
518
518
|
type: "boolean",
|
|
519
|
-
children: __alloy_js_core.code`return (this.displayValue === this.
|
|
519
|
+
children: __alloy_js_core.code`return (this.displayValue === this.format(this.initialValue) && !this.#isDirty) || !this.#isKeyPressed; `
|
|
520
520
|
}),
|
|
521
521
|
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
522
522
|
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassPropertyGet, {
|
|
@@ -569,7 +569,7 @@ function BasePromptDeclarations() {
|
|
|
569
569
|
updatedValue = value;
|
|
570
570
|
}
|
|
571
571
|
|
|
572
|
-
this.displayValue = this.mask(this.
|
|
572
|
+
this.displayValue = this.mask(this.format(updatedValue));
|
|
573
573
|
this.#value = updatedValue;
|
|
574
574
|
|
|
575
575
|
if (!this.#isDirty && this.#value !== this.initialValue) {
|
|
@@ -578,7 +578,7 @@ function BasePromptDeclarations() {
|
|
|
578
578
|
|
|
579
579
|
this.onChange(previousValue);
|
|
580
580
|
setTimeout(() => {
|
|
581
|
-
Promise.resolve(this.
|
|
581
|
+
Promise.resolve(this.checkValidations(updatedValue)).then(() => this.sync());
|
|
582
582
|
}, 0);
|
|
583
583
|
|
|
584
584
|
this.sync(); `
|
|
@@ -675,14 +675,14 @@ function BasePromptDeclarations() {
|
|
|
675
675
|
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
676
676
|
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
|
|
677
677
|
doc: "A method to validate the prompt input using the provided validator function, which updates the error message and error state based on the validation result. This method is called whenever the prompt value changes and needs to be validated.",
|
|
678
|
-
name: "
|
|
678
|
+
name: "checkValidations",
|
|
679
679
|
async: true,
|
|
680
680
|
"protected": true,
|
|
681
681
|
parameters: [{
|
|
682
682
|
name: "value",
|
|
683
683
|
type: "TValue"
|
|
684
684
|
}],
|
|
685
|
-
children: __alloy_js_core.code`let result = await this.
|
|
685
|
+
children: __alloy_js_core.code`let result = await this.validate(value);
|
|
686
686
|
if (typeof result === "string") {
|
|
687
687
|
this.errorMessage = result;
|
|
688
688
|
} else if (typeof result === "boolean") {
|
|
@@ -759,11 +759,11 @@ function BasePromptDeclarations() {
|
|
|
759
759
|
return this.bell();
|
|
760
760
|
}
|
|
761
761
|
|
|
762
|
-
this.changeValue(\`\${
|
|
762
|
+
this.changeValue(this.parse(\`\${
|
|
763
763
|
this.displayValue.slice(0, this.cursor - 1)
|
|
764
764
|
}\${
|
|
765
765
|
this.displayValue.slice(this.cursor)
|
|
766
|
-
}\`);
|
|
766
|
+
}\`));
|
|
767
767
|
|
|
768
768
|
if (this.isCursorAtStart) {
|
|
769
769
|
this.cursorOffset = 0;
|
|
@@ -783,11 +783,11 @@ function BasePromptDeclarations() {
|
|
|
783
783
|
return this.bell();
|
|
784
784
|
}
|
|
785
785
|
|
|
786
|
-
this.changeValue(\`\${
|
|
786
|
+
this.changeValue(this.parse(\`\${
|
|
787
787
|
this.displayValue.slice(0, this.cursor)
|
|
788
788
|
}\${
|
|
789
789
|
this.displayValue.slice(this.cursor + 1)
|
|
790
|
-
}\`);
|
|
790
|
+
}\`));
|
|
791
791
|
|
|
792
792
|
if (this.isCursorAtEnd) {
|
|
793
793
|
this.cursorOffset = 0;
|
|
@@ -833,7 +833,7 @@ function BasePromptDeclarations() {
|
|
|
833
833
|
children: __alloy_js_core.code`this.cursorOffset = 0;
|
|
834
834
|
this.cursor = this.displayValue.length;
|
|
835
835
|
|
|
836
|
-
await this.
|
|
836
|
+
await this.checkValidations(this.value);
|
|
837
837
|
if (this.isError) {
|
|
838
838
|
this.sync();
|
|
839
839
|
this.bell();
|
|
@@ -1084,7 +1084,7 @@ function TextPromptDeclarations() {
|
|
|
1084
1084
|
"protected": true,
|
|
1085
1085
|
parameters: [{
|
|
1086
1086
|
name: "previousValue",
|
|
1087
|
-
type: "
|
|
1087
|
+
type: "string"
|
|
1088
1088
|
}],
|
|
1089
1089
|
children: __alloy_js_core.code`this.#isInvalid = false;
|
|
1090
1090
|
this.cursor = this.displayValue.slice(0, this.cursor).length + 1; `
|
|
@@ -1101,11 +1101,11 @@ function TextPromptDeclarations() {
|
|
|
1101
1101
|
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
1102
1102
|
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
|
|
1103
1103
|
doc: "A method to validate the prompt input",
|
|
1104
|
-
name: "
|
|
1104
|
+
name: "checkValidations",
|
|
1105
1105
|
override: true,
|
|
1106
1106
|
async: true,
|
|
1107
1107
|
"protected": true,
|
|
1108
|
-
children: __alloy_js_core.code`await super.
|
|
1108
|
+
children: __alloy_js_core.code`await super.checkValidations(this.value);
|
|
1109
1109
|
this.#isInvalid = this.isError; `
|
|
1110
1110
|
}),
|
|
1111
1111
|
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
@@ -1834,17 +1834,17 @@ function NumericPromptDeclarations() {
|
|
|
1834
1834
|
}
|
|
1835
1835
|
|
|
1836
1836
|
if (config.parse) {
|
|
1837
|
-
this.
|
|
1837
|
+
this.parse = config.parse.bind(this);
|
|
1838
1838
|
} else {
|
|
1839
|
-
const
|
|
1840
|
-
this.
|
|
1839
|
+
const parse = (value: string) => this.isFloat ? Math.round(Math.pow(10, this.precision) * Number.parseFloat(value)) / Math.pow(10, this.precision) : Number.parseInt(value);
|
|
1840
|
+
this.parse = parse.bind(this);
|
|
1841
1841
|
}
|
|
1842
1842
|
|
|
1843
1843
|
if (config.validate) {
|
|
1844
|
-
this.
|
|
1844
|
+
this.validate = config.validate.bind(this);
|
|
1845
1845
|
} else {
|
|
1846
|
-
const
|
|
1847
|
-
this.
|
|
1846
|
+
const validate = (value: number) => !Number.isNaN(value) && value >= this.min && value <= this.max;
|
|
1847
|
+
this.validate = validate.bind(this);
|
|
1848
1848
|
}
|
|
1849
1849
|
|
|
1850
1850
|
this.changeValue(this.initialValue);
|
|
@@ -1880,7 +1880,7 @@ function NumericPromptDeclarations() {
|
|
|
1880
1880
|
this.displayValue.slice(this.cursor)
|
|
1881
1881
|
}\`;
|
|
1882
1882
|
|
|
1883
|
-
let value = this.
|
|
1883
|
+
let value = this.parse(displayValue);
|
|
1884
1884
|
if (!Number.isNaN(value)) {
|
|
1885
1885
|
|
|
1886
1886
|
value = Math.min(value, this.max);
|
|
@@ -1903,7 +1903,7 @@ function NumericPromptDeclarations() {
|
|
|
1903
1903
|
"protected": true,
|
|
1904
1904
|
parameters: [{
|
|
1905
1905
|
name: "previousValue",
|
|
1906
|
-
type: "
|
|
1906
|
+
type: "number"
|
|
1907
1907
|
}],
|
|
1908
1908
|
children: __alloy_js_core.code`this.#isInvalid = false;
|
|
1909
1909
|
this.cursor = this.displayValue.slice(0, this.cursor).length + 1; `
|
|
@@ -1911,11 +1911,11 @@ function NumericPromptDeclarations() {
|
|
|
1911
1911
|
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
1912
1912
|
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
|
|
1913
1913
|
doc: "A method to validate the prompt input",
|
|
1914
|
-
name: "
|
|
1914
|
+
name: "checkValidations",
|
|
1915
1915
|
override: true,
|
|
1916
1916
|
async: true,
|
|
1917
1917
|
"protected": true,
|
|
1918
|
-
children: __alloy_js_core.code`await super.
|
|
1918
|
+
children: __alloy_js_core.code`await super.checkValidations(this.value);
|
|
1919
1919
|
this.#isInvalid = this.isError; `
|
|
1920
1920
|
}),
|
|
1921
1921
|
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
@@ -2501,16 +2501,14 @@ function ConfirmPromptDeclarations() {
|
|
|
2501
2501
|
}
|
|
2502
2502
|
|
|
2503
2503
|
if (char.toLowerCase() === "y" || char.toLowerCase() === "t" || char.toLowerCase() === "0") {
|
|
2504
|
-
this.
|
|
2504
|
+
this.changeValue(true);
|
|
2505
2505
|
return this.submit();
|
|
2506
2506
|
} else if (char.toLowerCase() === "n" || char.toLowerCase() === "f" || char.toLowerCase() === "1") {
|
|
2507
|
-
this.
|
|
2507
|
+
this.changeValue(false);
|
|
2508
2508
|
return this.submit();
|
|
2509
2509
|
} else {
|
|
2510
2510
|
return this.bell();
|
|
2511
|
-
}
|
|
2512
|
-
|
|
2513
|
-
this.sync(); `
|
|
2511
|
+
} `
|
|
2514
2512
|
}),
|
|
2515
2513
|
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
2516
2514
|
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_class_declaration.ClassMethod, {
|
|
@@ -2652,6 +2650,50 @@ run(); ` }),
|
|
|
2652
2650
|
})
|
|
2653
2651
|
];
|
|
2654
2652
|
}
|
|
2653
|
+
function WaitForKeyPressDeclaration() {
|
|
2654
|
+
return [(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
|
|
2655
|
+
heading: "A function to create and run a wait-for-key-press prompt, which returns a promise that resolves when any key is pressed or rejects with a {@link CANCEL_SYMBOL | cancel symbol} if the prompt is cancelled.",
|
|
2656
|
+
get children() {
|
|
2657
|
+
return [
|
|
2658
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocRemarks, { children: __alloy_js_core.code`This function creates an instance of the Prompt class with a custom onKeyPress handler that resolves the promise when any key is pressed. It sets up event listeners for state updates and cancellation to handle the prompt interactions and return the appropriate results. The wait-for-key-press prompt is useful for scenarios where you want to pause execution until the user presses any key, such as waiting for user input before proceeding with a task.` }),
|
|
2659
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
2660
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocExample, { children: `import { waitForKeyPress } from "shell-shock:prompts";
|
|
2661
|
+
|
|
2662
|
+
async function run() {
|
|
2663
|
+
const result = await waitForKeyPress();
|
|
2664
|
+
console.log("A key was pressed!");
|
|
2665
|
+
}
|
|
2666
|
+
|
|
2667
|
+
run(); ` }),
|
|
2668
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
2669
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocParam, {
|
|
2670
|
+
name: "timeout",
|
|
2671
|
+
children: `The amount of time in milliseconds to wait before automatically resolving the prompt, defaults to 2 hours (7200000 ms)`
|
|
2672
|
+
}),
|
|
2673
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_typescript_components_tsdoc.TSDocReturns, { children: `A promise that resolves when any key is pressed` })
|
|
2674
|
+
];
|
|
2675
|
+
}
|
|
2676
|
+
}), (0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_typescript.FunctionDeclaration, {
|
|
2677
|
+
name: "waitForKeyPress",
|
|
2678
|
+
"export": true,
|
|
2679
|
+
parameters: [{
|
|
2680
|
+
name: "timeout",
|
|
2681
|
+
default: "7200000"
|
|
2682
|
+
}],
|
|
2683
|
+
children: __alloy_js_core.code`process.stdin.setRawMode(true);
|
|
2684
|
+
return new Promise(resolve => process.stdin.once("data", () => {
|
|
2685
|
+
if (timeout >= 0) {
|
|
2686
|
+
setTimeout(() => {
|
|
2687
|
+
process.stdin.setRawMode(false);
|
|
2688
|
+
resolve(void 0);
|
|
2689
|
+
}, timeout);
|
|
2690
|
+
}
|
|
2691
|
+
|
|
2692
|
+
process.stdin.setRawMode(false);
|
|
2693
|
+
resolve(void 0);
|
|
2694
|
+
})); `
|
|
2695
|
+
})];
|
|
2696
|
+
}
|
|
2655
2697
|
/**
|
|
2656
2698
|
* A built-in prompts module for Shell Shock.
|
|
2657
2699
|
*/
|
|
@@ -2705,6 +2747,8 @@ function PromptsBuiltin(props) {
|
|
|
2705
2747
|
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
2706
2748
|
(0, __alloy_js_core_jsx_runtime.createComponent)(ConfirmPromptDeclarations, {}),
|
|
2707
2749
|
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
2750
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(WaitForKeyPressDeclaration, {}),
|
|
2751
|
+
(0, __alloy_js_core_jsx_runtime.createComponent)(__powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
|
|
2708
2752
|
(0, __alloy_js_core_jsx_runtime.createComponent)(__alloy_js_core.Show, {
|
|
2709
2753
|
get when() {
|
|
2710
2754
|
return Boolean(children);
|
|
@@ -2724,4 +2768,5 @@ exports.PasswordPromptDeclaration = PasswordPromptDeclaration;
|
|
|
2724
2768
|
exports.PromptsBuiltin = PromptsBuiltin;
|
|
2725
2769
|
exports.SelectPromptDeclarations = SelectPromptDeclarations;
|
|
2726
2770
|
exports.TextPromptDeclarations = TextPromptDeclarations;
|
|
2727
|
-
exports.TogglePromptDeclarations = TogglePromptDeclarations;
|
|
2771
|
+
exports.TogglePromptDeclarations = TogglePromptDeclarations;
|
|
2772
|
+
exports.WaitForKeyPressDeclaration = WaitForKeyPressDeclaration;
|
|
@@ -31,10 +31,11 @@ declare function ConfirmPromptDeclarations(): _alloy_js_core0.Children;
|
|
|
31
31
|
* Declarations for a password prompt that allows users to input and edit text, with support for cursor movement, deletion, and custom masking. This prompt type can be used for various text input scenarios, such as entering a password or any other string input. The PasswordPrompt class extends the base Prompt class and implements specific logic for handling password input and editing interactions.
|
|
32
32
|
*/
|
|
33
33
|
declare function PasswordPromptDeclaration(): _alloy_js_core0.Children;
|
|
34
|
+
declare function WaitForKeyPressDeclaration(): _alloy_js_core0.Children;
|
|
34
35
|
/**
|
|
35
36
|
* A built-in prompts module for Shell Shock.
|
|
36
37
|
*/
|
|
37
38
|
declare function PromptsBuiltin(props: PromptsBuiltinProps): _alloy_js_core0.Children;
|
|
38
39
|
//#endregion
|
|
39
|
-
export { BasePromptDeclarations, ConfirmPromptDeclarations, NumericPromptDeclarations, PasswordPromptDeclaration, PromptsBuiltin, PromptsBuiltinProps, SelectPromptDeclarations, TextPromptDeclarations, TogglePromptDeclarations };
|
|
40
|
+
export { BasePromptDeclarations, ConfirmPromptDeclarations, NumericPromptDeclarations, PasswordPromptDeclaration, PromptsBuiltin, PromptsBuiltinProps, SelectPromptDeclarations, TextPromptDeclarations, TogglePromptDeclarations, WaitForKeyPressDeclaration };
|
|
40
41
|
//# sourceMappingURL=prompts-builtin.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompts-builtin.d.cts","names":[],"sources":["../../src/components/prompts-builtin.tsx"],"sourcesContent":[],"mappings":";;;;UA8CiB,mBAAA,SAA4B,KAC3C;;AADF;AAQA;AA21BgB,iBA31BA,sBAAA,CAAA,CA21BsB,EA31BA,eAAA,CAAA,QA21BA;AAoPtC;AAobA;AAyVA;AA4OgB,iBA7uCA,sBAAA,CAAA,CA6uCyB,EA7uCH,eAAA,CAAA,QA6uCG;
|
|
1
|
+
{"version":3,"file":"prompts-builtin.d.cts","names":[],"sources":["../../src/components/prompts-builtin.tsx"],"sourcesContent":[],"mappings":";;;;UA8CiB,mBAAA,SAA4B,KAC3C;;AADF;AAQA;AA21BgB,iBA31BA,sBAAA,CAAA,CA21BsB,EA31BA,eAAA,CAAA,QA21BA;AAoPtC;AAobA;AAyVA;AA4OgB,iBA7uCA,sBAAA,CAAA,CA6uCyB,EA7uCH,eAAA,CAAA,QA6uCG;AA4LzC;AAmEA;AAuDA;iBA/yCgB,wBAAA,CAAA,GAAwB,eAAA,CAAA;;;;iBAobxB,yBAAA,CAAA,GAAyB,eAAA,CAAA;;;;iBAyVzB,wBAAA,CAAA,GAAwB,eAAA,CAAA;;;;iBA4OxB,yBAAA,CAAA,GAAyB,eAAA,CAAA;;;;iBA4LzB,yBAAA,CAAA,GAAyB,eAAA,CAAA;iBAmEzB,0BAAA,CAAA,GAA0B,eAAA,CAAA;;;;iBAuD1B,cAAA,QAAsB,sBAAmB,eAAA,CAAA"}
|
|
@@ -31,10 +31,11 @@ declare function ConfirmPromptDeclarations(): _alloy_js_core0.Children;
|
|
|
31
31
|
* Declarations for a password prompt that allows users to input and edit text, with support for cursor movement, deletion, and custom masking. This prompt type can be used for various text input scenarios, such as entering a password or any other string input. The PasswordPrompt class extends the base Prompt class and implements specific logic for handling password input and editing interactions.
|
|
32
32
|
*/
|
|
33
33
|
declare function PasswordPromptDeclaration(): _alloy_js_core0.Children;
|
|
34
|
+
declare function WaitForKeyPressDeclaration(): _alloy_js_core0.Children;
|
|
34
35
|
/**
|
|
35
36
|
* A built-in prompts module for Shell Shock.
|
|
36
37
|
*/
|
|
37
38
|
declare function PromptsBuiltin(props: PromptsBuiltinProps): _alloy_js_core0.Children;
|
|
38
39
|
//#endregion
|
|
39
|
-
export { BasePromptDeclarations, ConfirmPromptDeclarations, NumericPromptDeclarations, PasswordPromptDeclaration, PromptsBuiltin, PromptsBuiltinProps, SelectPromptDeclarations, TextPromptDeclarations, TogglePromptDeclarations };
|
|
40
|
+
export { BasePromptDeclarations, ConfirmPromptDeclarations, NumericPromptDeclarations, PasswordPromptDeclaration, PromptsBuiltin, PromptsBuiltinProps, SelectPromptDeclarations, TextPromptDeclarations, TogglePromptDeclarations, WaitForKeyPressDeclaration };
|
|
40
41
|
//# sourceMappingURL=prompts-builtin.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompts-builtin.d.mts","names":[],"sources":["../../src/components/prompts-builtin.tsx"],"sourcesContent":[],"mappings":";;;;UA8CiB,mBAAA,SAA4B,KAC3C;;AADF;AAQA;AA21BgB,iBA31BA,sBAAA,CAAA,CA21BsB,EA31BA,eAAA,CAAA,QA21BA;AAoPtC;AAobA;AAyVA;AA4OgB,iBA7uCA,sBAAA,CAAA,CA6uCyB,EA7uCH,eAAA,CAAA,QA6uCG;
|
|
1
|
+
{"version":3,"file":"prompts-builtin.d.mts","names":[],"sources":["../../src/components/prompts-builtin.tsx"],"sourcesContent":[],"mappings":";;;;UA8CiB,mBAAA,SAA4B,KAC3C;;AADF;AAQA;AA21BgB,iBA31BA,sBAAA,CAAA,CA21BsB,EA31BA,eAAA,CAAA,QA21BA;AAoPtC;AAobA;AAyVA;AA4OgB,iBA7uCA,sBAAA,CAAA,CA6uCyB,EA7uCH,eAAA,CAAA,QA6uCG;AA4LzC;AAmEA;AAuDA;iBA/yCgB,wBAAA,CAAA,GAAwB,eAAA,CAAA;;;;iBAobxB,yBAAA,CAAA,GAAyB,eAAA,CAAA;;;;iBAyVzB,wBAAA,CAAA,GAAwB,eAAA,CAAA;;;;iBA4OxB,yBAAA,CAAA,GAAyB,eAAA,CAAA;;;;iBA4LzB,yBAAA,CAAA,GAAyB,eAAA,CAAA;iBAmEzB,0BAAA,CAAA,GAA0B,eAAA,CAAA;;;;iBAuD1B,cAAA,QAAsB,sBAAmB,eAAA,CAAA"}
|
|
@@ -367,21 +367,21 @@ function BasePromptDeclarations() {
|
|
|
367
367
|
}),
|
|
368
368
|
createIntrinsic("hbr", {}),
|
|
369
369
|
createComponent(ClassField, {
|
|
370
|
-
name: "
|
|
370
|
+
name: "validate",
|
|
371
371
|
"protected": true,
|
|
372
372
|
type: "(value: TValue) => boolean | string | null | undefined | Promise<boolean | string | null | undefined>",
|
|
373
373
|
children: code`() => true; `
|
|
374
374
|
}),
|
|
375
375
|
createIntrinsic("hbr", {}),
|
|
376
376
|
createComponent(ClassField, {
|
|
377
|
-
name: "
|
|
377
|
+
name: "parse",
|
|
378
378
|
"protected": true,
|
|
379
379
|
type: "PromptParser<TValue>",
|
|
380
380
|
children: code`(value: string) => value as TValue; `
|
|
381
381
|
}),
|
|
382
382
|
createIntrinsic("hbr", {}),
|
|
383
383
|
createComponent(ClassField, {
|
|
384
|
-
name: "
|
|
384
|
+
name: "format",
|
|
385
385
|
"protected": true,
|
|
386
386
|
type: "PromptFormatter<TValue>",
|
|
387
387
|
children: code`(value: TValue) => String(value); `
|
|
@@ -438,13 +438,13 @@ function BasePromptDeclarations() {
|
|
|
438
438
|
this.description = config.description;
|
|
439
439
|
}
|
|
440
440
|
if (config.validate) {
|
|
441
|
-
this.
|
|
441
|
+
this.validate = config.validate;
|
|
442
442
|
}
|
|
443
443
|
if (config.parse) {
|
|
444
|
-
this.
|
|
444
|
+
this.parse = config.parse.bind(this);
|
|
445
445
|
}
|
|
446
446
|
if (config.format) {
|
|
447
|
-
this.
|
|
447
|
+
this.format = config.format.bind(this);
|
|
448
448
|
}
|
|
449
449
|
|
|
450
450
|
if (config.maskCompleted) {
|
|
@@ -514,7 +514,7 @@ function BasePromptDeclarations() {
|
|
|
514
514
|
"protected": true,
|
|
515
515
|
name: "isPlaceholder",
|
|
516
516
|
type: "boolean",
|
|
517
|
-
children: code`return (this.displayValue === this.
|
|
517
|
+
children: code`return (this.displayValue === this.format(this.initialValue) && !this.#isDirty) || !this.#isKeyPressed; `
|
|
518
518
|
}),
|
|
519
519
|
createComponent(Spacing, {}),
|
|
520
520
|
createComponent(ClassPropertyGet, {
|
|
@@ -567,7 +567,7 @@ function BasePromptDeclarations() {
|
|
|
567
567
|
updatedValue = value;
|
|
568
568
|
}
|
|
569
569
|
|
|
570
|
-
this.displayValue = this.mask(this.
|
|
570
|
+
this.displayValue = this.mask(this.format(updatedValue));
|
|
571
571
|
this.#value = updatedValue;
|
|
572
572
|
|
|
573
573
|
if (!this.#isDirty && this.#value !== this.initialValue) {
|
|
@@ -576,7 +576,7 @@ function BasePromptDeclarations() {
|
|
|
576
576
|
|
|
577
577
|
this.onChange(previousValue);
|
|
578
578
|
setTimeout(() => {
|
|
579
|
-
Promise.resolve(this.
|
|
579
|
+
Promise.resolve(this.checkValidations(updatedValue)).then(() => this.sync());
|
|
580
580
|
}, 0);
|
|
581
581
|
|
|
582
582
|
this.sync(); `
|
|
@@ -673,14 +673,14 @@ function BasePromptDeclarations() {
|
|
|
673
673
|
createComponent(Spacing, {}),
|
|
674
674
|
createComponent(ClassMethod, {
|
|
675
675
|
doc: "A method to validate the prompt input using the provided validator function, which updates the error message and error state based on the validation result. This method is called whenever the prompt value changes and needs to be validated.",
|
|
676
|
-
name: "
|
|
676
|
+
name: "checkValidations",
|
|
677
677
|
async: true,
|
|
678
678
|
"protected": true,
|
|
679
679
|
parameters: [{
|
|
680
680
|
name: "value",
|
|
681
681
|
type: "TValue"
|
|
682
682
|
}],
|
|
683
|
-
children: code`let result = await this.
|
|
683
|
+
children: code`let result = await this.validate(value);
|
|
684
684
|
if (typeof result === "string") {
|
|
685
685
|
this.errorMessage = result;
|
|
686
686
|
} else if (typeof result === "boolean") {
|
|
@@ -757,11 +757,11 @@ function BasePromptDeclarations() {
|
|
|
757
757
|
return this.bell();
|
|
758
758
|
}
|
|
759
759
|
|
|
760
|
-
this.changeValue(\`\${
|
|
760
|
+
this.changeValue(this.parse(\`\${
|
|
761
761
|
this.displayValue.slice(0, this.cursor - 1)
|
|
762
762
|
}\${
|
|
763
763
|
this.displayValue.slice(this.cursor)
|
|
764
|
-
}\`);
|
|
764
|
+
}\`));
|
|
765
765
|
|
|
766
766
|
if (this.isCursorAtStart) {
|
|
767
767
|
this.cursorOffset = 0;
|
|
@@ -781,11 +781,11 @@ function BasePromptDeclarations() {
|
|
|
781
781
|
return this.bell();
|
|
782
782
|
}
|
|
783
783
|
|
|
784
|
-
this.changeValue(\`\${
|
|
784
|
+
this.changeValue(this.parse(\`\${
|
|
785
785
|
this.displayValue.slice(0, this.cursor)
|
|
786
786
|
}\${
|
|
787
787
|
this.displayValue.slice(this.cursor + 1)
|
|
788
|
-
}\`);
|
|
788
|
+
}\`));
|
|
789
789
|
|
|
790
790
|
if (this.isCursorAtEnd) {
|
|
791
791
|
this.cursorOffset = 0;
|
|
@@ -831,7 +831,7 @@ function BasePromptDeclarations() {
|
|
|
831
831
|
children: code`this.cursorOffset = 0;
|
|
832
832
|
this.cursor = this.displayValue.length;
|
|
833
833
|
|
|
834
|
-
await this.
|
|
834
|
+
await this.checkValidations(this.value);
|
|
835
835
|
if (this.isError) {
|
|
836
836
|
this.sync();
|
|
837
837
|
this.bell();
|
|
@@ -1082,7 +1082,7 @@ function TextPromptDeclarations() {
|
|
|
1082
1082
|
"protected": true,
|
|
1083
1083
|
parameters: [{
|
|
1084
1084
|
name: "previousValue",
|
|
1085
|
-
type: "
|
|
1085
|
+
type: "string"
|
|
1086
1086
|
}],
|
|
1087
1087
|
children: code`this.#isInvalid = false;
|
|
1088
1088
|
this.cursor = this.displayValue.slice(0, this.cursor).length + 1; `
|
|
@@ -1099,11 +1099,11 @@ function TextPromptDeclarations() {
|
|
|
1099
1099
|
createComponent(Spacing, {}),
|
|
1100
1100
|
createComponent(ClassMethod, {
|
|
1101
1101
|
doc: "A method to validate the prompt input",
|
|
1102
|
-
name: "
|
|
1102
|
+
name: "checkValidations",
|
|
1103
1103
|
override: true,
|
|
1104
1104
|
async: true,
|
|
1105
1105
|
"protected": true,
|
|
1106
|
-
children: code`await super.
|
|
1106
|
+
children: code`await super.checkValidations(this.value);
|
|
1107
1107
|
this.#isInvalid = this.isError; `
|
|
1108
1108
|
}),
|
|
1109
1109
|
createComponent(Spacing, {}),
|
|
@@ -1832,17 +1832,17 @@ function NumericPromptDeclarations() {
|
|
|
1832
1832
|
}
|
|
1833
1833
|
|
|
1834
1834
|
if (config.parse) {
|
|
1835
|
-
this.
|
|
1835
|
+
this.parse = config.parse.bind(this);
|
|
1836
1836
|
} else {
|
|
1837
|
-
const
|
|
1838
|
-
this.
|
|
1837
|
+
const parse = (value: string) => this.isFloat ? Math.round(Math.pow(10, this.precision) * Number.parseFloat(value)) / Math.pow(10, this.precision) : Number.parseInt(value);
|
|
1838
|
+
this.parse = parse.bind(this);
|
|
1839
1839
|
}
|
|
1840
1840
|
|
|
1841
1841
|
if (config.validate) {
|
|
1842
|
-
this.
|
|
1842
|
+
this.validate = config.validate.bind(this);
|
|
1843
1843
|
} else {
|
|
1844
|
-
const
|
|
1845
|
-
this.
|
|
1844
|
+
const validate = (value: number) => !Number.isNaN(value) && value >= this.min && value <= this.max;
|
|
1845
|
+
this.validate = validate.bind(this);
|
|
1846
1846
|
}
|
|
1847
1847
|
|
|
1848
1848
|
this.changeValue(this.initialValue);
|
|
@@ -1878,7 +1878,7 @@ function NumericPromptDeclarations() {
|
|
|
1878
1878
|
this.displayValue.slice(this.cursor)
|
|
1879
1879
|
}\`;
|
|
1880
1880
|
|
|
1881
|
-
let value = this.
|
|
1881
|
+
let value = this.parse(displayValue);
|
|
1882
1882
|
if (!Number.isNaN(value)) {
|
|
1883
1883
|
|
|
1884
1884
|
value = Math.min(value, this.max);
|
|
@@ -1901,7 +1901,7 @@ function NumericPromptDeclarations() {
|
|
|
1901
1901
|
"protected": true,
|
|
1902
1902
|
parameters: [{
|
|
1903
1903
|
name: "previousValue",
|
|
1904
|
-
type: "
|
|
1904
|
+
type: "number"
|
|
1905
1905
|
}],
|
|
1906
1906
|
children: code`this.#isInvalid = false;
|
|
1907
1907
|
this.cursor = this.displayValue.slice(0, this.cursor).length + 1; `
|
|
@@ -1909,11 +1909,11 @@ function NumericPromptDeclarations() {
|
|
|
1909
1909
|
createComponent(Spacing, {}),
|
|
1910
1910
|
createComponent(ClassMethod, {
|
|
1911
1911
|
doc: "A method to validate the prompt input",
|
|
1912
|
-
name: "
|
|
1912
|
+
name: "checkValidations",
|
|
1913
1913
|
override: true,
|
|
1914
1914
|
async: true,
|
|
1915
1915
|
"protected": true,
|
|
1916
|
-
children: code`await super.
|
|
1916
|
+
children: code`await super.checkValidations(this.value);
|
|
1917
1917
|
this.#isInvalid = this.isError; `
|
|
1918
1918
|
}),
|
|
1919
1919
|
createComponent(Spacing, {}),
|
|
@@ -2499,16 +2499,14 @@ function ConfirmPromptDeclarations() {
|
|
|
2499
2499
|
}
|
|
2500
2500
|
|
|
2501
2501
|
if (char.toLowerCase() === "y" || char.toLowerCase() === "t" || char.toLowerCase() === "0") {
|
|
2502
|
-
this.
|
|
2502
|
+
this.changeValue(true);
|
|
2503
2503
|
return this.submit();
|
|
2504
2504
|
} else if (char.toLowerCase() === "n" || char.toLowerCase() === "f" || char.toLowerCase() === "1") {
|
|
2505
|
-
this.
|
|
2505
|
+
this.changeValue(false);
|
|
2506
2506
|
return this.submit();
|
|
2507
2507
|
} else {
|
|
2508
2508
|
return this.bell();
|
|
2509
|
-
}
|
|
2510
|
-
|
|
2511
|
-
this.sync(); `
|
|
2509
|
+
} `
|
|
2512
2510
|
}),
|
|
2513
2511
|
createComponent(Spacing, {}),
|
|
2514
2512
|
createComponent(ClassMethod, {
|
|
@@ -2650,6 +2648,50 @@ run(); ` }),
|
|
|
2650
2648
|
})
|
|
2651
2649
|
];
|
|
2652
2650
|
}
|
|
2651
|
+
function WaitForKeyPressDeclaration() {
|
|
2652
|
+
return [createComponent(TSDoc, {
|
|
2653
|
+
heading: "A function to create and run a wait-for-key-press prompt, which returns a promise that resolves when any key is pressed or rejects with a {@link CANCEL_SYMBOL | cancel symbol} if the prompt is cancelled.",
|
|
2654
|
+
get children() {
|
|
2655
|
+
return [
|
|
2656
|
+
createComponent(TSDocRemarks, { children: code`This function creates an instance of the Prompt class with a custom onKeyPress handler that resolves the promise when any key is pressed. It sets up event listeners for state updates and cancellation to handle the prompt interactions and return the appropriate results. The wait-for-key-press prompt is useful for scenarios where you want to pause execution until the user presses any key, such as waiting for user input before proceeding with a task.` }),
|
|
2657
|
+
createComponent(Spacing, {}),
|
|
2658
|
+
createComponent(TSDocExample, { children: `import { waitForKeyPress } from "shell-shock:prompts";
|
|
2659
|
+
|
|
2660
|
+
async function run() {
|
|
2661
|
+
const result = await waitForKeyPress();
|
|
2662
|
+
console.log("A key was pressed!");
|
|
2663
|
+
}
|
|
2664
|
+
|
|
2665
|
+
run(); ` }),
|
|
2666
|
+
createComponent(Spacing, {}),
|
|
2667
|
+
createComponent(TSDocParam, {
|
|
2668
|
+
name: "timeout",
|
|
2669
|
+
children: `The amount of time in milliseconds to wait before automatically resolving the prompt, defaults to 2 hours (7200000 ms)`
|
|
2670
|
+
}),
|
|
2671
|
+
createComponent(TSDocReturns, { children: `A promise that resolves when any key is pressed` })
|
|
2672
|
+
];
|
|
2673
|
+
}
|
|
2674
|
+
}), createComponent(FunctionDeclaration, {
|
|
2675
|
+
name: "waitForKeyPress",
|
|
2676
|
+
"export": true,
|
|
2677
|
+
parameters: [{
|
|
2678
|
+
name: "timeout",
|
|
2679
|
+
default: "7200000"
|
|
2680
|
+
}],
|
|
2681
|
+
children: code`process.stdin.setRawMode(true);
|
|
2682
|
+
return new Promise(resolve => process.stdin.once("data", () => {
|
|
2683
|
+
if (timeout >= 0) {
|
|
2684
|
+
setTimeout(() => {
|
|
2685
|
+
process.stdin.setRawMode(false);
|
|
2686
|
+
resolve(void 0);
|
|
2687
|
+
}, timeout);
|
|
2688
|
+
}
|
|
2689
|
+
|
|
2690
|
+
process.stdin.setRawMode(false);
|
|
2691
|
+
resolve(void 0);
|
|
2692
|
+
})); `
|
|
2693
|
+
})];
|
|
2694
|
+
}
|
|
2653
2695
|
/**
|
|
2654
2696
|
* A built-in prompts module for Shell Shock.
|
|
2655
2697
|
*/
|
|
@@ -2703,6 +2745,8 @@ function PromptsBuiltin(props) {
|
|
|
2703
2745
|
createComponent(Spacing, {}),
|
|
2704
2746
|
createComponent(ConfirmPromptDeclarations, {}),
|
|
2705
2747
|
createComponent(Spacing, {}),
|
|
2748
|
+
createComponent(WaitForKeyPressDeclaration, {}),
|
|
2749
|
+
createComponent(Spacing, {}),
|
|
2706
2750
|
createComponent(Show, {
|
|
2707
2751
|
get when() {
|
|
2708
2752
|
return Boolean(children);
|
|
@@ -2715,5 +2759,5 @@ function PromptsBuiltin(props) {
|
|
|
2715
2759
|
}
|
|
2716
2760
|
|
|
2717
2761
|
//#endregion
|
|
2718
|
-
export { BasePromptDeclarations, ConfirmPromptDeclarations, NumericPromptDeclarations, PasswordPromptDeclaration, PromptsBuiltin, SelectPromptDeclarations, TextPromptDeclarations, TogglePromptDeclarations };
|
|
2762
|
+
export { BasePromptDeclarations, ConfirmPromptDeclarations, NumericPromptDeclarations, PasswordPromptDeclaration, PromptsBuiltin, SelectPromptDeclarations, TextPromptDeclarations, TogglePromptDeclarations, WaitForKeyPressDeclaration };
|
|
2719
2763
|
//# sourceMappingURL=prompts-builtin.mjs.map
|