Skip to content

Commit 6176ced

Browse files
authored
feat: add withGuide support to note prompt (#418)
1 parent 69681ea commit 6176ced

File tree

4 files changed

+44
-3
lines changed

4 files changed

+44
-3
lines changed

.changeset/chatty-islands-move.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@clack/prompts": patch
3+
---
4+
5+
Add withGuide support to note prompt

packages/prompts/src/note.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import process from 'node:process';
22
import type { Writable } from 'node:stream';
3-
import { getColumns } from '@clack/core';
3+
import { getColumns, settings } from '@clack/core';
44
import stringWidth from 'fast-string-width';
55
import { type Options as WrapAnsiOptions, wrapAnsi } from 'fast-wrap-ansi';
66
import color from 'picocolors';
@@ -9,6 +9,7 @@ import {
99
S_BAR,
1010
S_BAR_H,
1111
S_CONNECT_LEFT,
12+
S_CORNER_BOTTOM_LEFT,
1213
S_CORNER_BOTTOM_RIGHT,
1314
S_CORNER_TOP_RIGHT,
1415
S_STEP_SUBMIT,
@@ -35,6 +36,7 @@ const wrapWithFormat = (message: string, width: number, format: FormatFn): strin
3536

3637
export const note = (message = '', title = '', opts?: NoteOptions) => {
3738
const output: Writable = opts?.output ?? process.stdout;
39+
const hasGuide = (opts?.withGuide ?? settings.withGuide) !== false;
3840
const format = opts?.format ?? defaultNoteFormatter;
3941
const wrapMsg = wrapWithFormat(message, getColumns(output) - 6, format);
4042
const lines = ['', ...wrapMsg.split('\n').map(format), ''];
@@ -52,9 +54,11 @@ export const note = (message = '', title = '', opts?: NoteOptions) => {
5254
(ln) => `${color.gray(S_BAR)} ${ln}${' '.repeat(len - stringWidth(ln))}${color.gray(S_BAR)}`
5355
)
5456
.join('\n');
57+
const leadingBorder = hasGuide ? `${color.gray(S_BAR)}\n` : '';
58+
const bottomLeft = hasGuide ? S_CONNECT_LEFT : S_CORNER_BOTTOM_LEFT;
5559
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(
5761
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`
5963
);
6064
};

packages/prompts/test/__snapshots__/note.test.ts.snap

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,17 @@ exports[`note (isCI = false) > renders message with title 1`] = `
181181
]
182182
`;
183183

184+
exports[`note (isCI = false) > without guide 1`] = `
185+
[
186+
"◇ title ───╮
187+
│ │
188+
│ message │
189+
│ │
190+
╰───────────╯
191+
",
192+
]
193+
`;
194+
184195
exports[`note (isCI = true) > don't overflow 1`] = `
185196
[
186197
"│
@@ -361,3 +372,14 @@ exports[`note (isCI = true) > renders message with title 1`] = `
361372
",
362373
]
363374
`;
375+
376+
exports[`note (isCI = true) > without guide 1`] = `
377+
[
378+
"◇ title ───╮
379+
│ │
380+
│ message │
381+
│ │
382+
╰───────────╯
383+
",
384+
]
385+
`;

packages/prompts/test/note.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,14 @@ describe.each(['true', 'false'])('note (isCI = %s)', (isCI) => {
109109

110110
expect(output.buffer).toMatchSnapshot();
111111
});
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+
});
112122
});

0 commit comments

Comments
 (0)