diff --git a/packages/prompts/src/box.ts b/packages/prompts/src/box.ts index 398f746..060ada1 100644 --- a/packages/prompts/src/box.ts +++ b/packages/prompts/src/box.ts @@ -1,5 +1,6 @@ import type { Writable } from 'node:stream'; import { getColumns } from '@clack/core'; +import stringWidth from 'fast-string-width'; import { wrapAnsi } from 'fast-wrap-ansi'; import { type CommonOptions, @@ -14,7 +15,6 @@ import { S_CORNER_TOP_LEFT, S_CORNER_TOP_RIGHT, } from './common.js'; -import stringWidth from "fast-string-width"; export type BoxAlignment = 'left' | 'center' | 'right'; diff --git a/packages/prompts/src/note.ts b/packages/prompts/src/note.ts index 6b07055..bd80d07 100644 --- a/packages/prompts/src/note.ts +++ b/packages/prompts/src/note.ts @@ -1,6 +1,7 @@ import process from 'node:process'; import type { Writable } from 'node:stream'; import { getColumns } from '@clack/core'; +import stringWidth from 'fast-string-width'; import { type Options as WrapAnsiOptions, wrapAnsi } from 'fast-wrap-ansi'; import color from 'picocolors'; import { @@ -12,7 +13,6 @@ import { S_CORNER_TOP_RIGHT, S_STEP_SUBMIT, } from './common.js'; -import stringWidth from "fast-string-width"; type FormatFn = (line: string) => string; export interface NoteOptions extends CommonOptions { @@ -28,9 +28,7 @@ const wrapWithFormat = (message: string, width: number, format: FormatFn): strin }; const wrapMsg = wrapAnsi(message, width, opts).split('\n'); const maxWidthNormal = wrapMsg.reduce((sum, ln) => Math.max(stringWidth(ln), sum), 0); - const maxWidthFormat = wrapMsg - .map(format) - .reduce((sum, ln) => Math.max(stringWidth(ln), sum), 0); + const maxWidthFormat = wrapMsg.map(format).reduce((sum, ln) => Math.max(stringWidth(ln), sum), 0); const wrapWidth = width - (maxWidthFormat - maxWidthNormal); return wrapAnsi(message, wrapWidth, opts); }; diff --git a/packages/prompts/test/box.test.ts b/packages/prompts/test/box.test.ts index 8c9a224..3110598 100644 --- a/packages/prompts/test/box.test.ts +++ b/packages/prompts/test/box.test.ts @@ -236,11 +236,8 @@ describe.each(['true', 'false'])('box (isCI = %s)', (isCI) => { }); test('renders wide characters with auto width', () => { - const messages = [ - '이게 첫 번째 줄이에요', - 'これは次の行です', - ]; - prompts.box(messages.join("\n"), '这是标题', { + const messages = ['이게 첫 번째 줄이에요', 'これは次の行です']; + prompts.box(messages.join('\n'), '这是标题', { input, output, width: 'auto', @@ -250,11 +247,8 @@ describe.each(['true', 'false'])('box (isCI = %s)', (isCI) => { }); test('renders wide characters with specified width', () => { - const messages = [ - '이게 첫 번째 줄이에요', - 'これは次の行です', - ]; - prompts.box(messages.join("\n"), '这是标题', { + const messages = ['이게 첫 번째 줄이에요', 'これは次の行です']; + prompts.box(messages.join('\n'), '这是标题', { input, output, width: 0.2, diff --git a/packages/prompts/test/note.test.ts b/packages/prompts/test/note.test.ts index 775b29d..ac0df4f 100644 --- a/packages/prompts/test/note.test.ts +++ b/packages/prompts/test/note.test.ts @@ -87,13 +87,10 @@ describe.each(['true', 'false'])('note (isCI = %s)', (isCI) => { expect(output.buffer).toMatchSnapshot(); }); - test("handle wide characters", () => { - const messages = [ - '이게 첫 번째 줄이에요', - 'これは次の行です', - ]; + test('handle wide characters', () => { + const messages = ['이게 첫 번째 줄이에요', 'これは次の行です']; output.columns = 10; - prompts.note(messages.join("\n"), '这是标题', { + prompts.note(messages.join('\n'), '这是标题', { input, output, }); @@ -101,13 +98,10 @@ describe.each(['true', 'false'])('note (isCI = %s)', (isCI) => { expect(output.buffer).toMatchSnapshot(); }); - test("handle wide characters with formatter", () => { - const messages = [ - '이게 첫 번째 줄이에요', - 'これは次の行です', - ]; + test('handle wide characters with formatter', () => { + const messages = ['이게 첫 번째 줄이에요', 'これは次の行です']; output.columns = 10; - prompts.note(messages.join("\n"), '这是标题', { + prompts.note(messages.join('\n'), '这是标题', { format: (line) => colors.red(`* ${colors.cyan(line)} *`), input, output,