@shell-shock/preset-cli 0.5.1 → 0.7.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.
Files changed (49) hide show
  1. package/dist/components/banner-function-declaration.cjs +6 -6
  2. package/dist/components/banner-function-declaration.d.cts +2 -2
  3. package/dist/components/banner-function-declaration.d.cts.map +1 -1
  4. package/dist/components/banner-function-declaration.d.mts +2 -2
  5. package/dist/components/banner-function-declaration.d.mts.map +1 -1
  6. package/dist/components/banner-function-declaration.mjs +6 -6
  7. package/dist/components/banner-function-declaration.mjs.map +1 -1
  8. package/dist/components/command-entry.cjs +178 -120
  9. package/dist/components/command-entry.d.cts +2 -2
  10. package/dist/components/command-entry.d.mts +2 -2
  11. package/dist/components/command-entry.mjs +177 -119
  12. package/dist/components/command-entry.mjs.map +1 -1
  13. package/dist/components/command-router.d.cts +3 -3
  14. package/dist/components/command-router.d.cts.map +1 -1
  15. package/dist/components/index.cjs +1 -0
  16. package/dist/components/index.d.cts +2 -2
  17. package/dist/components/index.d.mts +2 -2
  18. package/dist/components/index.mjs +2 -2
  19. package/dist/components/prompts-builtin.cjs +485 -57
  20. package/dist/components/prompts-builtin.d.cts +13 -9
  21. package/dist/components/prompts-builtin.d.cts.map +1 -1
  22. package/dist/components/prompts-builtin.d.mts +13 -9
  23. package/dist/components/prompts-builtin.d.mts.map +1 -1
  24. package/dist/components/prompts-builtin.mjs +495 -68
  25. package/dist/components/prompts-builtin.mjs.map +1 -1
  26. package/dist/components/virtual-command-entry.cjs +4 -3
  27. package/dist/components/virtual-command-entry.mjs +3 -2
  28. package/dist/components/virtual-command-entry.mjs.map +1 -1
  29. package/dist/index.cjs +3 -0
  30. package/dist/index.d.cts.map +1 -1
  31. package/dist/index.d.mts.map +1 -1
  32. package/dist/index.mjs +3 -0
  33. package/dist/index.mjs.map +1 -1
  34. package/dist/plugin-upgrade/dist/components/index.cjs +2 -0
  35. package/dist/plugin-upgrade/dist/components/index.mjs +4 -0
  36. package/dist/plugin-upgrade/dist/components/upgrade-builtin.cjs +661 -0
  37. package/dist/plugin-upgrade/dist/components/upgrade-builtin.mjs +655 -0
  38. package/dist/plugin-upgrade/dist/components/upgrade-builtin.mjs.map +1 -0
  39. package/dist/plugin-upgrade/dist/components/upgrade-command.cjs +96 -0
  40. package/dist/plugin-upgrade/dist/components/upgrade-command.mjs +96 -0
  41. package/dist/plugin-upgrade/dist/components/upgrade-command.mjs.map +1 -0
  42. package/dist/plugin-upgrade/dist/index.cjs +49 -0
  43. package/dist/plugin-upgrade/dist/index.mjs +49 -0
  44. package/dist/plugin-upgrade/dist/index.mjs.map +1 -0
  45. package/dist/types/plugin.d.cts +6 -10
  46. package/dist/types/plugin.d.cts.map +1 -1
  47. package/dist/types/plugin.d.mts +6 -10
  48. package/dist/types/plugin.d.mts.map +1 -1
  49. package/package.json +10 -10
@@ -1,13 +1,14 @@
1
1
  import { createComponent, createIntrinsic, memo, 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 { useTheme } from "@shell-shock/preset-script/contexts/theme";
5
4
  import { Spacing } from "@powerlines/plugin-alloy/core/components/spacing";
6
- import defu from "defu";
7
5
  import { BuiltinFile } from "@powerlines/plugin-alloy/typescript/components/builtin-file";
6
+ import defu from "defu";
7
+ import { ReflectionKind } from "@powerlines/deepkit/vendor/type";
8
+ import { TSDoc, TSDocDefaultValue, TSDocExample, TSDocParam, TSDocRemarks, TSDocReturns } from "@powerlines/plugin-alloy/typescript/components/tsdoc";
9
+ import { useTheme } from "@shell-shock/preset-script/contexts/theme";
8
10
  import { ClassDeclaration, ClassField, ClassMethod, ClassPropertyGet } from "@powerlines/plugin-alloy/typescript/components/class-declaration";
9
- 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 { InterfaceDeclaration as InterfaceDeclaration$1, InterfaceMember } from "@powerlines/plugin-alloy/typescript/components/interface-declaration";
11
12
  import { TypeDeclaration } from "@powerlines/plugin-alloy/typescript/components/type-declaration";
12
13
 
13
14
  //#region src/components/prompts-builtin.tsx
@@ -83,7 +84,7 @@ function BasePromptDeclarations() {
83
84
  children: code`return " ".repeat(input.length); `
84
85
  }),
85
86
  createComponent(Spacing, {}),
