@inquirer/input 4.1.12 → 4.2.1

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
@@ -73,7 +73,8 @@ const answer = await input({ message: 'Enter your name' });
73
73
  | Property | Type | Required | Description |
74
74
  | ----------- | ----------------------------------------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
75
75
  | message | `string` | yes | The question to ask |
76
- | default | `string` | no | Default value if no answer is provided (press `backspace` to clear the default; press `tab` to inline the value for edits) |
76
+ | default | `string` | no | Default value if no answer is provided; see the prefill option below for governing it's behaviour. |
77
+ | prefill | `'tab' \| 'editable'` | no | Defaults to `'tab'`. If set to `'tab'`, pressing `backspace` will clear the default and pressing `tab` will inline the value for edits; If set to `'editable'`, the default value will already be inlined to edit. |
77
78
  | required | `boolean` | no | Defaults to `false`. If set to true, `undefined` (empty) will not be accepted for this. |
78
79
  | transformer | `(string, { isFinal: boolean }) => string` | no | Transform/Format the raw value entered by the user. Once the prompt is completed, `isFinal` will be `true`. This function is purely visual, modify the answer in your code if needed. |
79
80
  | validate | `string => boolean \| string \| Promise<boolean \| string>` | no | On submit, validate the filtered answered content. When returning a string, it'll be used as the error message displayed to the user. Note: returning a rejected promise, we'll assume a code error happened and crash. |
@@ -6,6 +6,7 @@ type InputTheme = {
6
6
  type InputConfig = {
7
7
  message: string;
8
8
  default?: string;
9
+ prefill?: 'tab' | 'editable';
9
10
  required?: boolean;
10
11
  transformer?: (value: string, { isFinal }: {
11
12
  isFinal: boolean;
@@ -5,7 +5,7 @@ const inputTheme = {
5
5
  validationFailureMode: 'keep',
6
6
  };
7
7
  exports.default = (0, core_1.createPrompt)((config, done) => {
8
- const { required, validate = () => true } = config;
8
+ const { required, validate = () => true, prefill = 'tab' } = config;
9
9
  const theme = (0, core_1.makeTheme)(inputTheme, config.theme);
10
10
  const [status, setStatus] = (0, core_1.useState)('idle');
11
11
  const [defaultValue = '', setDefaultValue] = (0, core_1.useState)(config.default);
@@ -53,6 +53,14 @@ exports.default = (0, core_1.createPrompt)((config, done) => {
53
53
  setError(undefined);
54
54
  }
55
55
  });
56
+ // If prefill is set to 'editable' cut out the default value and paste into current state and the user's cli buffer
57
+ // They can edit the value immediately instead of needing to press 'tab'
58
+ (0, core_1.useEffect)((rl) => {
59
+ if (prefill === 'editable' && defaultValue) {
60
+ rl.write(defaultValue);
61
+ setValue(defaultValue);
62
+ }
63
+ }, []);
56
64
  const message = theme.style.message(config.message, status);
57
65
  let formattedValue = value;
58
66
  if (typeof config.transformer === 'function') {
@@ -6,6 +6,7 @@ type InputTheme = {
6
6
  type InputConfig = {
7
7
  message: string;
8
8
  default?: string;
9
+ prefill?: 'tab' | 'editable';
9
10
  required?: boolean;
10
11
  transformer?: (value: string, { isFinal }: {
11
12
  isFinal: boolean;
package/dist/esm/index.js CHANGED
@@ -1,9 +1,9 @@
1
- import { createPrompt, useState, useKeypress, usePrefix, isEnterKey, isBackspaceKey, makeTheme, } from '@inquirer/core';
1
+ import { createPrompt, useState, useKeypress, useEffect, usePrefix, isEnterKey, isBackspaceKey, makeTheme, } from '@inquirer/core';
2
2
  const inputTheme = {
3
3
  validationFailureMode: 'keep',
4
4
  };
5
5
  export default createPrompt((config, done) => {
6
- const { required, validate = () => true } = config;
6
+ const { required, validate = () => true, prefill = 'tab' } = config;
7
7
  const theme = makeTheme(inputTheme, config.theme);
8
8
  const [status, setStatus] = useState('idle');
9
9
  const [defaultValue = '', setDefaultValue] = useState(config.default);
@@ -51,6 +51,14 @@ export default createPrompt((config, done) => {
51
51
  setError(undefined);
52
52
  }
53
53
  });
54
+ // If prefill is set to 'editable' cut out the default value and paste into current state and the user's cli buffer
55
+ // They can edit the value immediately instead of needing to press 'tab'
56
+ useEffect((rl) => {
57
+ if (prefill === 'editable' && defaultValue) {
58
+ rl.write(defaultValue);
59
+ setValue(defaultValue);
60
+ }
61
+ }, []);
54
62
  const message = theme.style.message(config.message, status);
55
63
  let formattedValue = value;
56
64
  if (typeof config.transformer === 'function') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inquirer/input",
3
- "version": "4.1.12",
3
+ "version": "4.2.1",
4
4
  "description": "Inquirer input text prompt",
5
5
  "keywords": [
6
6
  "answer",
@@ -74,12 +74,12 @@
74
74
  "tsc": "tshy"
75
75
  },
76
76
  "dependencies": {
77
- "@inquirer/core": "^10.1.13",
78
- "@inquirer/type": "^3.0.7"
77
+ "@inquirer/core": "^10.1.15",
78
+ "@inquirer/type": "^3.0.8"
79
79
  },
80
80
  "devDependencies": {
81
- "@arethetypeswrong/cli": "^0.18.1",
82
- "@inquirer/testing": "^2.1.47",
81
+ "@arethetypeswrong/cli": "^0.18.2",
82
+ "@inquirer/testing": "^2.1.49",
83
83
  "tshy": "^3.0.2"
84
84
  },
85
85
  "engines": {
@@ -105,5 +105,5 @@
105
105
  "optional": true
106
106
  }
107
107
  },
108
- "gitHead": "dc0770cf6344140b19b2e6b82330fc51084653d1"
108
+ "gitHead": "c1a755fe8b50377b685ea5951e0794985ce8d356"
109
109
  }