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/great-lies-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@clack/prompts": patch
---

fix(note): hard wrap text to column limit
10 changes: 7 additions & 3 deletions packages/prompts/src/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import process from 'node:process';
import type { Writable } from 'node:stream';
import { stripVTControlCharacters as strip } from 'node:util';
import { getColumns } from '@clack/core';
import { wrapAnsi } from 'fast-wrap-ansi';
import { type Options as WrapAnsiOptions, wrapAnsi } from 'fast-wrap-ansi';
import color from 'picocolors';
import {
type CommonOptions,
Expand All @@ -22,13 +22,17 @@ export interface NoteOptions extends CommonOptions {
const defaultNoteFormatter = (line: string): string => color.dim(line);

const wrapWithFormat = (message: string, width: number, format: FormatFn): string => {
const wrapMsg = wrapAnsi(message, width).split('\n');
const opts: WrapAnsiOptions = {
hard: true,
trim: false,
};
const wrapMsg = wrapAnsi(message, width, opts).split('\n');
const maxWidthNormal = wrapMsg.reduce((sum, ln) => Math.max(strip(ln).length, sum), 0);
const maxWidthFormat = wrapMsg
.map(format)
.reduce((sum, ln) => Math.max(strip(ln).length, sum), 0);
const wrapWidth = width - (maxWidthFormat - maxWidthNormal);
return wrapAnsi(message, wrapWidth);
return wrapAnsi(message, wrapWidth, opts);
};

export const note = (message = '', title = '', opts?: NoteOptions) => {
Expand Down
Loading
Loading