[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.

feat: confitm prompt multiline

Bruno Rocha (Aug 12, 2023, 3:51 PM -0300) 0612e379 b19e4b2f

+58 -23
+58 -23
packages/prompts/src/index.ts
··· 60 60 61 61 function formatTextWithMaxWidth( 62 62 text: string, 63 - options?: Partial<{ 64 - defaultSymbol: string; 65 - initialSymbol: string; 66 - newLineSymbol: string; 67 - endSymbol: string; 68 - lineWrapper: (line: string) => string; 69 - }> 63 + options?: { 64 + defaultSymbol?: string; 65 + initialSymbol?: string; 66 + newLineSymbol?: string; 67 + endSymbol?: string; 68 + lineWrapper?: (line: string) => string; 69 + } 70 70 ): string { 71 71 const defaultSymbol = options?.defaultSymbol ?? color.cyan(S_BAR); 72 72 const initialSymbol = options?.initialSymbol ?? defaultSymbol; ··· 151 151 case 'cancel': 152 152 return [ 153 153 title, 154 - formatTextWithMaxWidth(this.value?.trim() ? this.value : '', { 154 + formatTextWithMaxWidth(this.value ?? '', { 155 155 defaultSymbol: color.gray(S_BAR), 156 156 endSymbol: color.gray(S_BAR_END), 157 157 lineWrapper: (line) => color.strikethrough(color.dim(line)), 158 158 }), 159 159 ].join('\n'); 160 160 default: 161 - return [title, formatTextWithMaxWidth(value)].join('\n'); 161 + return [ 162 + title, 163 + formatTextWithMaxWidth(value, { 164 + endSymbol: color.cyan(S_BAR_END), 165 + }), 166 + ].join('\n'); 162 167 } 163 168 }, 164 169 }).prompt() as Promise<string | symbol>; ··· 174 179 validate: opts.validate, 175 180 mask: opts.mask ?? S_PASSWORD_MASK, 176 181 render() { 177 - const title = `${color.gray(S_BAR)}\n${symbol(this.state)} ${opts.message}\n`; 182 + const title = [ 183 + color.gray(S_BAR), 184 + formatTextWithMaxWidth(opts.message, { 185 + initialSymbol: symbol(this.state), 186 + }), 187 + ].join('\n'); 178 188 const value = this.valueWithCursor; 179 189 const masked = this.masked; 180 190 181 191 switch (this.state) { 182 192 case 'error': 183 - return `${title.trim()}\n${color.yellow(S_BAR)} ${masked}\n${color.yellow( 184 - S_BAR_END 185 - )} ${color.yellow(this.error)}\n`; 193 + return [ 194 + title, 195 + formatTextWithMaxWidth(masked, { 196 + defaultSymbol: color.yellow(S_BAR), 197 + }), 198 + formatTextWithMaxWidth(this.error, { 199 + defaultSymbol: color.yellow(S_BAR), 200 + endSymbol: color.yellow(S_BAR_END), 201 + lineWrapper: color.yellow, 202 + }), 203 + ].join('\n'); 186 204 case 'submit': 187 - return `${title}${color.gray(S_BAR)} ${color.dim(masked)}`; 205 + return [title, formatTextWithMaxWidth(masked, { lineWrapper: color.dim })].join('\n'); 188 206 case 'cancel': 189 - return `${title}${color.gray(S_BAR)} ${color.strikethrough(color.dim(masked ?? ''))}${ 190 - masked ? '\n' + color.gray(S_BAR) : '' 191 - }`; 207 + return [ 208 + title, 209 + formatTextWithMaxWidth(masked ?? '', { 210 + defaultSymbol: color.gray(S_BAR), 211 + endSymbol: color.gray(S_BAR_END), 212 + lineWrapper: (line) => color.strikethrough(color.dim(line)), 213 + }), 214 + ].join('\n'); 192 215 default: 193 - return `${title}${color.cyan(S_BAR)} ${value}\n${color.cyan(S_BAR_END)}\n`; 216 + return [title, formatTextWithMaxWidth(value, { endSymbol: color.cyan(S_BAR_END) })].join( 217 + '\n' 218 + ); 194 219 } 195 220 }, 196 221 }).prompt() as Promise<string | symbol>; ··· 210 235 inactive, 211 236 initialValue: opts.initialValue ?? true, 212 237 render() { 213 - const title = `${color.gray(S_BAR)}\n${symbol(this.state)} ${opts.message}\n`; 238 + const title = [ 239 + color.gray(S_BAR), 240 + formatTextWithMaxWidth(opts.message, { 241 + initialSymbol: symbol(this.state), 242 + }), 243 + ].join('\n'); 214 244 const value = this.value ? active : inactive; 215 245 216 246 switch (this.state) { 217 247 case 'submit': 218 - return `${title}${color.gray(S_BAR)} ${color.dim(value)}`; 248 + return [title, formatTextWithMaxWidth(value, { lineWrapper: color.dim })].join('\n'); 219 249 case 'cancel': 220 - return `${title}${color.gray(S_BAR)} ${color.strikethrough( 221 - color.dim(value) 222 - )}\n${color.gray(S_BAR)}`; 250 + return [ 251 + title, 252 + formatTextWithMaxWidth(value, { 253 + defaultSymbol: color.gray(S_BAR), 254 + endSymbol: color.gray(S_BAR_END), 255 + lineWrapper: (line) => color.strikethrough(color.dim(line)), 256 + }), 257 + ].join('\n'); 223 258 default: { 224 259 return `${title}${color.cyan(S_BAR)} ${ 225 260 this.value