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

Configure Feed

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

feat: add withGuide support to note prompt (#418)

+44 -3
+5
.changeset/chatty-islands-move.md
··· 1 + --- 2 + "@clack/prompts": patch 3 + --- 4 + 5 + Add withGuide support to note prompt
+7 -3
packages/prompts/src/note.ts
··· 1 1 import process from 'node:process'; 2 2 import type { Writable } from 'node:stream'; 3 - import { getColumns } from '@clack/core'; 3 + import { getColumns, settings } from '@clack/core'; 4 4 import stringWidth from 'fast-string-width'; 5 5 import { type Options as WrapAnsiOptions, wrapAnsi } from 'fast-wrap-ansi'; 6 6 import color from 'picocolors'; ··· 9 9 S_BAR, 10 10 S_BAR_H, 11 11 S_CONNECT_LEFT, 12 + S_CORNER_BOTTOM_LEFT, 12 13 S_CORNER_BOTTOM_RIGHT, 13 14 S_CORNER_TOP_RIGHT, 14 15 S_STEP_SUBMIT, ··· 35 36 36 37 export const note = (message = '', title = '', opts?: NoteOptions) => { 37 38 const output: Writable = opts?.output ?? process.stdout; 39 + const hasGuide = (opts?.withGuide ?? settings.withGuide) !== false; 38 40 const format = opts?.format ?? defaultNoteFormatter; 39 41 const wrapMsg = wrapWithFormat(message, getColumns(output) - 6, format); 40 42 const lines = ['', ...wrapMsg.split('\n').map(format), '']; ··· 52 54 (ln) => `${color.gray(S_BAR)} ${ln}${' '.repeat(len - stringWidth(ln))}${color.gray(S_BAR)}` 53 55 ) 54 56 .join('\n'); 57 + const leadingBorder = hasGuide ? `${color.gray(S_BAR)}\n` : ''; 58 + const bottomLeft = hasGuide ? S_CONNECT_LEFT : S_CORNER_BOTTOM_LEFT; 55 59 output.write( 56 - `${color.gray(S_BAR)}\n${color.green(S_STEP_SUBMIT)} ${color.reset(title)} ${color.gray( 60 + `${leadingBorder}${color.green(S_STEP_SUBMIT)} ${color.reset(title)} ${color.gray( 57 61 S_BAR_H.repeat(Math.max(len - titleLen - 1, 1)) + S_CORNER_TOP_RIGHT 58 - )}\n${msg}\n${color.gray(S_CONNECT_LEFT + S_BAR_H.repeat(len + 2) + S_CORNER_BOTTOM_RIGHT)}\n` 62 + )}\n${msg}\n${color.gray(bottomLeft + S_BAR_H.repeat(len + 2) + S_CORNER_BOTTOM_RIGHT)}\n` 59 63 ); 60 64 };
+22
packages/prompts/test/__snapshots__/note.test.ts.snap
··· 181 181 ] 182 182 `; 183 183 184 + exports[`note (isCI = false) > without guide 1`] = ` 185 + [ 186 + "◇ title ───╮ 187 + │ │ 188 + │ message │ 189 + │ │ 190 + ╰───────────╯ 191 + ", 192 + ] 193 + `; 194 + 184 195 exports[`note (isCI = true) > don't overflow 1`] = ` 185 196 [ 186 197 "│ ··· 361 372 ", 362 373 ] 363 374 `; 375 + 376 + exports[`note (isCI = true) > without guide 1`] = ` 377 + [ 378 + "◇ title ───╮ 379 + │ │ 380 + │ message │ 381 + │ │ 382 + ╰───────────╯ 383 + ", 384 + ] 385 + `;
+10
packages/prompts/test/note.test.ts
··· 109 109 110 110 expect(output.buffer).toMatchSnapshot(); 111 111 }); 112 + 113 + test('without guide', () => { 114 + prompts.note('message', 'title', { 115 + input, 116 + output, 117 + withGuide: false, 118 + }); 119 + 120 + expect(output.buffer).toMatchSnapshot(); 121 + }); 112 122 });