[READ-ONLY] Mirror of https://github.com/bombshell-dev/clack. Effortlessly build beautiful command-line apps bomb.sh/docs/clack/basics/getting-started/
cli command-line command-line-app node prompt prompts
5

Configure Feed

Select the types of activity you want to include in your feed.

Do not default value to placeholder (#50)

authored by

Nate Moore and committed by
GitHub
(Feb 17, 2023, 4:46 AM -0600) cc5a47b7 362d3188

+13 -4
+6
.changeset/eleven-pumpkins-refuse.md
··· 1 + --- 2 + "@clack/prompts": patch 3 + "@clack/core": patch 4 + --- 5 + 6 + Adds a new `defaultValue` option to the text prompt, removes automatic usage of the placeholder value.
-3
packages/core/src/prompts/prompt.ts
··· 153 153 } 154 154 155 155 if (key?.name === 'return') { 156 - if ('placeholder' in this.opts && !this.value) { 157 - this.value = this.opts.placeholder; 158 - } 159 156 if (this.opts.validate) { 160 157 const problem = this.opts.validate(this.value); 161 158 if (problem) {
+4
packages/core/src/prompts/text.ts
··· 3 3 4 4 export interface TextOptions extends PromptOptions<TextPrompt> { 5 5 placeholder?: string; 6 + defaultValue?: string; 6 7 } 7 8 8 9 export default class TextPrompt extends Prompt { ··· 14 15 super(opts); 15 16 16 17 this.on('finalize', () => { 18 + if (!this.value) { 19 + this.value = opts.defaultValue; 20 + } 17 21 this.valueWithCursor = this.value; 18 22 }); 19 23 this.on('value', () => {
+3 -1
packages/prompts/src/index.ts
··· 45 45 export interface TextOptions { 46 46 message: string; 47 47 placeholder?: string; 48 + defaultValue?: string; 48 49 initialValue?: string; 49 50 validate?: (value: string) => string | void; 50 51 } ··· 52 53 return new TextPrompt({ 53 54 validate: opts.validate, 54 55 placeholder: opts.placeholder, 56 + defaultValue: opts.defaultValue, 55 57 initialValue: opts.initialValue, 56 58 render() { 57 59 const title = `${color.gray(S_BAR)}\n${symbol(this.state)} ${ ··· 69 71 S_BAR 70 72 )} ${value}\n${color.yellow(S_BAR_END)} ${color.yellow(this.error)}\n`; 71 73 case "submit": 72 - return `${title}${color.gray(S_BAR)} ${color.dim(this.value)}`; 74 + return `${title}${color.gray(S_BAR)} ${color.dim(this.value || opts.placeholder)}`; 73 75 case "cancel": 74 76 return `${title}${color.gray(S_BAR)} ${color.strikethrough( 75 77 color.dim(this.value)