Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/chatty-islands-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@clack/prompts": patch
---

Add withGuide support to note prompt
10 changes: 7 additions & 3 deletions packages/prompts/src/note.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
Expand All @@ -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), ''];
Expand All @@ -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`
);
};
22 changes: 22 additions & 0 deletions packages/prompts/test/__snapshots__/note.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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`] = `
[
"│
Expand Down Expand Up @@ -361,3 +372,14 @@ exports[`note (isCI = true) > renders message with title 1`] = `
",
]
`;

exports[`note (isCI = true) > without guide 1`] = `
[
"◇ title ───╮
│ │
│ message │
│ │
╰───────────╯
",
]
`;
10 changes: 10 additions & 0 deletions packages/prompts/test/note.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Loading