diff --git a/packages/prompts/src/note.ts b/packages/prompts/src/note.ts index 13e8229..2d6e2b5 100644 --- a/packages/prompts/src/note.ts +++ b/packages/prompts/src/note.ts @@ -1,5 +1,7 @@ +import process from 'node:process'; import type { Writable } from 'node:stream'; import { stripVTControlCharacters as strip } from 'node:util'; +import { wrapAnsi } from 'fast-wrap-ansi'; import color from 'picocolors'; import { type CommonOptions, @@ -10,8 +12,6 @@ import { S_CORNER_TOP_RIGHT, S_STEP_SUBMIT, } from './common.js'; -import { wrapAnsi } from "fast-wrap-ansi"; -import process from "node:process"; export interface NoteOptions extends CommonOptions { format?: (line: string) => string; @@ -19,13 +19,15 @@ export interface NoteOptions extends CommonOptions { const defaultNoteFormatter = (line: string): string => color.dim(line); -const wrapWithFormat = (message: string, width: number, format: NoteOptions["format"]): string => { - const wrapMsg = wrapAnsi(message, width).split("\n"); +const wrapWithFormat = (message: string, width: number, format: NoteOptions['format']): string => { + const wrapMsg = wrapAnsi(message, width).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 maxWidthFormat = wrapMsg + .map(format) + .reduce((sum, ln) => Math.max(strip(ln).length, sum), 0); const wrapWidth = width - (maxWidthFormat - maxWidthNormal); return wrapAnsi(message, wrapWidth); -} +}; export const note = (message = '', title = '', opts?: NoteOptions) => { const output: Writable = opts?.output ?? process.stdout; diff --git a/packages/prompts/test/note.test.ts b/packages/prompts/test/note.test.ts index acb5f4b..d68cbad 100644 --- a/packages/prompts/test/note.test.ts +++ b/packages/prompts/test/note.test.ts @@ -64,8 +64,8 @@ describe.each(['true', 'false'])('note (isCI = %s)', (isCI) => { expect(output.buffer).toMatchSnapshot(); }); - test('don\'t overflow', () => { - const input = `${'test string '.repeat(32)}\n`.repeat(4).trim(); + test("don't overflow", () => { + const input = `${'test string '.repeat(32)}\n`.repeat(4).trim(); prompts.note(input, 'title', { input, output: Object.assign(output, { columns: 75 }), @@ -74,10 +74,10 @@ describe.each(['true', 'false'])('note (isCI = %s)', (isCI) => { expect(output.buffer).toMatchSnapshot(); }); - test('don\'t overflow with formatter', () => { - const input = `${'test string '.repeat(32)}\n`.repeat(4).trim(); + test("don't overflow with formatter", () => { + const input = `${'test string '.repeat(32)}\n`.repeat(4).trim(); prompts.note(input, 'title', { - format: (line) => colors.red(`* ${colors.cyan(line)} *`), + format: (line) => colors.red(`* ${colors.cyan(line)} *`), input, output: Object.assign(output, { columns: 75 }), });