diff --git a/.changeset/chatty-islands-move.md b/.changeset/chatty-islands-move.md new file mode 100644 index 00000000..bd7e1ac9 --- /dev/null +++ b/.changeset/chatty-islands-move.md @@ -0,0 +1,5 @@ +--- +"@clack/prompts": patch +--- + +Add withGuide support to note prompt diff --git a/packages/prompts/src/note.ts b/packages/prompts/src/note.ts index bd80d07b..75e3c766 100644 --- a/packages/prompts/src/note.ts +++ b/packages/prompts/src/note.ts @@ -1,6 +1,6 @@ import process from 'node:process'; import type { Writable } from 'node:stream'; -import { getColumns } from '@clack/core'; +import { getColumns, settings } from '@clack/core'; import stringWidth from 'fast-string-width'; import { type Options as WrapAnsiOptions, wrapAnsi } from 'fast-wrap-ansi'; import color from 'picocolors'; @@ -9,6 +9,7 @@ import { S_BAR, S_BAR_H, S_CONNECT_LEFT, + S_CORNER_BOTTOM_LEFT, S_CORNER_BOTTOM_RIGHT, S_CORNER_TOP_RIGHT, S_STEP_SUBMIT, @@ -35,6 +36,7 @@ const wrapWithFormat = (message: string, width: number, format: FormatFn): strin export const note = (message = '', title = '', opts?: NoteOptions) => { const output: Writable = opts?.output ?? process.stdout; + const hasGuide = (opts?.withGuide ?? settings.withGuide) !== false; const format = opts?.format ?? defaultNoteFormatter; const wrapMsg = wrapWithFormat(message, getColumns(output) - 6, format); const lines = ['', ...wrapMsg.split('\n').map(format), '']; @@ -52,9 +54,11 @@ export const note = (message = '', title = '', opts?: NoteOptions) => { (ln) => `${color.gray(S_BAR)} ${ln}${' '.repeat(len - stringWidth(ln))}${color.gray(S_BAR)}` ) .join('\n'); + const leadingBorder = hasGuide ? `${color.gray(S_BAR)}\n` : ''; + const bottomLeft = hasGuide ? S_CONNECT_LEFT : S_CORNER_BOTTOM_LEFT; output.write( - `${color.gray(S_BAR)}\n${color.green(S_STEP_SUBMIT)} ${color.reset(title)} ${color.gray( + `${leadingBorder}${color.green(S_STEP_SUBMIT)} ${color.reset(title)} ${color.gray( S_BAR_H.repeat(Math.max(len - titleLen - 1, 1)) + S_CORNER_TOP_RIGHT - )}\n${msg}\n${color.gray(S_CONNECT_LEFT + S_BAR_H.repeat(len + 2) + S_CORNER_BOTTOM_RIGHT)}\n` + )}\n${msg}\n${color.gray(bottomLeft + S_BAR_H.repeat(len + 2) + S_CORNER_BOTTOM_RIGHT)}\n` ); }; diff --git a/packages/prompts/test/__snapshots__/note.test.ts.snap b/packages/prompts/test/__snapshots__/note.test.ts.snap index ccb42566..032d05c1 100644 --- a/packages/prompts/test/__snapshots__/note.test.ts.snap +++ b/packages/prompts/test/__snapshots__/note.test.ts.snap @@ -181,6 +181,17 @@ exports[`note (isCI = false) > renders message with title 1`] = ` ] `; +exports[`note (isCI = false) > without guide 1`] = ` +[ + "◇ title ───╮ +│ │ +│ message │ +│ │ +╰───────────╯ +", +] +`; + exports[`note (isCI = true) > don't overflow 1`] = ` [ "│ @@ -361,3 +372,14 @@ exports[`note (isCI = true) > renders message with title 1`] = ` ", ] `; + +exports[`note (isCI = true) > without guide 1`] = ` +[ + "◇ title ───╮ +│ │ +│ message │ +│ │ +╰───────────╯ +", +] +`; diff --git a/packages/prompts/test/note.test.ts b/packages/prompts/test/note.test.ts index ac0df4fe..4d4c0775 100644 --- a/packages/prompts/test/note.test.ts +++ b/packages/prompts/test/note.test.ts @@ -109,4 +109,14 @@ describe.each(['true', 'false'])('note (isCI = %s)', (isCI) => { expect(output.buffer).toMatchSnapshot(); }); + + test('without guide', () => { + prompts.note('message', 'title', { + input, + output, + withGuide: false, + }); + + expect(output.buffer).toMatchSnapshot(); + }); });