@shell-shock/preset-cli 0.5.1 → 0.6.0
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/banner-function-declaration.d.cts +2 -2
- package/dist/components/banner-function-declaration.d.cts.map +1 -1
- package/dist/components/banner-function-declaration.d.mts +2 -2
- package/dist/components/command-entry.cjs +96 -45
- 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 +2 -2
- package/dist/components/command-entry.d.mts.map +1 -1
- package/dist/components/command-entry.mjs +96 -45
- package/dist/components/command-entry.mjs.map +1 -1
- 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 +451 -48
- package/dist/components/prompts-builtin.d.cts +5 -1
- package/dist/components/prompts-builtin.d.cts.map +1 -1
- package/dist/components/prompts-builtin.d.mts +5 -1
- package/dist/components/prompts-builtin.d.mts.map +1 -1
- package/dist/components/prompts-builtin.mjs +452 -50
- package/dist/components/prompts-builtin.mjs.map +1 -1
- package/dist/components/virtual-command-entry.cjs +1 -0
- package/dist/components/virtual-command-entry.d.cts +2 -2
- package/dist/components/virtual-command-entry.mjs +1 -0
- package/dist/components/virtual-command-entry.mjs.map +1 -1
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -9
|
@@ -2,12 +2,13 @@ import { createComponent, createIntrinsic, memo, mergeProps } from "@alloy-js/co
|
|
|
2
2
|
import { Show, code, splitProps } from "@alloy-js/core";
|
|
3
3
|
import { FunctionDeclaration, VarDeclaration } from "@alloy-js/typescript";
|
|
4
4
|
import { useTheme } from "@shell-shock/preset-script/contexts/theme";
|
|
5
|
+
import { ReflectionKind } from "@powerlines/deepkit/vendor/type";
|
|
5
6
|
import { Spacing } from "@powerlines/plugin-alloy/core/components/spacing";
|
|
6
7
|
import defu from "defu";
|
|
7
8
|
import { BuiltinFile } from "@powerlines/plugin-alloy/typescript/components/builtin-file";
|
|
8
9
|
import { ClassDeclaration, ClassField, ClassMethod, ClassPropertyGet } from "@powerlines/plugin-alloy/typescript/components/class-declaration";
|
|
9
10
|
import { InterfaceDeclaration, InterfaceMember } from "@powerlines/plugin-alloy/typescript/components/interface-declaration";
|
|
10
|
-
import { TSDoc, TSDocExample, TSDocParam, TSDocRemarks, TSDocReturns } from "@powerlines/plugin-alloy/typescript/components/tsdoc";
|
|
11
|
+
import { TSDoc, TSDocDefaultValue, TSDocExample, TSDocParam, TSDocRemarks, TSDocReturns } from "@powerlines/plugin-alloy/typescript/components/tsdoc";
|
|
11
12
|
import { TypeDeclaration } from "@powerlines/plugin-alloy/typescript/components/type-declaration";
|
|
12
13
|
|
|
13
14
|
//#region src/components/prompts-builtin.tsx
|
|
@@ -136,7 +137,7 @@ function BasePromptDeclarations() {
|
|
|
136
137
|
createComponent(Spacing, {}),
|
|
137
138
|
createComponent(InterfaceDeclaration, {
|
|
138
139
|
name: "PromptConfig",
|
|
139
|
-
doc: "Configuration options for
|
|
140
|
+
doc: "Configuration options for creating a prompt",
|
|
140
141
|
typeParameters: [{
|
|
141
142
|
name: "TValue",
|
|
142
143
|
default: "string"
|
|
@@ -180,7 +181,7 @@ function BasePromptDeclarations() {
|
|
|
180
181
|
createComponent(InterfaceMember, {
|
|
181
182
|
name: "validate",
|
|
182
183
|
optional: true,
|
|
183
|
-
type: "(value: TValue) => boolean | string | null | undefined | Promise<boolean | string | null | undefined>",
|
|
184
|
+
type: "(value: TValue) => boolean | string | { type: 'error' | 'warning'; message: string } | null | undefined | Promise<boolean | string | { type: 'error' | 'warning'; message: string } | null | undefined>",
|
|
184
185
|
doc: "A validation function that returns true if the input is valid, false or a string error message if the input is invalid"
|
|
185
186
|
}),
|
|
186
187
|
createComponent(Spacing, {}),
|
|
@@ -299,7 +300,7 @@ function BasePromptDeclarations() {
|
|
|
299
300
|
name: "defaultErrorMessage",
|
|
300
301
|
"protected": true,
|
|
301
302
|
type: "string",
|
|
302
|
-
children: code`"
|
|
303
|
+
children: code`"An invalid value was provided"; `
|
|
303
304
|
}),
|
|
304
305
|
createIntrinsic("hbr", {}),
|
|
305
306
|
createComponent(ClassField, {
|
|
@@ -384,6 +385,13 @@ function BasePromptDeclarations() {
|
|
|
384
385
|
type: "number",
|
|
385
386
|
children: code`0; `
|
|
386
387
|
}),
|
|
388
|
+
createIntrinsic("hbr", {}),
|
|
389
|
+
createComponent(ClassField, {
|
|
390
|
+
name: "cursorHidden",
|
|
391
|
+
"protected": true,
|
|
392
|
+
type: "boolean",
|
|
393
|
+
children: code`false; `
|
|
394
|
+
}),
|
|
387
395
|
createComponent(Spacing, {}),
|
|
388
396
|
code`constructor(protected config: PromptConfig<TValue>) {
|
|
389
397
|
super();
|
|
@@ -709,6 +717,8 @@ function BasePromptDeclarations() {
|
|
|
709
717
|
}
|
|
710
718
|
|
|
711
719
|
this.output.write(clear(this.consoleOutput, this.output.columns));
|
|
720
|
+
} else if (this.cursorHidden) {
|
|
721
|
+
this.output.write(cursor.hide);
|
|
712
722
|
}
|
|
713
723
|
|
|
714
724
|
this.consoleOutput = \` \${
|
|
@@ -794,10 +804,10 @@ function BasePromptDeclarations() {
|
|
|
794
804
|
}
|
|
795
805
|
}),
|
|
796
806
|
createComponent(Spacing, {}),
|
|
807
|
+
createComponent(TSDoc, { heading: "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." }),
|
|
797
808
|
createComponent(VarDeclaration, {
|
|
798
809
|
"export": true,
|
|
799
810
|
name: "CANCEL_SYMBOL",
|
|
800
|
-
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.",
|
|
801
811
|
children: code`Symbol("shell-shock:prompts:cancel"); `
|
|
802
812
|
}),
|
|
803
813
|
createComponent(Spacing, {}),
|
|
@@ -830,7 +840,7 @@ function TextPromptDeclarations() {
|
|
|
830
840
|
createComponent(InterfaceDeclaration, {
|
|
831
841
|
name: "StringPromptConfig",
|
|
832
842
|
"extends": "PromptConfig<string>",
|
|
833
|
-
doc: "Configuration options for
|
|
843
|
+
doc: "Configuration options for creating a text-based prompt",
|
|
834
844
|
get children() {
|
|
835
845
|
return [
|
|
836
846
|
createComponent(InterfaceMember, {
|
|
@@ -880,6 +890,7 @@ function TextPromptDeclarations() {
|
|
|
880
890
|
|
|
881
891
|
this.cursor = 0;
|
|
882
892
|
this.sync();
|
|
893
|
+
this.first();
|
|
883
894
|
} `,
|
|
884
895
|
createComponent(Spacing, {}),
|
|
885
896
|
createComponent(ClassMethod, {
|
|
@@ -1302,6 +1313,14 @@ function SelectPromptDeclarations() {
|
|
|
1302
1313
|
type: "PromptOption<TValue>[]",
|
|
1303
1314
|
children: code`[]; `
|
|
1304
1315
|
}),
|
|
1316
|
+
createIntrinsic("hbr", {}),
|
|
1317
|
+
createComponent(ClassField, {
|
|
1318
|
+
name: "cursorHidden",
|
|
1319
|
+
"protected": true,
|
|
1320
|
+
override: true,
|
|
1321
|
+
type: "boolean",
|
|
1322
|
+
children: code`true; `
|
|
1323
|
+
}),
|
|
1305
1324
|
createComponent(Spacing, {}),
|
|
1306
1325
|
code`constructor(config: SelectPromptConfig<TValue>) {
|
|
1307
1326
|
super(config);
|
|
@@ -1476,11 +1495,7 @@ function SelectPromptDeclarations() {
|
|
|
1476
1495
|
name: "render",
|
|
1477
1496
|
override: true,
|
|
1478
1497
|
"protected": true,
|
|
1479
|
-
children: code`
|
|
1480
|
-
this.output.write(cursor.hide);
|
|
1481
|
-
}
|
|
1482
|
-
|
|
1483
|
-
const spacing = Math.max(...this.options.map(option => option.label?.length || 0)) + 2;
|
|
1498
|
+
children: code`const spacing = Math.max(...this.options.map(option => option.label?.length || 0)) + 2;
|
|
1484
1499
|
|
|
1485
1500
|
const startIndex = Math.max(Math.min(this.options.length - this.optionsPerPage, this.cursor - Math.floor(this.optionsPerPage / 2)), 0);
|
|
1486
1501
|
const endIndex = Math.min(startIndex + this.optionsPerPage, this.options.length);
|
|
@@ -1612,7 +1627,7 @@ function NumericPromptDeclarations() {
|
|
|
1612
1627
|
createComponent(InterfaceDeclaration, {
|
|
1613
1628
|
name: "NumberPromptConfig",
|
|
1614
1629
|
"extends": "PromptConfig<number>",
|
|
1615
|
-
doc: "Configuration options for
|
|
1630
|
+
doc: "Configuration options for creating a numeric prompt",
|
|
1616
1631
|
get children() {
|
|
1617
1632
|
return [
|
|
1618
1633
|
createComponent(InterfaceMember, {
|
|
@@ -1659,6 +1674,13 @@ function NumericPromptDeclarations() {
|
|
|
1659
1674
|
"extends": "Prompt<number>",
|
|
1660
1675
|
get children() {
|
|
1661
1676
|
return [
|
|
1677
|
+
createComponent(ClassField, {
|
|
1678
|
+
name: "isInvalid",
|
|
1679
|
+
isPrivateMember: true,
|
|
1680
|
+
type: "boolean",
|
|
1681
|
+
children: code`false; `
|
|
1682
|
+
}),
|
|
1683
|
+
createComponent(Spacing, {}),
|
|
1662
1684
|
createComponent(ClassField, {
|
|
1663
1685
|
name: "initialValue",
|
|
1664
1686
|
"protected": true,
|
|
@@ -1667,6 +1689,14 @@ function NumericPromptDeclarations() {
|
|
|
1667
1689
|
children: code`0; `
|
|
1668
1690
|
}),
|
|
1669
1691
|
createIntrinsic("hbr", {}),
|
|
1692
|
+
createComponent(ClassField, {
|
|
1693
|
+
name: "defaultErrorMessage",
|
|
1694
|
+
"protected": true,
|
|
1695
|
+
override: true,
|
|
1696
|
+
type: "string",
|
|
1697
|
+
children: code`"A valid numeric value must be provided"; `
|
|
1698
|
+
}),
|
|
1699
|
+
createIntrinsic("hbr", {}),
|
|
1670
1700
|
createComponent(ClassField, {
|
|
1671
1701
|
name: "isFloat",
|
|
1672
1702
|
"protected": true,
|
|
@@ -1752,6 +1782,7 @@ function NumericPromptDeclarations() {
|
|
|
1752
1782
|
}
|
|
1753
1783
|
|
|
1754
1784
|
this.sync();
|
|
1785
|
+
this.last();
|
|
1755
1786
|
} `,
|
|
1756
1787
|
createComponent(Spacing, {}),
|
|
1757
1788
|
createComponent(ClassMethod, {
|
|
@@ -1762,14 +1793,6 @@ function NumericPromptDeclarations() {
|
|
|
1762
1793
|
children: code`super.reset();
|
|
1763
1794
|
this.currentInput = "";
|
|
1764
1795
|
`
|
|
1765
|
-
}),
|
|
1766
|
-
createComponent(Spacing, {}),
|
|
1767
|
-
createComponent(ClassMethod, {
|
|
1768
|
-
doc: "A method to move the cursor to the end of the input",
|
|
1769
|
-
name: "next",
|
|
1770
|
-
"protected": true,
|
|
1771
|
-
children: code`this.changeValue(this.initialValue);
|
|
1772
|
-
this.sync(); `
|
|
1773
1796
|
}),
|
|
1774
1797
|
createComponent(Spacing, {}),
|
|
1775
1798
|
createComponent(ClassMethod, {
|
|
@@ -1793,18 +1816,12 @@ function NumericPromptDeclarations() {
|
|
|
1793
1816
|
return this.bell();
|
|
1794
1817
|
}
|
|
1795
1818
|
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
}
|
|
1799
|
-
|
|
1800
|
-
this.currentInput += char;
|
|
1801
|
-
this.inputTimestamp = Date.now();
|
|
1802
|
-
|
|
1803
|
-
if (char === ".") {
|
|
1819
|
+
this.displayValue += char;
|
|
1820
|
+
if ((char === "-" || char === ".") && this.displayValue.length === 1) {
|
|
1804
1821
|
return this.sync();
|
|
1805
1822
|
}
|
|
1806
1823
|
|
|
1807
|
-
let value = Math.min(this.parser(this.
|
|
1824
|
+
let value = Math.min(this.parser(this.displayValue), this.max);
|
|
1808
1825
|
if (value > this.max) {
|
|
1809
1826
|
value = this.max;
|
|
1810
1827
|
}
|
|
@@ -1813,6 +1830,14 @@ function NumericPromptDeclarations() {
|
|
|
1813
1830
|
}
|
|
1814
1831
|
|
|
1815
1832
|
this.changeValue(value);
|
|
1833
|
+
this.sync(); `
|
|
1834
|
+
}),
|
|
1835
|
+
createComponent(Spacing, {}),
|
|
1836
|
+
createComponent(ClassMethod, {
|
|
1837
|
+
doc: "A method to move the cursor to the end of the input",
|
|
1838
|
+
name: "next",
|
|
1839
|
+
"protected": true,
|
|
1840
|
+
children: code`this.changeValue(this.initialValue);
|
|
1816
1841
|
this.sync(); `
|
|
1817
1842
|
}),
|
|
1818
1843
|
createComponent(Spacing, {}),
|
|
@@ -1820,14 +1845,10 @@ function NumericPromptDeclarations() {
|
|
|
1820
1845
|
doc: "A method to move the cursor to the up",
|
|
1821
1846
|
name: "up",
|
|
1822
1847
|
"protected": true,
|
|
1823
|
-
children: code`
|
|
1824
|
-
|
|
1825
|
-
let value = this.value;
|
|
1848
|
+
children: code`let value = this.value;
|
|
1826
1849
|
if (this.displayValue === "") {
|
|
1827
|
-
value = this.min
|
|
1828
|
-
}
|
|
1829
|
-
|
|
1830
|
-
if (value >= this.max) {
|
|
1850
|
+
value = this.min < 0 ? 0 : this.min;
|
|
1851
|
+
} else if (value >= this.max) {
|
|
1831
1852
|
return this.bell();
|
|
1832
1853
|
}
|
|
1833
1854
|
|
|
@@ -1839,36 +1860,134 @@ function NumericPromptDeclarations() {
|
|
|
1839
1860
|
doc: "A method to move the cursor to the down",
|
|
1840
1861
|
name: "down",
|
|
1841
1862
|
"protected": true,
|
|
1842
|
-
children: code`
|
|
1863
|
+
children: code`let value = this.value;
|
|
1864
|
+
if (this.displayValue === "") {
|
|
1865
|
+
value = this.min < 0 ? 0 : this.min;
|
|
1866
|
+
} else if (value <= this.min) {
|
|
1867
|
+
return this.bell();
|
|
1868
|
+
}
|
|
1843
1869
|
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1870
|
+
this.changeValue(value === this.min ? this.min : value - this.increment);
|
|
1871
|
+
this.sync(); `
|
|
1872
|
+
}),
|
|
1873
|
+
createComponent(Spacing, {}),
|
|
1874
|
+
createComponent(ClassMethod, {
|
|
1875
|
+
doc: "A method to move the cursor to the left",
|
|
1876
|
+
name: "left",
|
|
1877
|
+
"protected": true,
|
|
1878
|
+
children: code`if (this.cursor <= 0 || this.isPlaceholder) {
|
|
1879
|
+
return this.bell();
|
|
1847
1880
|
}
|
|
1848
1881
|
|
|
1849
|
-
|
|
1882
|
+
this.moveCursor(-1);
|
|
1883
|
+
this.sync(); `
|
|
1884
|
+
}),
|
|
1885
|
+
createComponent(Spacing, {}),
|
|
1886
|
+
createComponent(ClassMethod, {
|
|
1887
|
+
doc: "A method to move the cursor to the right",
|
|
1888
|
+
name: "right",
|
|
1889
|
+
"protected": true,
|
|
1890
|
+
children: code`if (this.cursor >= this.displayValue.length || this.isPlaceholder) {
|
|
1850
1891
|
return this.bell();
|
|
1851
1892
|
}
|
|
1852
1893
|
|
|
1853
|
-
this.
|
|
1894
|
+
this.moveCursor(1);
|
|
1854
1895
|
this.sync(); `
|
|
1896
|
+
}),
|
|
1897
|
+
createComponent(Spacing, {}),
|
|
1898
|
+
createComponent(ClassMethod, {
|
|
1899
|
+
doc: "A method to move the cursor to the left or right by a \\`count\\` of positions",
|
|
1900
|
+
name: "moveCursor",
|
|
1901
|
+
parameters: [{
|
|
1902
|
+
name: "count",
|
|
1903
|
+
type: "number"
|
|
1904
|
+
}],
|
|
1905
|
+
"protected": true,
|
|
1906
|
+
children: code`if (this.isPlaceholder) {
|
|
1907
|
+
return;
|
|
1908
|
+
}
|
|
1909
|
+
|
|
1910
|
+
this.cursor = this.cursor + count;
|
|
1911
|
+
this.cursorOffset += count; `
|
|
1855
1912
|
}),
|
|
1856
1913
|
createComponent(Spacing, {}),
|
|
1857
1914
|
createComponent(ClassMethod, {
|
|
1858
1915
|
doc: "A method to delete the character backward of the cursor",
|
|
1859
1916
|
name: "delete",
|
|
1860
1917
|
"protected": true,
|
|
1861
|
-
children: code`if (this.
|
|
1918
|
+
children: code`if (this.isCursorAtStart()) {
|
|
1862
1919
|
return this.bell();
|
|
1863
1920
|
}
|
|
1864
1921
|
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
value = this.min === Number.NEGATIVE_INFINITY ? 0 : this.min;
|
|
1922
|
+
if (this.displayValue === "") {
|
|
1923
|
+
return this.bell();
|
|
1868
1924
|
}
|
|
1869
1925
|
|
|
1870
|
-
this.changeValue(
|
|
1926
|
+
this.changeValue(\`\${this.displayValue.slice(0, this.cursor - 1)}\${this.displayValue.slice(this.cursor)}\`);
|
|
1927
|
+
this.#isInvalid = false;
|
|
1928
|
+
|
|
1929
|
+
if (this.isCursorAtStart()) {
|
|
1930
|
+
this.cursorOffset = 0
|
|
1931
|
+
} else {
|
|
1932
|
+
this.cursorOffset++;
|
|
1933
|
+
this.moveCursor(-1);
|
|
1934
|
+
}
|
|
1935
|
+
|
|
1936
|
+
this.sync(); `
|
|
1937
|
+
}),
|
|
1938
|
+
createComponent(Spacing, {}),
|
|
1939
|
+
createComponent(ClassMethod, {
|
|
1940
|
+
doc: "A method to delete the character forward of the cursor",
|
|
1941
|
+
name: "deleteForward",
|
|
1942
|
+
"protected": true,
|
|
1943
|
+
children: code`if (this.cursor >= this.displayValue.length || this.isPlaceholder) {
|
|
1944
|
+
return this.bell();
|
|
1945
|
+
}
|
|
1946
|
+
|
|
1947
|
+
this.changeValue(\`\${
|
|
1948
|
+
this.displayValue.slice(0, this.cursor)
|
|
1949
|
+
}\${
|
|
1950
|
+
this.displayValue.slice(this.cursor + 1)
|
|
1951
|
+
}\`);
|
|
1952
|
+
this.#isInvalid = false;
|
|
1953
|
+
|
|
1954
|
+
if (this.isCursorAtEnd()) {
|
|
1955
|
+
this.cursorOffset = 0;
|
|
1956
|
+
} else {
|
|
1957
|
+
this.cursorOffset++;
|
|
1958
|
+
}
|
|
1959
|
+
|
|
1960
|
+
this.sync(); `
|
|
1961
|
+
}),
|
|
1962
|
+
createComponent(Spacing, {}),
|
|
1963
|
+
createComponent(ClassMethod, {
|
|
1964
|
+
doc: "A method to move the cursor to the start",
|
|
1965
|
+
name: "first",
|
|
1966
|
+
"protected": true,
|
|
1967
|
+
children: code`this.cursor = 0;
|
|
1968
|
+
this.sync(); `
|
|
1969
|
+
}),
|
|
1970
|
+
createComponent(Spacing, {}),
|
|
1971
|
+
createComponent(ClassMethod, {
|
|
1972
|
+
doc: "A method to move the cursor to the end",
|
|
1973
|
+
name: "last",
|
|
1974
|
+
"protected": true,
|
|
1975
|
+
children: code`this.cursor = this.displayValue.length;
|
|
1871
1976
|
this.sync(); `
|
|
1977
|
+
}),
|
|
1978
|
+
createComponent(Spacing, {}),
|
|
1979
|
+
createComponent(ClassMethod, {
|
|
1980
|
+
doc: "A method to check if the cursor is at the start",
|
|
1981
|
+
name: "isCursorAtStart",
|
|
1982
|
+
"protected": true,
|
|
1983
|
+
children: code`return this.cursor === 0 || (this.isPlaceholder && this.cursor === 1); `
|
|
1984
|
+
}),
|
|
1985
|
+
createComponent(Spacing, {}),
|
|
1986
|
+
createComponent(ClassMethod, {
|
|
1987
|
+
doc: "A method to check if the cursor is at the end",
|
|
1988
|
+
name: "isCursorAtEnd",
|
|
1989
|
+
"protected": true,
|
|
1990
|
+
children: code`return this.cursor === this.displayValue.length || (this.isPlaceholder && this.cursor === this.displayValue.length + 1); `
|
|
1872
1991
|
})
|
|
1873
1992
|
];
|
|
1874
1993
|
}
|
|
@@ -1938,7 +2057,7 @@ function TogglePromptDeclarations() {
|
|
|
1938
2057
|
"export": true,
|
|
1939
2058
|
name: "TogglePromptConfig",
|
|
1940
2059
|
"extends": "PromptConfig<boolean>",
|
|
1941
|
-
doc: "Configuration options for
|
|
2060
|
+
doc: "Configuration options for creating a boolean toggle prompt",
|
|
1942
2061
|
get children() {
|
|
1943
2062
|
return [
|
|
1944
2063
|
createComponent(InterfaceMember, {
|
|
@@ -1962,7 +2081,7 @@ function TogglePromptDeclarations() {
|
|
|
1962
2081
|
createComponent(ClassDeclaration, {
|
|
1963
2082
|
"export": true,
|
|
1964
2083
|
name: "TogglePrompt",
|
|
1965
|
-
doc: "A prompt for
|
|
2084
|
+
doc: "A prompt for toggling a boolean input",
|
|
1966
2085
|
"extends": "Prompt<boolean>",
|
|
1967
2086
|
get children() {
|
|
1968
2087
|
return [
|
|
@@ -1987,6 +2106,14 @@ function TogglePromptDeclarations() {
|
|
|
1987
2106
|
type: "string",
|
|
1988
2107
|
children: code`"No"; `
|
|
1989
2108
|
}),
|
|
2109
|
+
createIntrinsic("hbr", {}),
|
|
2110
|
+
createComponent(ClassField, {
|
|
2111
|
+
name: "cursorHidden",
|
|
2112
|
+
"protected": true,
|
|
2113
|
+
override: true,
|
|
2114
|
+
type: "boolean",
|
|
2115
|
+
children: code`true; `
|
|
2116
|
+
}),
|
|
1990
2117
|
createComponent(Spacing, {}),
|
|
1991
2118
|
code`constructor(config: TogglePromptConfig) {
|
|
1992
2119
|
super(config);
|
|
@@ -2100,6 +2227,23 @@ function TogglePromptDeclarations() {
|
|
|
2100
2227
|
"protected": true,
|
|
2101
2228
|
children: code`this.changeValue(!this.value);
|
|
2102
2229
|
this.sync(); `
|
|
2230
|
+
}),
|
|
2231
|
+
createComponent(Spacing, {}),
|
|
2232
|
+
createComponent(ClassMethod, {
|
|
2233
|
+
doc: "A method to render the prompt",
|
|
2234
|
+
name: "render",
|
|
2235
|
+
override: true,
|
|
2236
|
+
"protected": true,
|
|
2237
|
+
returnType: "string",
|
|
2238
|
+
children: code`return this.isSubmitted
|
|
2239
|
+
? colors.text.prompt.input.submitted(this.value ? this.trueMessage : this.falseMessage)
|
|
2240
|
+
: this.isCancelled
|
|
2241
|
+
? colors.text.prompt.input.cancelled(this.value ? this.trueMessage : this.falseMessage)
|
|
2242
|
+
: \`\${
|
|
2243
|
+
this.value ? colors.text.prompt.input.inactive(this.falseMessage) : colors.underline(colors.bold(colors.text.prompt.input.active(this.falseMessage)))
|
|
2244
|
+
} \${colors.border.app.divider.tertiary("/")} \${
|
|
2245
|
+
this.value ? colors.underline(colors.bold(colors.text.prompt.input.active(this.trueMessage))) : colors.text.prompt.input.inactive(this.trueMessage)
|
|
2246
|
+
}\`; `
|
|
2103
2247
|
})
|
|
2104
2248
|
];
|
|
2105
2249
|
}
|
|
@@ -2159,6 +2303,262 @@ run(); ` }),
|
|
|
2159
2303
|
];
|
|
2160
2304
|
}
|
|
2161
2305
|
/**
|
|
2306
|
+
* A component that renders the declarations for the built-in confirm prompt, which allows users to select a boolean value (true/false) with support for custom messages for the true and false states. This prompt type can be used for scenarios where the user needs to toggle a setting on or off, such as enabling or disabling a feature. The ConfirmPrompt class extends the base Prompt class and implements specific logic for handling boolean input and rendering interactions.
|
|
2307
|
+
*/
|
|
2308
|
+
function ConfirmPromptDeclarations() {
|
|
2309
|
+
return [
|
|
2310
|
+
createComponent(InterfaceDeclaration, {
|
|
2311
|
+
"export": true,
|
|
2312
|
+
name: "ConfirmPromptConfig",
|
|
2313
|
+
"extends": "PromptConfig<boolean>",
|
|
2314
|
+
doc: "Configuration options for creating a boolean confirm prompt",
|
|
2315
|
+
get children() {
|
|
2316
|
+
return [
|
|
2317
|
+
createComponent(TSDoc, {
|
|
2318
|
+
heading: "The message for the \\`Yes\\` state of the prompt",
|
|
2319
|
+
get children() {
|
|
2320
|
+
return createComponent(TSDocDefaultValue, {
|
|
2321
|
+
get type() {
|
|
2322
|
+
return ReflectionKind.string;
|
|
2323
|
+
},
|
|
2324
|
+
defaultValue: "Yes"
|
|
2325
|
+
});
|
|
2326
|
+
}
|
|
2327
|
+
}),
|
|
2328
|
+
createComponent(InterfaceMember, {
|
|
2329
|
+
name: "yesMessage",
|
|
2330
|
+
optional: true,
|
|
2331
|
+
type: "string"
|
|
2332
|
+
}),
|
|
2333
|
+
createComponent(Spacing, {}),
|
|
2334
|
+
createComponent(TSDoc, {
|
|
2335
|
+
heading: "The \\`Yes\\` option when choosing between yes/no",
|
|
2336
|
+
get children() {
|
|
2337
|
+
return createComponent(TSDocDefaultValue, {
|
|
2338
|
+
get type() {
|
|
2339
|
+
return ReflectionKind.string;
|
|
2340
|
+
},
|
|
2341
|
+
defaultValue: "1"
|
|
2342
|
+
});
|
|
2343
|
+
}
|
|
2344
|
+
}),
|
|
2345
|
+
createComponent(InterfaceMember, {
|
|
2346
|
+
name: "yesOption",
|
|
2347
|
+
optional: true,
|
|
2348
|
+
type: "string"
|
|
2349
|
+
}),
|
|
2350
|
+
createComponent(Spacing, {}),
|
|
2351
|
+
createComponent(TSDoc, {
|
|
2352
|
+
heading: "The message for the \\`No\\` state of the prompt",
|
|
2353
|
+
get children() {
|
|
2354
|
+
return createComponent(TSDocDefaultValue, {
|
|
2355
|
+
get type() {
|
|
2356
|
+
return ReflectionKind.string;
|
|
2357
|
+
},
|
|
2358
|
+
defaultValue: "(Y/n)"
|
|
2359
|
+
});
|
|
2360
|
+
}
|
|
2361
|
+
}),
|
|
2362
|
+
createComponent(InterfaceMember, {
|
|
2363
|
+
name: "noMessage",
|
|
2364
|
+
optional: true,
|
|
2365
|
+
type: "string"
|
|
2366
|
+
}),
|
|
2367
|
+
createComponent(Spacing, {}),
|
|
2368
|
+
createComponent(TSDoc, {
|
|
2369
|
+
heading: "The \\`No\\` option when choosing between yes/no",
|
|
2370
|
+
get children() {
|
|
2371
|
+
return createComponent(TSDocDefaultValue, {
|
|
2372
|
+
get type() {
|
|
2373
|
+
return ReflectionKind.string;
|
|
2374
|
+
},
|
|
2375
|
+
defaultValue: "(y/N)"
|
|
2376
|
+
});
|
|
2377
|
+
}
|
|
2378
|
+
}),
|
|
2379
|
+
createComponent(InterfaceMember, {
|
|
2380
|
+
name: "noOption",
|
|
2381
|
+
optional: true,
|
|
2382
|
+
type: "string"
|
|
2383
|
+
})
|
|
2384
|
+
];
|
|
2385
|
+
}
|
|
2386
|
+
}),
|
|
2387
|
+
createComponent(Spacing, {}),
|
|
2388
|
+
createComponent(ClassDeclaration, {
|
|
2389
|
+
"export": true,
|
|
2390
|
+
name: "ConfirmPrompt",
|
|
2391
|
+
doc: "A prompt for confirming a boolean input",
|
|
2392
|
+
"extends": "Prompt<boolean>",
|
|
2393
|
+
get children() {
|
|
2394
|
+
return [
|
|
2395
|
+
createComponent(ClassField, {
|
|
2396
|
+
name: "initialValue",
|
|
2397
|
+
"protected": true,
|
|
2398
|
+
override: true,
|
|
2399
|
+
type: "boolean",
|
|
2400
|
+
children: code`false; `
|
|
2401
|
+
}),
|
|
2402
|
+
createIntrinsic("hbr", {}),
|
|
2403
|
+
createComponent(ClassField, {
|
|
2404
|
+
name: "yesMessage",
|
|
2405
|
+
"protected": true,
|
|
2406
|
+
type: "string",
|
|
2407
|
+
children: code`"Yes"; `
|
|
2408
|
+
}),
|
|
2409
|
+
createIntrinsic("hbr", {}),
|
|
2410
|
+
createComponent(ClassField, {
|
|
2411
|
+
name: "yesOption",
|
|
2412
|
+
"protected": true,
|
|
2413
|
+
type: "string",
|
|
2414
|
+
children: code`"(Y/n)"; `
|
|
2415
|
+
}),
|
|
2416
|
+
createIntrinsic("hbr", {}),
|
|
2417
|
+
createComponent(ClassField, {
|
|
2418
|
+
name: "noMessage",
|
|
2419
|
+
"protected": true,
|
|
2420
|
+
type: "string",
|
|
2421
|
+
children: code`"No"; `
|
|
2422
|
+
}),
|
|
2423
|
+
createIntrinsic("hbr", {}),
|
|
2424
|
+
createComponent(ClassField, {
|
|
2425
|
+
name: "noOption",
|
|
2426
|
+
"protected": true,
|
|
2427
|
+
type: "string",
|
|
2428
|
+
children: code`"(y/N)"; `
|
|
2429
|
+
}),
|
|
2430
|
+
createIntrinsic("hbr", {}),
|
|
2431
|
+
createComponent(ClassField, {
|
|
2432
|
+
name: "cursorHidden",
|
|
2433
|
+
"protected": true,
|
|
2434
|
+
override: true,
|
|
2435
|
+
type: "boolean",
|
|
2436
|
+
children: code`true; `
|
|
2437
|
+
}),
|
|
2438
|
+
createComponent(Spacing, {}),
|
|
2439
|
+
code`constructor(config: ConfirmPromptConfig) {
|
|
2440
|
+
super(config);
|
|
2441
|
+
|
|
2442
|
+
if (config.initialValue) {
|
|
2443
|
+
this.initialValue = config.initialValue;
|
|
2444
|
+
}
|
|
2445
|
+
|
|
2446
|
+
if (config.yesMessage) {
|
|
2447
|
+
this.yesMessage = config.yesMessage;
|
|
2448
|
+
}
|
|
2449
|
+
if (config.yesOption) {
|
|
2450
|
+
this.yesOption = config.yesOption;
|
|
2451
|
+
}
|
|
2452
|
+
if (config.noMessage) {
|
|
2453
|
+
this.noMessage = config.noMessage;
|
|
2454
|
+
}
|
|
2455
|
+
if (config.noOption) {
|
|
2456
|
+
this.noOption = config.noOption;
|
|
2457
|
+
}
|
|
2458
|
+
|
|
2459
|
+
this.sync();
|
|
2460
|
+
} `,
|
|
2461
|
+
createComponent(Spacing, {}),
|
|
2462
|
+
createComponent(ClassMethod, {
|
|
2463
|
+
doc: "A method to handle keypress events and determine the corresponding action",
|
|
2464
|
+
name: "keypress",
|
|
2465
|
+
override: true,
|
|
2466
|
+
"protected": true,
|
|
2467
|
+
parameters: [{
|
|
2468
|
+
name: "char",
|
|
2469
|
+
type: "string"
|
|
2470
|
+
}, {
|
|
2471
|
+
name: "key",
|
|
2472
|
+
type: "readline.Key"
|
|
2473
|
+
}],
|
|
2474
|
+
children: code`const action = this.getAction(key);
|
|
2475
|
+
if (action && typeof (this as any)[action] === "function") {
|
|
2476
|
+
return (this as any)[action]();
|
|
2477
|
+
}
|
|
2478
|
+
|
|
2479
|
+
if (char.toLowerCase() === "y" || char.toLowerCase() === "t" || char.toLowerCase() === "0") {
|
|
2480
|
+
this.value = true;
|
|
2481
|
+
return this.submit();
|
|
2482
|
+
} else if (char.toLowerCase() === "n" || char.toLowerCase() === "f" || char.toLowerCase() === "1") {
|
|
2483
|
+
this.value = false;
|
|
2484
|
+
return this.submit();
|
|
2485
|
+
} else {
|
|
2486
|
+
return this.bell();
|
|
2487
|
+
}
|
|
2488
|
+
|
|
2489
|
+
this.sync(); `
|
|
2490
|
+
}),
|
|
2491
|
+
createComponent(Spacing, {}),
|
|
2492
|
+
createComponent(ClassMethod, {
|
|
2493
|
+
doc: "A method to render the prompt",
|
|
2494
|
+
name: "render",
|
|
2495
|
+
override: true,
|
|
2496
|
+
"protected": true,
|
|
2497
|
+
returnType: "string",
|
|
2498
|
+
children: code`return this.isSubmitted
|
|
2499
|
+
? colors.text.prompt.input.submitted(this.value ? this.yesMessage : this.noMessage)
|
|
2500
|
+
: this.isCancelled
|
|
2501
|
+
? colors.text.prompt.input.cancelled(this.value ? this.yesMessage : this.noMessage)
|
|
2502
|
+
: colors.text.prompt.input.inactive(this.initialValue ? this.yesOption : this.noOption); `
|
|
2503
|
+
})
|
|
2504
|
+
];
|
|
2505
|
+
}
|
|
2506
|
+
}),
|
|
2507
|
+
createComponent(Spacing, {}),
|
|
2508
|
+
createComponent(TSDoc, { heading: "An object representing the configuration options for a confirm prompt, which extends the base PromptFactoryConfig with additional options specific to the confirm prompt." }),
|
|
2509
|
+
createComponent(TypeDeclaration, {
|
|
2510
|
+
name: "ConfirmConfig",
|
|
2511
|
+
"export": true,
|
|
2512
|
+
children: code`PromptFactoryConfig<boolean> & ConfirmPromptConfig; `
|
|
2513
|
+
}),
|
|
2514
|
+
createComponent(Spacing, {}),
|
|
2515
|
+
createComponent(TSDoc, {
|
|
2516
|
+
heading: "A function to create and run a confirm 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.",
|
|
2517
|
+
get children() {
|
|
2518
|
+
return [
|
|
2519
|
+
createComponent(TSDocExample, { children: `import { confirm, isCancel } from "shell-shock:prompts";
|
|
2520
|
+
|
|
2521
|
+
async function run() {
|
|
2522
|
+
const likesIceCream = await confirm({
|
|
2523
|
+
message: "Do you like ice cream?"
|
|
2524
|
+
});
|
|
2525
|
+
if (isCancel(likesIceCream)) {
|
|
2526
|
+
console.log("Prompt was cancelled");
|
|
2527
|
+
return;
|
|
2528
|
+
}
|
|
2529
|
+
|
|
2530
|
+
console.log("You" + (likesIceCream ? " like ice cream" : " don't like ice cream") + "!");
|
|
2531
|
+
}
|
|
2532
|
+
|
|
2533
|
+
run(); ` }),
|
|
2534
|
+
createComponent(Spacing, {}),
|
|
2535
|
+
createComponent(TSDocParam, {
|
|
2536
|
+
name: "config",
|
|
2537
|
+
children: `The configuration options to pass to the confirm prompt, which extends the base PromptFactoryConfig with additional options specific to the confirm prompt`
|
|
2538
|
+
}),
|
|
2539
|
+
createComponent(TSDocReturns, { children: `A promise that resolves with the submitted value or rejects with a {@link CANCEL_SYMBOL | cancel symbol} if the prompt is cancelled` })
|
|
2540
|
+
];
|
|
2541
|
+
}
|
|
2542
|
+
}),
|
|
2543
|
+
createComponent(FunctionDeclaration, {
|
|
2544
|
+
name: "confirm",
|
|
2545
|
+
"export": true,
|
|
2546
|
+
parameters: [{
|
|
2547
|
+
name: "config",
|
|
2548
|
+
type: "ConfirmConfig"
|
|
2549
|
+
}],
|
|
2550
|
+
returnType: "Promise<boolean | symbol>",
|
|
2551
|
+
children: code`return new Promise<boolean | symbol>((response, reject) => {
|
|
2552
|
+
const prompt = new ConfirmPrompt(config);
|
|
2553
|
+
|
|
2554
|
+
prompt.on("state", state => config.onState?.(state));
|
|
2555
|
+
prompt.on("submit", value => response(value));
|
|
2556
|
+
prompt.on("cancel", event => reject(CANCEL_SYMBOL));
|
|
2557
|
+
}); `
|
|
2558
|
+
})
|
|
2559
|
+
];
|
|
2560
|
+
}
|
|
2561
|
+
/**
|
|
2162
2562
|
* 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.
|
|
2163
2563
|
*/
|
|
2164
2564
|
function PasswordPromptDeclaration() {
|
|
@@ -2278,6 +2678,8 @@ function PromptsBuiltin(props) {
|
|
|
2278
2678
|
createComponent(Spacing, {}),
|
|
2279
2679
|
createComponent(PasswordPromptDeclaration, {}),
|
|
2280
2680
|
createComponent(Spacing, {}),
|
|
2681
|
+
createComponent(ConfirmPromptDeclarations, {}),
|
|
2682
|
+
createComponent(Spacing, {}),
|
|
2281
2683
|
createComponent(Show, {
|
|
2282
2684
|
get when() {
|
|
2283
2685
|
return Boolean(children);
|
|
@@ -2290,5 +2692,5 @@ function PromptsBuiltin(props) {
|
|
|
2290
2692
|
}
|
|
2291
2693
|
|
|
2292
2694
|
//#endregion
|
|
2293
|
-
export { BasePromptDeclarations, NumericPromptDeclarations, PasswordPromptDeclaration, PromptsBuiltin, SelectPromptDeclarations, TextPromptDeclarations, TogglePromptDeclarations };
|
|
2695
|
+
export { BasePromptDeclarations, ConfirmPromptDeclarations, NumericPromptDeclarations, PasswordPromptDeclaration, PromptsBuiltin, SelectPromptDeclarations, TextPromptDeclarations, TogglePromptDeclarations };
|
|
2294
2696
|
//# sourceMappingURL=prompts-builtin.mjs.map
|