@inquirer/input 2.3.0 → 3.0.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/README.md CHANGED
@@ -75,14 +75,14 @@ You can theme a prompt by passing a `theme` object option. The theme object only
75
75
 
76
76
  ```ts
77
77
  type Theme = {
78
- prefix: string;
78
+ prefix: string | { idle: string; done: string };
79
79
  spinner: {
80
80
  interval: number;
81
81
  frames: string[];
82
82
  };
83
83
  style: {
84
84
  answer: (text: string) => string;
85
- message: (text: string) => string;
85
+ message: (text: string, status: 'idle' | 'done' | 'loading') => string;
86
86
  error: (text: string) => string;
87
87
  defaultAnswer: (text: string) => string;
88
88
  };
package/dist/cjs/index.js CHANGED
@@ -13,15 +13,14 @@ const core_1 = require("@inquirer/core");
13
13
  exports.default = (0, core_1.createPrompt)((config, done) => {
14
14
  const { required, validate = () => true } = config;
15
15
  const theme = (0, core_1.makeTheme)(config.theme);
16
- const [status, setStatus] = (0, core_1.useState)('pending');
16
+ const [status, setStatus] = (0, core_1.useState)('idle');
17
17
  const [defaultValue = '', setDefaultValue] = (0, core_1.useState)(config.default);
18
18
  const [errorMsg, setError] = (0, core_1.useState)();
19
19
  const [value, setValue] = (0, core_1.useState)('');
20
- const isLoading = status === 'loading';
21
- const prefix = (0, core_1.usePrefix)({ isLoading, theme });
20
+ const prefix = (0, core_1.usePrefix)({ status, theme });
22
21
  (0, core_1.useKeypress)((key, rl) => __awaiter(void 0, void 0, void 0, function* () {
23
22
  // Ignore keypress while our prompt is doing other processing.
24
- if (status !== 'pending') {
23
+ if (status !== 'idle') {
25
24
  return;
26
25
  }
27
26
  if ((0, core_1.isEnterKey)(key)) {
@@ -38,7 +37,7 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
38
37
  // get cleared, forcing the user to re-enter the value instead of fixing it.
39
38
  rl.write(value);
40
39
  setError(isValid || 'You must provide a valid value');
41
- setStatus('pending');
40
+ setStatus('idle');
42
41
  }
43
42
  }
44
43
  else if ((0, core_1.isBackspaceKey)(key) && !value) {
@@ -55,7 +54,7 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
55
54
  setError(undefined);
56
55
  }
57
56
  }));
58
- const message = theme.style.message(config.message);
57
+ const message = theme.style.message(config.message, status);
59
58
  let formattedValue = value;
60
59
  if (typeof config.transformer === 'function') {
61
60
  formattedValue = config.transformer(value, { isFinal: status === 'done' });
@@ -2,15 +2,14 @@ import { createPrompt, useState, useKeypress, usePrefix, isEnterKey, isBackspace
2
2
  export default createPrompt((config, done) => {
3
3
  const { required, validate = () => true } = config;
4
4
  const theme = makeTheme(config.theme);
5
- const [status, setStatus] = useState('pending');
5
+ const [status, setStatus] = useState('idle');
6
6
  const [defaultValue = '', setDefaultValue] = useState(config.default);
7
7
  const [errorMsg, setError] = useState();
8
8
  const [value, setValue] = useState('');
9
- const isLoading = status === 'loading';
10
- const prefix = usePrefix({ isLoading, theme });
9
+ const prefix = usePrefix({ status, theme });
11
10
  useKeypress(async (key, rl) => {
12
11
  // Ignore keypress while our prompt is doing other processing.
13
- if (status !== 'pending') {
12
+ if (status !== 'idle') {
14
13
  return;
15
14
  }
16
15
  if (isEnterKey(key)) {
@@ -27,7 +26,7 @@ export default createPrompt((config, done) => {
27
26
  // get cleared, forcing the user to re-enter the value instead of fixing it.
28
27
  rl.write(value);
29
28
  setError(isValid || 'You must provide a valid value');
30
- setStatus('pending');
29
+ setStatus('idle');
31
30
  }
32
31
  }
33
32
  else if (isBackspaceKey(key) && !value) {
@@ -44,7 +43,7 @@ export default createPrompt((config, done) => {
44
43
  setError(undefined);
45
44
  }
46
45
  });
47
- const message = theme.style.message(config.message);
46
+ const message = theme.style.message(config.message, status);
48
47
  let formattedValue = value;
49
48
  if (typeof config.transformer === 'function') {
50
49
  formattedValue = config.transformer(value, { isFinal: status === 'done' });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inquirer/input",
3
- "version": "2.3.0",
3
+ "version": "3.0.0",
4
4
  "description": "Inquirer input text prompt",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "typings": "./dist/cjs/types/index.d.ts",
@@ -54,11 +54,11 @@
54
54
  "license": "MIT",
55
55
  "homepage": "https://github.com/SBoudrias/Inquirer.js/blob/main/packages/input/README.md",
56
56
  "dependencies": {
57
- "@inquirer/core": "^9.1.0",
58
- "@inquirer/type": "^1.5.3"
57
+ "@inquirer/core": "^9.2.0",
58
+ "@inquirer/type": "^1.5.4"
59
59
  },
60
60
  "devDependencies": {
61
- "@inquirer/testing": "^2.1.32"
61
+ "@inquirer/testing": "^2.1.33"
62
62
  },
63
63
  "scripts": {
64
64
  "tsc": "yarn run tsc:esm && yarn run tsc:cjs",
@@ -85,5 +85,5 @@
85
85
  }
86
86
  },
87
87
  "sideEffects": false,
88
- "gitHead": "0c039599ef88fe9eb804fe083ee386ec906a856f"
88
+ "gitHead": "5fe03a4686d349d0d6cf281f86f12a4f7c992ad4"
89
89
  }