Skip to content

Commit 2839c66

Browse files
hyperz11143081j
andauthored
fix(note): hard wrap (#383)
Co-authored-by: James Garbutt <43081j@users.noreply.github.com>
1 parent 09e596c commit 2839c66

File tree

3 files changed

+124
-115
lines changed

3 files changed

+124
-115
lines changed

.changeset/great-lies-dance.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+
fix(note): hard wrap text to column limit

packages/prompts/src/note.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import process from 'node:process';
22
import type { Writable } from 'node:stream';
33
import { stripVTControlCharacters as strip } from 'node:util';
44
import { getColumns } from '@clack/core';
5-
import { wrapAnsi } from 'fast-wrap-ansi';
5+
import { type Options as WrapAnsiOptions, wrapAnsi } from 'fast-wrap-ansi';
66
import color from 'picocolors';
77
import {
88
type CommonOptions,
@@ -22,13 +22,17 @@ export interface NoteOptions extends CommonOptions {
2222
const defaultNoteFormatter = (line: string): string => color.dim(line);
2323

2424
const wrapWithFormat = (message: string, width: number, format: FormatFn): string => {
25-
const wrapMsg = wrapAnsi(message, width).split('\n');
25+
const opts: WrapAnsiOptions = {
26+
hard: true,
27+
trim: false,
28+
};
29+
const wrapMsg = wrapAnsi(message, width, opts).split('\n');
2630
const maxWidthNormal = wrapMsg.reduce((sum, ln) => Math.max(strip(ln).length, sum), 0);
2731
const maxWidthFormat = wrapMsg
2832
.map(format)
2933
.reduce((sum, ln) => Math.max(strip(ln).length, sum), 0);
3034
const wrapWidth = width - (maxWidthFormat - maxWidthNormal);
31-
return wrapAnsi(message, wrapWidth);
35+
return wrapAnsi(message, wrapWidth, opts);
3236
};
3337

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

0 commit comments

Comments
 (0)