@inquirer/input
Advanced tools
@@ -9,2 +9,3 @@ import { type Theme } from '@inquirer/core'; | ||
| default?: string; | ||
| prefill?: 'tab' | 'editable'; | ||
| required?: boolean; | ||
@@ -11,0 +12,0 @@ transformer?: (value: string, { isFinal }: { |
@@ -8,3 +8,3 @@ "use strict"; | ||
| exports.default = (0, core_1.createPrompt)((config, done) => { | ||
| const { required, validate = () => true } = config; | ||
| const { required, validate = () => true, prefill = 'tab' } = config; | ||
| const theme = (0, core_1.makeTheme)(inputTheme, config.theme); | ||
@@ -57,2 +57,10 @@ const [status, setStatus] = (0, core_1.useState)('idle'); | ||
| }); | ||
| // If prefill is set to 'editable' cut out the default value and paste into current state and the user's cli buffer | ||
| // They can edit the value immediately instead of needing to press 'tab' | ||
| (0, core_1.useEffect)((rl) => { | ||
| if (prefill === 'editable' && defaultValue) { | ||
| rl.write(defaultValue); | ||
| setValue(defaultValue); | ||
| } | ||
| }, []); | ||
| const message = theme.style.message(config.message, status); | ||
@@ -59,0 +67,0 @@ let formattedValue = value; |
@@ -9,2 +9,3 @@ import { type Theme } from '@inquirer/core'; | ||
| default?: string; | ||
| prefill?: 'tab' | 'editable'; | ||
| required?: boolean; | ||
@@ -11,0 +12,0 @@ transformer?: (value: string, { isFinal }: { |
+10
-2
@@ -1,2 +0,2 @@ | ||
| import { createPrompt, useState, useKeypress, usePrefix, isEnterKey, isBackspaceKey, makeTheme, } from '@inquirer/core'; | ||
| import { createPrompt, useState, useKeypress, useEffect, usePrefix, isEnterKey, isBackspaceKey, makeTheme, } from '@inquirer/core'; | ||
| const inputTheme = { | ||
@@ -6,3 +6,3 @@ validationFailureMode: 'keep', | ||
| export default createPrompt((config, done) => { | ||
| const { required, validate = () => true } = config; | ||
| const { required, validate = () => true, prefill = 'tab' } = config; | ||
| const theme = makeTheme(inputTheme, config.theme); | ||
@@ -55,2 +55,10 @@ const [status, setStatus] = useState('idle'); | ||
| }); | ||
| // If prefill is set to 'editable' cut out the default value and paste into current state and the user's cli buffer | ||
| // They can edit the value immediately instead of needing to press 'tab' | ||
| useEffect((rl) => { | ||
| if (prefill === 'editable' && defaultValue) { | ||
| rl.write(defaultValue); | ||
| setValue(defaultValue); | ||
| } | ||
| }, []); | ||
| const message = theme.style.message(config.message, status); | ||
@@ -57,0 +65,0 @@ let formattedValue = value; |
+4
-4
| { | ||
| "name": "@inquirer/input", | ||
| "version": "4.1.12", | ||
| "version": "4.2.0", | ||
| "description": "Inquirer input text prompt", | ||
@@ -77,3 +77,3 @@ "keywords": [ | ||
| "dependencies": { | ||
| "@inquirer/core": "^10.1.13", | ||
| "@inquirer/core": "^10.1.14", | ||
| "@inquirer/type": "^3.0.7" | ||
@@ -83,3 +83,3 @@ }, | ||
| "@arethetypeswrong/cli": "^0.18.1", | ||
| "@inquirer/testing": "^2.1.47", | ||
| "@inquirer/testing": "^2.1.48", | ||
| "tshy": "^3.0.2" | ||
@@ -110,3 +110,3 @@ }, | ||
| }, | ||
| "gitHead": "dc0770cf6344140b19b2e6b82330fc51084653d1" | ||
| "gitHead": "43b7bb94390c1e2b6473af1b790ff2fd1c8007c8" | ||
| } |
+2
-1
@@ -76,3 +76,4 @@ # `@inquirer/input` | ||
| | message | `string` | yes | The question to ask | | ||
| | default | `string` | no | Default value if no answer is provided (press `backspace` to clear the default; press `tab` to inline the value for edits) | | ||
| | default | `string` | no | Default value if no answer is provided; see the prefill option below for governing it's behaviour. | | ||
| | 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. | | ||
| | required | `boolean` | no | Defaults to `false`. If set to true, `undefined` (empty) will not be accepted for this. | | ||
@@ -79,0 +80,0 @@ | 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. | |
16016
7.87%206
9.57%110
0.92%Updated