86
- createComponent(InterfaceDeclaration, {
87
+ createComponent(InterfaceDeclaration$1, {
87
88
  "export": true,
88
89
  name: "PromptState",
89
90
  doc: "The current state of a prompt",
@@ -134,9 +135,9 @@ function BasePromptDeclarations() {
134
135
  }
135
136
  }),
136
137
  createComponent(Spacing, {}),
137
- createComponent(InterfaceDeclaration, {
138
+ createComponent(InterfaceDeclaration$1, {
138
139
  name: "PromptConfig",
139
- doc: "Configuration options for configuring a prompt",
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, {}),
@@ -202,7 +203,14 @@ function BasePromptDeclarations() {
202
203
  name: "mask",
203
204
  optional: true,
204
205
  type: "(input: string) => string",
205
- doc: "A function that masks the input value and returns the masked result or throws an error if the input is invalid"
206
+ 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."
207
+ }),
208
+ createComponent(Spacing, {}),
209
+ createComponent(InterfaceMember, {
210
+ name: "maskSubmitted",
211
+ optional: true,
212
+ type: "(input: string) => string",
213
+ 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."
206
214
  }),
207
215
  createComponent(Spacing, {}),
208
216
  createComponent(InterfaceMember, {
@@ -299,7 +307,7 @@ function BasePromptDeclarations() {
299
307
  name: "defaultErrorMessage",
300
308
  "protected": true,
301
309
  type: "string",
302
- children: code`"Invalid value provided"; `
310
+ children: code`"An invalid value was provided"; `
303
311
  }),
304
312
  createIntrinsic("hbr", {}),
305
313
  createComponent(ClassField, {
@@ -318,6 +326,7 @@ function BasePromptDeclarations() {
318
326
  createIntrinsic("hbr", {}),
319
327
  createComponent(ClassField, {
320
328
  name: "isInitial",
329
+ "protected": true,
321
330
  type: "boolean",
322
331
  children: code`true; `
323
332
  }),
@@ -371,6 +380,12 @@ function BasePromptDeclarations() {
371
380
  children: code`noMask; `
372
381
  }),
373
382
  createIntrinsic("hbr", {}),
383
+ createComponent(ClassField, {
384
+ name: "maskSubmitted",
385
+ "protected": true,
386
+ type: "(input: string) => string"
387
+ }),
388
+ createIntrinsic("hbr", {}),
374
389
  createComponent(ClassField, {
375
390
  name: "cursor",
376
391
  "protected": true,
@@ -384,6 +399,13 @@ function BasePromptDeclarations() {
384
399
  type: "number",
385
400
  children: code`0; `
386
401
  }),
402
+ createIntrinsic("hbr", {}),
403
+ createComponent(ClassField, {
404
+ name: "cursorHidden",
405
+ "protected": true,
406
+ type: "boolean",
407
+ children: code`false; `
408
+ }),
387
409
  createComponent(Spacing, {}),
388
410
  code`constructor(protected config: PromptConfig<TValue>) {
389
411
  super();
@@ -410,6 +432,16 @@ function BasePromptDeclarations() {
410
432
  this.formatter = config.format.bind(this);
411
433
  }
412
434
 
435
+ if (config.maskSubmitted) {
436
+ this.maskSubmitted = config.maskSubmitted;
437
+ }
438
+ if (config.mask) {
439
+ this.mask = config.mask;
440
+ }
441
+ if (!this.maskSubmitted) {
442
+ this.maskSubmitted = this.mask;
443
+ }
444
+
413
445
  if (config.timeout !== undefined && !Number.isNaN(config.timeout)) {
414
446
  setTimeout(() => {
415
447
  if (!this.isCompleted) {
@@ -499,7 +531,7 @@ function BasePromptDeclarations() {
499
531
  updatedValue = value;
500
532
  }
501
533
 
502
- this.displayValue = this.formatter(updatedValue);
534
+ this.displayValue = this.mask(this.formatter(updatedValue));
503
535
  this.#value = updatedValue;
504
536
  setTimeout(() => {
505
537
  Promise.resolve(this.validate(updatedValue)).then(() => this.sync());
@@ -709,6 +741,8 @@ function BasePromptDeclarations() {
709
741
  }
710
742
 
711
743
  this.output.write(clear(this.consoleOutput, this.output.columns));
744
+ } else if (this.cursorHidden) {
745
+ this.output.write(cursor.hide);
712
746
  }
713
747
 
714
748
  this.consoleOutput = \` \${
@@ -751,7 +785,7 @@ function BasePromptDeclarations() {
751
785
  : this.isError
752
786
  ? colors.text.prompt.input.error(this.displayValue)
753
787
  : this.isSubmitted
754
- ? colors.text.prompt.input.submitted(this.displayValue)
788
+ ? colors.text.prompt.input.submitted(this.maskSubmitted(this.displayValue))
755
789
  : this.isCancelled
756
790
  ? colors.text.prompt.input.cancelled(this.displayValue)
757
791
  : colors.bold(colors.text.prompt.input.active(this.displayValue)); `
@@ -760,7 +794,7 @@ function BasePromptDeclarations() {
760
794
  }
761
795
  }),
762
796
  createComponent(Spacing, {}),
763
- createComponent(InterfaceDeclaration, {
797
+ createComponent(InterfaceDeclaration$1, {
764
798
  name: "PromptFactoryConfig",
765
799
  "extends": "PromptConfig<TValue>",
766
800
  doc: "Configuration options for creating a prompt with a prompt factory function",
@@ -794,10 +828,10 @@ function BasePromptDeclarations() {
794
828
  }
795
829
  }),
796
830
  createComponent(Spacing, {}),
831
+ 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
832
  createComponent(VarDeclaration, {
798
833
  "export": true,
799
834
  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
835
  children: code`Symbol("shell-shock:prompts:cancel"); `
802
836
  }),
803
837
  createComponent(Spacing, {}),
@@ -827,10 +861,10 @@ function BasePromptDeclarations() {
827
861
  */
828
862
  function TextPromptDeclarations() {
829
863
  return [
830
- createComponent(InterfaceDeclaration, {
864
+ createComponent(InterfaceDeclaration$1, {
831
865
  name: "StringPromptConfig",
832
866
  "extends": "PromptConfig<string>",
833
- doc: "Configuration options for configuring a text-based prompt",
867
+ doc: "Configuration options for creating a text-based prompt",
834
868
  get children() {
835
869
  return [
836
870
  createComponent(InterfaceMember, {
@@ -880,6 +914,7 @@ function TextPromptDeclarations() {
880
914
 
881
915
  this.cursor = 0;
882
916
  this.sync();
917
+ this.first();
883
918
  } `,
884
919
  createComponent(Spacing, {}),
885
920
  createComponent(ClassMethod, {
@@ -1149,7 +1184,7 @@ run(); ` }),
1149
1184
  */
1150
1185
  function SelectPromptDeclarations() {
1151
1186
  return [
1152
- createComponent(InterfaceDeclaration, {
1187
+ createComponent(InterfaceDeclaration$1, {
1153
1188
  name: "PromptOptionConfig",
1154
1189
  doc: "Configuration for an option the user can select from the select prompt",
1155
1190
  typeParameters: [{
@@ -1202,7 +1237,7 @@ function SelectPromptDeclarations() {
1202
1237
  }
1203
1238
  }),
1204
1239
  createComponent(Spacing, {}),
1205
- createComponent(InterfaceDeclaration, {
1240
+ createComponent(InterfaceDeclaration$1, {
1206
1241
  "export": true,
1207
1242
  name: "PromptOption",
1208
1243
  "extends": "PromptOptionConfig<TValue>",
@@ -1239,7 +1274,7 @@ function SelectPromptDeclarations() {
1239
1274
  }
1240
1275
  }),
1241
1276
  createComponent(Spacing, {}),
1242
- createComponent(InterfaceDeclaration, {
1277
+ createComponent(InterfaceDeclaration$1, {
1243
1278
  name: "SelectPromptConfig",
1244
1279
  "extends": "PromptConfig<TValue>",
1245
1280
  doc: "An options object for configuring a select prompt",
@@ -1302,6 +1337,14 @@ function SelectPromptDeclarations() {
1302
1337
  type: "PromptOption<TValue>[]",
1303
1338
  children: code`[]; `
1304
1339
  }),
1340
+ createIntrinsic("hbr", {}),
1341
+ createComponent(ClassField, {
1342
+ name: "cursorHidden",
1343
+ "protected": true,
1344
+ override: true,
1345
+ type: "boolean",
1346
+ children: code`true; `
1347
+ }),
1305
1348
  createComponent(Spacing, {}),
1306
1349
  code`constructor(config: SelectPromptConfig<TValue>) {
1307
1350
  super(config);
@@ -1476,11 +1519,7 @@ function SelectPromptDeclarations() {
1476
1519
  name: "render",
1477
1520
  override: true,
1478
1521
  "protected": true,
1479
- children: code`if (this.isInitial) {
1480
- this.output.write(cursor.hide);
1481
- }
1482
-
1483
- const spacing = Math.max(...this.options.map(option => option.label?.length || 0)) + 2;
1522
+ children: code`const spacing = Math.max(...this.options.map(option => option.label?.length || 0)) + 2;
1484
1523
 
1485
1524
  const startIndex = Math.max(Math.min(this.options.length - this.optionsPerPage, this.cursor - Math.floor(this.optionsPerPage / 2)), 0);
1486
1525
  const endIndex = Math.min(startIndex + this.optionsPerPage, this.options.length);
@@ -1609,10 +1648,10 @@ run(); ` }),
1609
1648
  */
1610
1649
  function NumericPromptDeclarations() {
1611
1650
  return [
1612
- createComponent(InterfaceDeclaration, {
1651
+ createComponent(InterfaceDeclaration$1, {
1613
1652
  name: "NumberPromptConfig",
1614
1653
  "extends": "PromptConfig<number>",
1615
- doc: "Configuration options for configuring a numeric prompt",
1654
+ doc: "Configuration options for creating a numeric prompt",
1616
1655
  get children() {
1617
1656
  return [
1618
1657
  createComponent(InterfaceMember, {
@@ -1659,6 +1698,13 @@ function NumericPromptDeclarations() {
1659
1698
  "extends": "Prompt<number>",
1660
1699
  get children() {
1661
1700
  return [
1701
+ createComponent(ClassField, {
1702
+ name: "isInvalid",
1703
+ isPrivateMember: true,
1704
+ type: "boolean",
1705
+ children: code`false; `
1706
+ }),
1707
+ createComponent(Spacing, {}),
1662
1708
  createComponent(ClassField, {
1663
1709
  name: "initialValue",
1664
1710
  "protected": true,
@@ -1667,6 +1713,14 @@ function NumericPromptDeclarations() {
1667
1713
  children: code`0; `
1668
1714
  }),
1669
1715
  createIntrinsic("hbr", {}),
1716
+ createComponent(ClassField, {
1717
+ name: "defaultErrorMessage",
1718
+ "protected": true,
1719
+ override: true,
1720
+ type: "string",
1721
+ children: code`"A valid numeric value must be provided"; `
1722
+ }),
1723
+ createIntrinsic("hbr", {}),
1670
1724
  createComponent(ClassField, {
1671
1725
  name: "isFloat",
1672
1726
  "protected": true,
@@ -1752,6 +1806,7 @@ function NumericPromptDeclarations() {
1752
1806
  }
1753
1807
 
1754
1808
  this.sync();
1809
+ this.last();
1755
1810
  } `,
1756
1811
  createComponent(Spacing, {}),
1757
1812
  createComponent(ClassMethod, {
@@ -1762,14 +1817,6 @@ function NumericPromptDeclarations() {
1762
1817
  children: code`super.reset();
1763
1818
  this.currentInput = "";
1764
1819
  `
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
1820
  }),
1774
1821
  createComponent(Spacing, {}),
1775
1822
  createComponent(ClassMethod, {
@@ -1793,18 +1840,12 @@ function NumericPromptDeclarations() {
1793
1840
  return this.bell();
1794
1841
  }
1795
1842
 
1796
- if (Date.now() - this.inputTimestamp > 1000) {
1797
- this.currentInput = "";
1798
- }
1799
-
1800
- this.currentInput += char;
1801
- this.inputTimestamp = Date.now();
1802
-
1803
- if (char === ".") {
1843
+ this.displayValue += char;
1844
+ if ((char === "-" || char === ".") && this.displayValue.length === 1) {
1804
1845
  return this.sync();
1805
1846
  }
1806
1847
 
1807
- let value = Math.min(this.parser(this.currentInput), this.max);
1848
+ let value = Math.min(this.parser(this.displayValue), this.max);
1808
1849
  if (value > this.max) {
1809
1850
  value = this.max;
1810
1851
  }
@@ -1813,6 +1854,14 @@ function NumericPromptDeclarations() {
1813
1854
  }
1814
1855
 
1815
1856
  this.changeValue(value);
1857
+ this.sync(); `
1858
+ }),
1859
+ createComponent(Spacing, {}),
1860
+ createComponent(ClassMethod, {
1861
+ doc: "A method to move the cursor to the end of the input",
1862
+ name: "next",
1863
+ "protected": true,
1864
+ children: code`this.changeValue(this.initialValue);
1816
1865
  this.sync(); `
1817
1866
  }),
1818
1867
  createComponent(Spacing, {}),
@@ -1820,14 +1869,10 @@ function NumericPromptDeclarations() {
1820
1869
  doc: "A method to move the cursor to the up",
1821
1870
  name: "up",
1822
1871
  "protected": true,
1823
- children: code`this.currentInput = "";
1824
-
1825
- let value = this.value;
1872
+ children: code`let value = this.value;
1826
1873
  if (this.displayValue === "") {
1827
- value = this.min === Number.NEGATIVE_INFINITY ? 0 - this.increment : this.min - this.increment;
1828
- }
1829
-
1830
- if (value >= this.max) {
1874
+ value = this.min < 0 ? 0 : this.min;
1875
+ } else if (value >= this.max) {
1831
1876
  return this.bell();
1832
1877
  }
1833
1878
 
@@ -1839,36 +1884,134 @@ function NumericPromptDeclarations() {
1839
1884
  doc: "A method to move the cursor to the down",
1840
1885
  name: "down",
1841
1886
  "protected": true,
1842
- children: code`this.currentInput = "";
1887
+ children: code`let value = this.value;
1888
+ if (this.displayValue === "") {
1889
+ value = this.min < 0 ? 0 : this.min;
1890
+ } else if (value <= this.min) {
1891
+ return this.bell();
1892
+ }
1843
1893
 
1844
- let value = this.value;
1845
- if(this.displayValue === "") {
1846
- value = this.min === Number.NEGATIVE_INFINITY ? 0 + this.increment : this.min + this.increment;
1894
+ this.changeValue(value === this.min ? this.min : value - this.increment);
1895
+ this.sync(); `
1896
+ }),
1897
+ createComponent(Spacing, {}),
1898
+ createComponent(ClassMethod, {
1899
+ doc: "A method to move the cursor to the left",
1900
+ name: "left",
1901
+ "protected": true,
1902
+ children: code`if (this.cursor <= 0 || this.isPlaceholder) {
1903
+ return this.bell();
1847
1904
  }
1848
1905
 
1849
- if (value <= this.min) {
1906
+ this.moveCursor(-1);
1907
+ this.sync(); `
1908
+ }),
1909
+ createComponent(Spacing, {}),
1910
+ createComponent(ClassMethod, {
1911
+ doc: "A method to move the cursor to the right",
1912
+ name: "right",
1913
+ "protected": true,
1914
+ children: code`if (this.cursor >= this.displayValue.length || this.isPlaceholder) {
1850
1915
  return this.bell();
1851
1916
  }
1852
1917
 
1853
- this.changeValue(value - this.increment);
1918
+ this.moveCursor(1);
1854
1919
  this.sync(); `
1920
+ }),
1921
+ createComponent(Spacing, {}),
1922
+ createComponent(ClassMethod, {
1923
+ doc: "A method to move the cursor to the left or right by a \\`count\\` of positions",
1924
+ name: "moveCursor",
1925
+ parameters: [{
1926
+ name: "count",
1927
+ type: "number"
1928
+ }],
1929
+ "protected": true,
1930
+ children: code`if (this.isPlaceholder) {
1931
+ return;
1932
+ }
1933
+
1934
+ this.cursor = this.cursor + count;
1935
+ this.cursorOffset += count; `
1855
1936
  }),
1856
1937
  createComponent(Spacing, {}),
1857
1938
  createComponent(ClassMethod, {
1858
1939
  doc: "A method to delete the character backward of the cursor",
1859
1940
  name: "delete",
1860
1941
  "protected": true,
1861
- children: code`if (this.displayValue === "") {
1942
+ children: code`if (this.isCursorAtStart()) {
1862
1943
  return this.bell();
1863
1944
  }
1864
1945
 
1865
- let value = this.parser(this.displayValue.slice(0, -1));
1866
- if (value < this.min) {
1867
- value = this.min === Number.NEGATIVE_INFINITY ? 0 : this.min;
1946
+ if (this.displayValue === "") {
1947
+ return this.bell();
1948
+ }
1949
+
1950
+ this.changeValue(\`\${this.displayValue.slice(0, this.cursor - 1)}\${this.displayValue.slice(this.cursor)}\`);
1951
+ this.#isInvalid = false;
1952
+
1953
+ if (this.isCursorAtStart()) {
1954
+ this.cursorOffset = 0
1955
+ } else {
1956
+ this.cursorOffset++;
1957
+ this.moveCursor(-1);
1868
1958
  }
1869
1959
 
1870
- this.changeValue(value);
1871
1960
  this.sync(); `
1961
+ }),
1962
+ createComponent(Spacing, {}),
1963
+ createComponent(ClassMethod, {
1964
+ doc: "A method to delete the character forward of the cursor",
1965
+ name: "deleteForward",
1966
+ "protected": true,
1967
+ children: code`if (this.cursor >= this.displayValue.length || this.isPlaceholder) {
1968
+ return this.bell();
1969
+ }
1970
+
1971
+ this.changeValue(\`\${
1972
+ this.displayValue.slice(0, this.cursor)
1973
+ }\${
1974
+ this.displayValue.slice(this.cursor + 1)
1975
+ }\`);
1976
+ this.#isInvalid = false;
1977
+
1978
+ if (this.isCursorAtEnd()) {
1979
+ this.cursorOffset = 0;
1980
+ } else {
1981
+ this.cursorOffset++;
1982
+ }
1983
+
1984
+ this.sync(); `
1985
+ }),
1986
+ createComponent(Spacing, {}),
1987
+ createComponent(ClassMethod, {
1988
+ doc: "A method to move the cursor to the start",
1989
+ name: "first",
1990
+ "protected": true,
1991
+ children: code`this.cursor = 0;
1992
+ this.sync(); `
1993
+ }),
1994
+ createComponent(Spacing, {}),
1995
+ createComponent(ClassMethod, {
1996
+ doc: "A method to move the cursor to the end",
1997
+ name: "last",
1998
+ "protected": true,
1999
+ children: code`this.cursor = this.displayValue.length;
2000
+ this.sync(); `
2001
+ }),
2002
+ createComponent(Spacing, {}),
2003
+ createComponent(ClassMethod, {
2004
+ doc: "A method to check if the cursor is at the start",
2005
+ name: "isCursorAtStart",
2006
+ "protected": true,
2007
+ children: code`return this.cursor === 0 || (this.isPlaceholder && this.cursor === 1); `
2008
+ }),
2009
+ createComponent(Spacing, {}),
2010
+ createComponent(ClassMethod, {
2011
+ doc: "A method to check if the cursor is at the end",
2012
+ name: "isCursorAtEnd",
2013
+ "protected": true,
2014
+ children: code`return this.cursor === this.displayValue.length || (this.isPlaceholder && this.cursor === this.displayValue.length + 1); `
1872
2015
  })
1873
2016
  ];
1874
2017
  }
@@ -1934,11 +2077,11 @@ run(); ` }),
1934
2077
  */
1935
2078
  function TogglePromptDeclarations() {
1936
2079
  return [
1937
- createComponent(InterfaceDeclaration, {
2080
+ createComponent(InterfaceDeclaration$1, {
1938
2081
  "export": true,
1939
2082
  name: "TogglePromptConfig",
1940
2083
  "extends": "PromptConfig<boolean>",
1941
- doc: "Configuration options for configuring a boolean toggle prompt",
2084
+ doc: "Configuration options for creating a boolean toggle prompt",
1942
2085
  get children() {
1943
2086
  return [
1944
2087
  createComponent(InterfaceMember, {
@@ -1962,7 +2105,7 @@ function TogglePromptDeclarations() {
1962
2105
  createComponent(ClassDeclaration, {
1963
2106
  "export": true,
1964
2107
  name: "TogglePrompt",
1965
- doc: "A prompt for selecting a boolean input",
2108
+ doc: "A prompt for toggling a boolean input",
1966
2109
  "extends": "Prompt<boolean>",
1967
2110
  get children() {
1968
2111
  return [
@@ -1987,6 +2130,14 @@ function TogglePromptDeclarations() {
1987
2130
  type: "string",
1988
2131
  children: code`"No"; `
1989
2132
  }),
2133
+ createIntrinsic("hbr", {}),
2134
+ createComponent(ClassField, {
2135
+ name: "cursorHidden",
2136
+ "protected": true,
2137
+ override: true,
2138
+ type: "boolean",
2139
+ children: code`true; `
2140
+ }),
1990
2141
  createComponent(Spacing, {}),
1991
2142
  code`constructor(config: TogglePromptConfig) {
1992
2143
  super(config);
@@ -2100,6 +2251,23 @@ function TogglePromptDeclarations() {
2100
2251
  "protected": true,
2101
2252
  children: code`this.changeValue(!this.value);
2102
2253
  this.sync(); `
2254
+ }),
2255
+ createComponent(Spacing, {}),
2256
+ createComponent(ClassMethod, {
2257
+ doc: "A method to render the prompt",
2258
+ name: "render",
2259
+ override: true,
2260
+ "protected": true,
2261
+ returnType: "string",
2262
+ children: code`return this.isSubmitted
2263
+ ? colors.text.prompt.input.submitted(this.value ? this.trueMessage : this.falseMessage)
2264
+ : this.isCancelled
2265
+ ? colors.text.prompt.input.cancelled(this.value ? this.trueMessage : this.falseMessage)
2266
+ : \`\${
2267
+ this.value ? colors.text.prompt.input.inactive(this.falseMessage) : colors.underline(colors.bold(colors.text.prompt.input.active(this.falseMessage)))
2268
+ } \${colors.border.app.divider.tertiary("/")} \${
2269
+ this.value ? colors.underline(colors.bold(colors.text.prompt.input.active(this.trueMessage))) : colors.text.prompt.input.inactive(this.trueMessage)
2270
+ }\`; `
2103
2271
  })
2104
2272
  ];
2105
2273
  }
@@ -2159,6 +2327,262 @@ run(); ` }),
2159
2327
  ];
2160
2328
  }
2161
2329
  /**
2330
+ * 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.
2331
+ */
2332
+ function ConfirmPromptDeclarations() {
2333
+ return [
2334
+ createComponent(InterfaceDeclaration$1, {
2335
+ "export": true,
2336
+ name: "ConfirmPromptConfig",
2337
+ "extends": "PromptConfig<boolean>",
2338
+ doc: "Configuration options for creating a boolean confirm prompt",
2339
+ get children() {
2340
+ return [
2341
+ createComponent(TSDoc, {
2342
+ heading: "The message for the \\`Yes\\` state of the prompt",
2343
+ get children() {
2344
+ return createComponent(TSDocDefaultValue, {
2345
+ get type() {
2346
+ return ReflectionKind.string;
2347
+ },
2348
+ defaultValue: "Yes"
2349
+ });
2350
+ }
2351
+ }),
2352
+ createComponent(InterfaceMember, {
2353
+ name: "yesMessage",
2354
+ optional: true,
2355
+ type: "string"
2356
+ }),
2357
+ createComponent(Spacing, {}),
2358
+ createComponent(TSDoc, {
2359
+ heading: "The \\`Yes\\` option when choosing between yes/no",
2360
+ get children() {
2361
+ return createComponent(TSDocDefaultValue, {
2362
+ get type() {
2363
+ return ReflectionKind.string;
2364
+ },
2365
+ defaultValue: "1"
2366
+ });
2367
+ }
2368
+ }),
2369
+ createComponent(InterfaceMember, {
2370
+ name: "yesOption",
2371
+ optional: true,
2372
+ type: "string"
2373
+ }),
2374
+ createComponent(Spacing, {}),
2375
+ createComponent(TSDoc, {
2376
+ heading: "The message for the \\`No\\` state of the prompt",
2377
+ get children() {
2378
+ return createComponent(TSDocDefaultValue, {
2379
+ get type() {
2380
+ return ReflectionKind.string;
2381
+ },
2382
+ defaultValue: "(Y/n)"
2383
+ });
2384
+ }
2385
+ }),
2386
+ createComponent(InterfaceMember, {
2387
+ name: "noMessage",
2388
+ optional: true,
2389
+ type: "string"
2390
+ }),
2391
+ createComponent(Spacing, {}),
2392
+ createComponent(TSDoc, {
2393
+ heading: "The \\`No\\` option when choosing between yes/no",
2394
+ get children() {
2395
+ return createComponent(TSDocDefaultValue, {
2396
+ get type() {
2397
+ return ReflectionKind.string;
2398
+ },
2399
+ defaultValue: "(y/N)"
2400
+ });
2401
+ }
2402
+ }),
2403
+ createComponent(InterfaceMember, {
2404
+ name: "noOption",
2405
+ optional: true,
2406
+ type: "string"
2407
+ })
2408
+ ];
2409
+ }
2410
+ }),
2411
+ createComponent(Spacing, {}),
2412
+ createComponent(ClassDeclaration, {
2413
+ "export": true,
2414
+ name: "ConfirmPrompt",
2415
+ doc: "A prompt for confirming a boolean input",
2416
+ "extends": "Prompt<boolean>",
2417
+ get children() {
2418
+ return [
2419
+ createComponent(ClassField, {
2420
+ name: "initialValue",
2421
+ "protected": true,
2422
+ override: true,
2423
+ type: "boolean",
2424
+ children: code`false; `
2425
+ }),
2426
+ createIntrinsic("hbr", {}),
2427
+ createComponent(ClassField, {
2428
+ name: "yesMessage",
2429
+ "protected": true,
2430
+ type: "string",
2431
+ children: code`"Yes"; `
2432
+ }),
2433
+ createIntrinsic("hbr", {}),
2434
+ createComponent(ClassField, {
2435
+ name: "yesOption",
2436
+ "protected": true,
2437
+ type: "string",
2438
+ children: code`"(Y/n)"; `
2439
+ }),
2440
+ createIntrinsic("hbr", {}),
2441
+ createComponent(ClassField, {
2442
+ name: "noMessage",
2443
+ "protected": true,
2444
+ type: "string",
2445
+ children: code`"No"; `
2446
+ }),
2447
+ createIntrinsic("hbr", {}),
2448
+ createComponent(ClassField, {
2449
+ name: "noOption",
2450
+ "protected": true,
2451
+ type: "string",
2452
+ children: code`"(y/N)"; `
2453
+ }),
2454
+ createIntrinsic("hbr", {}),
2455
+ createComponent(ClassField, {
2456
+ name: "cursorHidden",
2457
+ "protected": true,
2458
+ override: true,
2459
+ type: "boolean",
2460
+ children: code`true; `
2461
+ }),
2462
+ createComponent(Spacing, {}),
2463
+ code`constructor(config: ConfirmPromptConfig) {
2464
+ super(config);
2465
+
2466
+ if (config.initialValue) {
2467
+ this.initialValue = config.initialValue;
2468
+ }
2469
+
2470
+ if (config.yesMessage) {
2471
+ this.yesMessage = config.yesMessage;
2472
+ }
2473
+ if (config.yesOption) {
2474
+ this.yesOption = config.yesOption;
2475
+ }
2476
+ if (config.noMessage) {
2477
+ this.noMessage = config.noMessage;
2478
+ }
2479
+ if (config.noOption) {
2480
+ this.noOption = config.noOption;
2481
+ }
2482
+
2483
+ this.sync();
2484
+ } `,
2485
+ createComponent(Spacing, {}),
2486
+ createComponent(ClassMethod, {
2487
+ doc: "A method to handle keypress events and determine the corresponding action",
2488
+ name: "keypress",
2489
+ override: true,
2490
+ "protected": true,
2491
+ parameters: [{
2492
+ name: "char",
2493
+ type: "string"
2494
+ }, {
2495
+ name: "key",
2496
+ type: "readline.Key"
2497
+ }],
2498
+ children: code`const action = this.getAction(key);
2499
+ if (action && typeof (this as any)[action] === "function") {
2500
+ return (this as any)[action]();
2501
+ }
2502
+
2503
+ if (char.toLowerCase() === "y" || char.toLowerCase() === "t" || char.toLowerCase() === "0") {
2504
+ this.value = true;
2505
+ return this.submit();
2506
+ } else if (char.toLowerCase() === "n" || char.toLowerCase() === "f" || char.toLowerCase() === "1") {
2507
+ this.value = false;
2508
+ return this.submit();
2509
+ } else {
2510
+ return this.bell();
2511
+ }
2512
+
2513
+ this.sync(); `
2514
+ }),
2515
+ createComponent(Spacing, {}),
2516
+ createComponent(ClassMethod, {
2517
+ doc: "A method to render the prompt",
2518
+ name: "render",
2519
+ override: true,
2520
+ "protected": true,
2521
+ returnType: "string",
2522
+ children: code`return this.isSubmitted
2523
+ ? colors.text.prompt.input.submitted(this.value ? this.yesMessage : this.noMessage)
2524
+ : this.isCancelled
2525
+ ? colors.text.prompt.input.cancelled(this.value ? this.yesMessage : this.noMessage)
2526
+ : colors.text.prompt.input.inactive(this.initialValue ? this.yesOption : this.noOption); `
2527
+ })
2528
+ ];
2529
+ }
2530
+ }),
2531
+ createComponent(Spacing, {}),
2532
+ 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." }),
2533
+ createComponent(TypeDeclaration, {
2534
+ name: "ConfirmConfig",
2535
+ "export": true,
2536
+ children: code`PromptFactoryConfig<boolean> & ConfirmPromptConfig; `
2537
+ }),
2538
+ createComponent(Spacing, {}),
2539
+ createComponent(TSDoc, {
2540
+ 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.",
2541
+ get children() {
2542
+ return [
2543
+ createComponent(TSDocExample, { children: `import { confirm, isCancel } from "shell-shock:prompts";
2544
+
2545
+ async function run() {
2546
+ const likesIceCream = await confirm({
2547
+ message: "Do you like ice cream?"
2548
+ });
2549
+ if (isCancel(likesIceCream)) {
2550
+ console.log("Prompt was cancelled");
2551
+ return;
2552
+ }
2553
+
2554
+ console.log("You" + (likesIceCream ? " like ice cream" : " don't like ice cream") + "!");
2555
+ }
2556
+
2557
+ run(); ` }),
2558
+ createComponent(Spacing, {}),
2559
+ createComponent(TSDocParam, {
2560
+ name: "config",
2561
+ children: `The configuration options to pass to the confirm prompt, which extends the base PromptFactoryConfig with additional options specific to the confirm prompt`
2562
+ }),
2563
+ 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` })
2564
+ ];
2565
+ }
2566
+ }),
2567
+ createComponent(FunctionDeclaration, {
2568
+ name: "confirm",
2569
+ "export": true,
2570
+ parameters: [{
2571
+ name: "config",
2572
+ type: "ConfirmConfig"
2573
+ }],
2574
+ returnType: "Promise<boolean | symbol>",
2575
+ children: code`return new Promise<boolean | symbol>((response, reject) => {
2576
+ const prompt = new ConfirmPrompt(config);
2577
+
2578
+ prompt.on("state", state => config.onState?.(state));
2579
+ prompt.on("submit", value => response(value));
2580
+ prompt.on("cancel", event => reject(CANCEL_SYMBOL));
2581
+ }); `
2582
+ })
2583
+ ];
2584
+ }
2585
+ /**
2162
2586
  * 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
2587
  */
2164
2588
  function PasswordPromptDeclaration() {
@@ -2179,7 +2603,7 @@ function PasswordPromptDeclaration() {
2179
2603
  createComponent(TypeDeclaration, {
2180
2604
  name: "PasswordConfig",
2181
2605
  "export": true,
2182
- children: code`Omit<TextConfig, "mask">; `
2606
+ children: code`Omit<TextConfig, "mask" | "maskSubmitted">; `
2183
2607
  }),
2184
2608
  createComponent(Spacing, {}),
2185
2609
  createComponent(TSDoc, {
@@ -2222,7 +2646,8 @@ run(); ` }),
2222
2646
  returnType: "Promise<string | symbol>",
2223
2647
  children: code`return text({
2224
2648
  ...config,
2225
- mask: passwordMask
2649
+ mask: passwordMask,
2650
+ maskSubmitted: () => "*******"
2226
2651
  });`
2227
2652
  })
2228
2653
  ];
@@ -2234,7 +2659,7 @@ function PromptsBuiltin(props) {
2234
2659
  const [{ children }, rest] = splitProps(props, ["children"]);
2235
2660
  return createComponent(BuiltinFile, mergeProps({
2236
2661
  id: "prompts",
2237
- description: "A collection of prompts that allow for interactive input in command line applications."
2662
+ description: "A collection of prompts that allow for interactive input in command-line applications."
2238
2663
  }, rest, {
2239
2664
  get imports() {
2240
2665
  return defu(rest.imports ?? {}, {
@@ -2278,6 +2703,8 @@ function PromptsBuiltin(props) {
2278
2703
  createComponent(Spacing, {}),
2279
2704
  createComponent(PasswordPromptDeclaration, {}),
2280
2705
  createComponent(Spacing, {}),
2706
+ createComponent(ConfirmPromptDeclarations, {}),
2707
+ createComponent(Spacing, {}),
2281
2708
  createComponent(Show, {
2282
2709
  get when() {
2283
2710
  return Boolean(children);
@@ -2290,5 +2717,5 @@ function PromptsBuiltin(props) {
2290
2717
  }
2291
2718
 
2292
2719
  //#endregion
2293
- export { BasePromptDeclarations, NumericPromptDeclarations, PasswordPromptDeclaration, PromptsBuiltin, SelectPromptDeclarations, TextPromptDeclarations, TogglePromptDeclarations };
2720
+ export { BasePromptDeclarations, ConfirmPromptDeclarations, NumericPromptDeclarations, PasswordPromptDeclaration, PromptsBuiltin, SelectPromptDeclarations, TextPromptDeclarations, TogglePromptDeclarations };
2294
2721
  //# sourceMappingURL=prompts-builtin.mjs.map