@inquirer/confirm 6.1.1 → 6.3.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 +23 -0
- package/dist/index.d.ts +27 -3
- package/dist/index.js +40 -14
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -78,14 +78,37 @@ type Theme = {
|
|
|
78
78
|
interval: number;
|
|
79
79
|
frames: string[];
|
|
80
80
|
};
|
|
81
|
+
keywords: {
|
|
82
|
+
yes: string;
|
|
83
|
+
no: string;
|
|
84
|
+
};
|
|
81
85
|
style: {
|
|
82
86
|
answer: (text: string) => string;
|
|
83
87
|
message: (text: string, status: 'idle' | 'done' | 'loading') => string;
|
|
84
88
|
defaultAnswer: (text: string) => string;
|
|
89
|
+
confirmDefault: (text: string) => string;
|
|
85
90
|
};
|
|
86
91
|
};
|
|
87
92
|
```
|
|
88
93
|
|
|
94
|
+
The `keywords` property defines the words accepted as "yes" and "no". Matching is
|
|
95
|
+
prefix-based and case-insensitive, and the first character of each word is shown in
|
|
96
|
+
the hint (e.g. `Y/n`). The matched word is also displayed once the prompt is answered.
|
|
97
|
+
Overriding `keywords` is how `@inquirer/i18n` localizes the prompt:
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
confirm({
|
|
101
|
+
message: '¿Continuar?',
|
|
102
|
+
theme: {
|
|
103
|
+
keywords: { yes: 'Sí', no: 'No' },
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
The `confirmDefault` style marks the character representing the default answer in the
|
|
109
|
+
hint. By default it uppercases the character (`Y/n`); for scripts without case
|
|
110
|
+
(e.g. Chinese) it highlights the character with a color instead.
|
|
111
|
+
|
|
89
112
|
# License
|
|
90
113
|
|
|
91
114
|
Copyright (c) 2023 Simon Boudrias (twitter: [@vaxilart](https://twitter.com/Vaxilart))<br/>
|
package/dist/index.d.ts
CHANGED
|
@@ -2,9 +2,33 @@ import { type Theme } from '@inquirer/core';
|
|
|
2
2
|
import type { PartialDeep } from '@inquirer/type';
|
|
3
3
|
type ConfirmConfig = {
|
|
4
4
|
message: string;
|
|
5
|
-
default?: boolean;
|
|
5
|
+
default?: boolean | undefined;
|
|
6
6
|
transformer?: (value: boolean) => string;
|
|
7
|
-
theme?: PartialDeep<Theme
|
|
7
|
+
theme?: PartialDeep<Theme<ConfirmTheme>>;
|
|
8
8
|
};
|
|
9
|
-
|
|
9
|
+
type ConfirmTheme = {
|
|
10
|
+
/**
|
|
11
|
+
* Words accepted as "yes" and "no" answers. Matching is prefix-based and
|
|
12
|
+
* case-insensitive, and the first character of each word is shown in the
|
|
13
|
+
* hint. These words are also displayed once the prompt is answered.
|
|
14
|
+
*/
|
|
15
|
+
keywords: {
|
|
16
|
+
yes: string;
|
|
17
|
+
no: string;
|
|
18
|
+
};
|
|
19
|
+
style: {
|
|
20
|
+
/**
|
|
21
|
+
* Style the character representing the default answer in the hint (e.g.
|
|
22
|
+
* "Y/n"). Uppercases it by default; scripts without case (e.g. Chinese)
|
|
23
|
+
* are highlighted with a color instead.
|
|
24
|
+
*/
|
|
25
|
+
confirmDefault: (text: string) => string;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
declare const _default: import("@inquirer/type").Prompt<boolean, {
|
|
29
|
+
message: string;
|
|
30
|
+
default?: boolean | undefined | undefined;
|
|
31
|
+
transformer?: ((value: boolean) => string) | undefined;
|
|
32
|
+
theme?: PartialDeep<Theme<ConfirmTheme>> | undefined;
|
|
33
|
+
} & ConfirmConfig>;
|
|
10
34
|
export default _default;
|
package/dist/index.js
CHANGED
|
@@ -1,21 +1,47 @@
|
|
|
1
1
|
import { createPrompt, useState, useKeypress, isEnterKey, isTabKey, usePrefix, makeTheme, } from '@inquirer/core';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
import { styleText } from 'node:util';
|
|
3
|
+
const confirmTheme = {
|
|
4
|
+
keywords: {
|
|
5
|
+
yes: 'Yes',
|
|
6
|
+
no: 'No',
|
|
7
|
+
},
|
|
8
|
+
style: {
|
|
9
|
+
confirmDefault: (text) => {
|
|
10
|
+
const first = text[0] ?? '';
|
|
11
|
+
if (first.toLowerCase() === first.toUpperCase()) {
|
|
12
|
+
return styleText('cyan', text);
|
|
13
|
+
}
|
|
14
|
+
return first.toUpperCase() + text.slice(1);
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
};
|
|
13
18
|
export default createPrompt((config, done) => {
|
|
14
|
-
const { transformer = boolToString } = config;
|
|
15
19
|
const [status, setStatus] = useState('idle');
|
|
16
20
|
const [value, setValue] = useState('');
|
|
17
|
-
const theme = makeTheme(config.theme);
|
|
21
|
+
const theme = makeTheme(confirmTheme, config.theme);
|
|
18
22
|
const prefix = usePrefix({ status, theme });
|
|
23
|
+
const { yes, no } = theme.keywords;
|
|
24
|
+
// The hint shows the first character of each label, lowercased; the default
|
|
25
|
+
// side is then uppercased (or colored) by `confirmDefault`.
|
|
26
|
+
const yesHint = (yes[0] ?? '').toLowerCase();
|
|
27
|
+
const noHint = (no[0] ?? '').toLowerCase();
|
|
28
|
+
const hint = config.default === false
|
|
29
|
+
? `${yesHint}/${theme.style.confirmDefault(noHint)}`
|
|
30
|
+
: `${theme.style.confirmDefault(yesHint)}/${noHint}`;
|
|
31
|
+
function boolToString(value) {
|
|
32
|
+
return value ? yes : no;
|
|
33
|
+
}
|
|
34
|
+
const { transformer = boolToString } = config;
|
|
35
|
+
function getBooleanValue(value, defaultValue) {
|
|
36
|
+
const v = value.toLowerCase();
|
|
37
|
+
if (v === '')
|
|
38
|
+
return defaultValue !== false;
|
|
39
|
+
if (yes.toLowerCase().startsWith(v))
|
|
40
|
+
return true;
|
|
41
|
+
if (no.toLowerCase().startsWith(v))
|
|
42
|
+
return false;
|
|
43
|
+
return defaultValue !== false;
|
|
44
|
+
}
|
|
19
45
|
useKeypress((key, rl) => {
|
|
20
46
|
if (status !== 'idle')
|
|
21
47
|
return;
|
|
@@ -41,7 +67,7 @@ export default createPrompt((config, done) => {
|
|
|
41
67
|
formattedValue = theme.style.answer(value);
|
|
42
68
|
}
|
|
43
69
|
else {
|
|
44
|
-
defaultValue = ` ${theme.style.defaultAnswer(
|
|
70
|
+
defaultValue = ` ${theme.style.defaultAnswer(hint)}`;
|
|
45
71
|
}
|
|
46
72
|
const message = theme.style.message(config.message, status);
|
|
47
73
|
return `${prefix} ${message}${defaultValue} ${formattedValue}`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inquirer/confirm",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.3.0",
|
|
4
4
|
"description": "Inquirer confirm prompt",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"answer",
|
|
@@ -67,10 +67,11 @@
|
|
|
67
67
|
"tsc": "tsc"
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@inquirer/core": "^
|
|
71
|
-
"@inquirer/type": "^4.0
|
|
70
|
+
"@inquirer/core": "^12.0.1",
|
|
71
|
+
"@inquirer/type": "^4.1.0"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
|
+
"@repo/tsconfig": "0.0.0",
|
|
74
75
|
"typescript": "^6.0.2"
|
|
75
76
|
},
|
|
76
77
|
"peerDependencies": {
|
|
@@ -86,5 +87,5 @@
|
|
|
86
87
|
},
|
|
87
88
|
"main": "./dist/index.js",
|
|
88
89
|
"types": "./dist/index.d.ts",
|
|
89
|
-
"gitHead": "
|
|
90
|
+
"gitHead": "51ac389603405e8f9f315ce49416153d95c5fefe"
|
|
90
91
|
}
|