@inquirer/rawlist 1.2.16 → 2.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
@@ -33,6 +33,27 @@ const answer = await rawlist({
33
33
  | -------- | ------------------------------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
34
34
  | message | `string` | yes | The question to ask |
35
35
  | choices | `Array<{ value: string, name?: string, key?: string }>` | yes | List of the available choices. The `value` will be returned as the answer, and used as display if no `name` is defined. By default, choices will be selected by index. This can be customized by using the `key` option. |
36
+ | theme | [See Theming](#Theming) | no | Customize look of the prompt. |
37
+
38
+ ## Theming
39
+
40
+ You can theme a prompt by passing a `theme` object option. The theme object only need to includes the keys you wish to modify, we'll fallback on the defaults for the rest.
41
+
42
+ ```ts
43
+ type Theme = {
44
+ prefix: string;
45
+ spinner: {
46
+ interval: number;
47
+ frames: string[];
48
+ };
49
+ style: {
50
+ answer: (text: string) => string;
51
+ message: (text: string) => string;
52
+ error: (text: string) => string;
53
+ highlight: (text: string) => string;
54
+ };
55
+ };
56
+ ```
36
57
 
37
58
  # License
38
59
 
package/dist/cjs/index.js CHANGED
@@ -16,7 +16,8 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
16
16
  const [status, setStatus] = (0, core_1.useState)('pending');
17
17
  const [value, setValue] = (0, core_1.useState)('');
18
18
  const [errorMsg, setError] = (0, core_1.useState)(undefined);
19
- const prefix = (0, core_1.usePrefix)();
19
+ const theme = (0, core_1.makeTheme)(config.theme);
20
+ const prefix = (0, core_1.usePrefix)({ theme });
20
21
  (0, core_1.useKeypress)((key, rl) => {
21
22
  if ((0, core_1.isEnterKey)(key)) {
22
23
  let selectedChoice;
@@ -45,9 +46,9 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
45
46
  setError(undefined);
46
47
  }
47
48
  });
48
- const message = chalk_1.default.bold(config.message);
49
+ const message = theme.style.message(config.message);
49
50
  if (status === 'done') {
50
- return `${prefix} ${message} ${chalk_1.default.cyan(value)}`;
51
+ return `${prefix} ${message} ${theme.style.answer(value)}`;
51
52
  }
52
53
  let index = 0;
53
54
  const choicesStr = choices
@@ -58,14 +59,14 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
58
59
  index += 1;
59
60
  const line = ` ${choice.key || index}) ${choice.name || choice.value}`;
60
61
  if (choice.key === value.toLowerCase() || String(index) === value) {
61
- return chalk_1.default.cyan(line);
62
+ return theme.style.highlight(line);
62
63
  }
63
64
  return line;
64
65
  })
65
66
  .join('\n');
66
67
  let error = '';
67
68
  if (errorMsg) {
68
- error = chalk_1.default.red(`> ${errorMsg}`);
69
+ error = theme.style.error(errorMsg);
69
70
  }
70
71
  return [
71
72
  `${prefix} ${message} ${value}`,
@@ -5,8 +5,24 @@ type Choice<Value> = {
5
5
  key?: string;
6
6
  };
7
7
  declare const _default: <Value extends unknown>(config: {
8
- message: string | Promise<string> | (() => Promise<string>);
8
+ message: string;
9
9
  choices: readonly (Separator | Choice<Value>)[];
10
+ theme?: {
11
+ prefix?: string | undefined;
12
+ spinner?: {
13
+ interval?: number | undefined;
14
+ frames?: (string | undefined)[] | undefined;
15
+ } | undefined;
16
+ style?: {
17
+ answer?: {} | undefined;
18
+ message?: {} | undefined;
19
+ error?: {} | undefined;
20
+ defaultAnswer?: {} | undefined;
21
+ help?: {} | undefined;
22
+ highlight?: {} | undefined;
23
+ key?: {} | undefined;
24
+ } | undefined;
25
+ } | undefined;
10
26
  }, context?: import("@inquirer/type").Context | undefined) => import("@inquirer/type").CancelablePromise<Value>;
11
27
  export default _default;
12
28
  export { Separator };
@@ -1,4 +1,4 @@
1
- import { createPrompt, useState, useKeypress, usePrefix, isEnterKey, Separator, } from '@inquirer/core';
1
+ import { createPrompt, useState, useKeypress, usePrefix, isEnterKey, Separator, makeTheme, } from '@inquirer/core';
2
2
  import chalk from 'chalk';
3
3
  const numberRegex = /[0-9]+/;
4
4
  function isSelectableChoice(choice) {
@@ -9,7 +9,8 @@ export default createPrompt((config, done) => {
9
9
  const [status, setStatus] = useState('pending');
10
10
  const [value, setValue] = useState('');
11
11
  const [errorMsg, setError] = useState(undefined);
12
- const prefix = usePrefix();
12
+ const theme = makeTheme(config.theme);
13
+ const prefix = usePrefix({ theme });
13
14
  useKeypress((key, rl) => {
14
15
  if (isEnterKey(key)) {
15
16
  let selectedChoice;
@@ -38,9 +39,9 @@ export default createPrompt((config, done) => {
38
39
  setError(undefined);
39
40
  }
40
41
  });
41
- const message = chalk.bold(config.message);
42
+ const message = theme.style.message(config.message);
42
43
  if (status === 'done') {
43
- return `${prefix} ${message} ${chalk.cyan(value)}`;
44
+ return `${prefix} ${message} ${theme.style.answer(value)}`;
44
45
  }
45
46
  let index = 0;
46
47
  const choicesStr = choices
@@ -51,14 +52,14 @@ export default createPrompt((config, done) => {
51
52
  index += 1;
52
53
  const line = ` ${choice.key || index}) ${choice.name || choice.value}`;
53
54
  if (choice.key === value.toLowerCase() || String(index) === value) {
54
- return chalk.cyan(line);
55
+ return theme.style.highlight(line);
55
56
  }
56
57
  return line;
57
58
  })
58
59
  .join('\n');
59
60
  let error = '';
60
61
  if (errorMsg) {
61
- error = chalk.red(`> ${errorMsg}`);
62
+ error = theme.style.error(errorMsg);
62
63
  }
63
64
  return [
64
65
  `${prefix} ${message} ${value}`,
@@ -5,8 +5,24 @@ type Choice<Value> = {
5
5
  key?: string;
6
6
  };
7
7
  declare const _default: <Value extends unknown>(config: {
8
- message: string | Promise<string> | (() => Promise<string>);
8
+ message: string;
9
9
  choices: readonly (Separator | Choice<Value>)[];
10
+ theme?: {
11
+ prefix?: string | undefined;
12
+ spinner?: {
13
+ interval?: number | undefined;
14
+ frames?: (string | undefined)[] | undefined;
15
+ } | undefined;
16
+ style?: {
17
+ answer?: {} | undefined;
18
+ message?: {} | undefined;
19
+ error?: {} | undefined;
20
+ defaultAnswer?: {} | undefined;
21
+ help?: {} | undefined;
22
+ highlight?: {} | undefined;
23
+ key?: {} | undefined;
24
+ } | undefined;
25
+ } | undefined;
10
26
  }, context?: import("@inquirer/type").Context | undefined) => import("@inquirer/type").CancelablePromise<Value>;
11
27
  export default _default;
12
28
  export { Separator };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inquirer/rawlist",
3
- "version": "1.2.16",
3
+ "version": "2.0.0",
4
4
  "description": "Inquirer rawlist prompt",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "typings": "./dist/cjs/types/index.d.ts",
@@ -54,12 +54,12 @@
54
54
  "license": "MIT",
55
55
  "homepage": "https://github.com/SBoudrias/Inquirer.js/blob/master/packages/rawlist/README.md",
56
56
  "dependencies": {
57
- "@inquirer/core": "^6.0.0",
58
- "@inquirer/type": "^1.1.6",
57
+ "@inquirer/core": "^7.0.0",
58
+ "@inquirer/type": "^1.2.0",
59
59
  "chalk": "^4.1.2"
60
60
  },
61
61
  "devDependencies": {
62
- "@inquirer/testing": "^2.1.10"
62
+ "@inquirer/testing": "^2.1.11"
63
63
  },
64
64
  "scripts": {
65
65
  "tsc": "yarn run tsc:esm && yarn run tsc:cjs",
@@ -70,7 +70,7 @@
70
70
  "access": "public"
71
71
  },
72
72
  "engines": {
73
- "node": ">=14.18.0"
73
+ "node": ">=18"
74
74
  },
75
75
  "exports": {
76
76
  ".": {
@@ -84,5 +84,5 @@
84
84
  }
85
85
  }
86
86
  },
87
- "gitHead": "4dee2b11d89a7c8a698c9eeda546ba8092b84f64"
87
+ "gitHead": "44016a40bc9e93455dfdb9fa6c25c27c1c109bd3"
88
88
  }