[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: add log (#82)

authored by

Nate Moore and committed by
GitHub
(Feb 24, 2023, 6:44 PM -0600) a79733e9 ab1c7f66

+61 -13
+5
.changeset/hot-candles-repeat.md
··· 1 + --- 2 + "@clack/prompts": minor 3 + --- 4 + 5 + Add `log` APIs. Supports `log.info`, `log.success`, `log.warn`, and `log.error`. For low-level control, `log.message` is also exposed.
+56 -13
packages/prompts/src/index.ts
··· 38 38 const S_CONNECT_LEFT = s('├', '+'); 39 39 const S_CORNER_BOTTOM_RIGHT = s('╯', '+'); 40 40 41 + const S_INFO = s('●', '•'); 42 + const S_SUCCESS = s('◆', '*'); 43 + const S_WARN = s('▲', '!'); 44 + const S_ERROR = s('■', 'x'); 45 + 41 46 const symbol = (state: State) => { 42 47 switch (state) { 43 48 case 'initial': ··· 340 345 i === 0 ? `${color.yellow(S_BAR_END)} ${color.yellow(ln)}` : ` ${ln}` 341 346 ) 342 347 .join('\n'); 343 - return `${title}${color.yellow(S_BAR)} ${this.options 344 - .map((option, i) => { 345 - const selected = this.value.includes(option.value); 346 - const active = i === this.cursor; 347 - if (active && selected) { 348 - return opt(option, 'active-selected'); 349 - } 350 - if (selected) { 351 - return opt(option, 'selected'); 352 - } 353 - return opt(option, active ? 'active' : 'inactive'); 354 - }) 355 - .join(`\n${color.yellow(S_BAR)} `)}\n${footer}\n`; 348 + return ( 349 + title + 350 + color.yellow(S_BAR) + 351 + ' ' + 352 + this.options 353 + .map((option, i) => { 354 + const selected = this.value.includes(option.value); 355 + const active = i === this.cursor; 356 + if (active && selected) { 357 + return opt(option, 'active-selected'); 358 + } 359 + if (selected) { 360 + return opt(option, 'selected'); 361 + } 362 + return opt(option, active ? 'active' : 'inactive'); 363 + }) 364 + .join(`\n${color.yellow(S_BAR)} `) + 365 + '\n' + 366 + footer + 367 + '\n' 368 + ); 356 369 } 357 370 default: { 358 371 return `${title}${color.cyan(S_BAR)} ${this.options ··· 407 420 408 421 export const outro = (message = '') => { 409 422 process.stdout.write(`${color.gray(S_BAR)}\n${color.gray(S_BAR_END)} ${message}\n\n`); 423 + }; 424 + 425 + export type LogMessageOptions = { 426 + symbol?: string; 427 + }; 428 + export const log = { 429 + message: (message = '', { symbol = color.gray(S_BAR) }: LogMessageOptions = {}) => { 430 + const parts = [`${color.gray(S_BAR)}`]; 431 + if (message) { 432 + const [firstLine, ...lines] = message.split('\n'); 433 + parts.push(`${symbol} ${firstLine}`, ...lines.map((ln) => `${color.gray(S_BAR)} ${ln}`)); 434 + } 435 + process.stdout.write(`${parts.join('\n')}\n`); 436 + }, 437 + info: (message: string) => { 438 + log.message(message, { symbol: color.blue(S_INFO) }); 439 + }, 440 + success: (message: string) => { 441 + log.message(message, { symbol: color.green(S_SUCCESS) }); 442 + }, 443 + warn: (message: string) => { 444 + log.message(message, { symbol: color.yellow(S_WARN) }); 445 + }, 446 + /** alias for `log.warn()`. */ 447 + warning: (message: string) => { 448 + log.warn(message); 449 + }, 450 + error: (message: string) => { 451 + log.message(message, { symbol: color.red(S_ERROR) }); 452 + }, 410 453 }; 411 454 412 455 const frames = unicode ? ['◒', '◐', '◓', '◑'] : ['•', 'o', 'O', '0'];