From 7f40da2577b65250d0d7fbad2ddbfd20aed1ccb7 Mon Sep 17 00:00:00 2001 From: James Garbutt <43081j@users.noreply.github.com> Date: Sun, 6 Sep 2026 13:35:15 +0100 Subject: [PATCH] fix: output submit gap only when guide enabled In the text prompt, we output a `" "` prefix to align the submitted value with the guide. When the guide is disabled, this was leaving is with an unnecessary gap. This fix removes that gap. Fixes #598. --- .changeset/hungry-rice-film.md | 5 ++++ packages/core/test/prompts/prompt.test.ts | 1 + packages/prompts/src/text.ts | 2 +- .../test/__snapshots__/text.test.ts.snap | 28 ++++++++++++++++--- packages/prompts/test/text.test.ts | 2 ++ 5 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 .changeset/hungry-rice-film.md diff --git a/.changeset/hungry-rice-film.md b/.changeset/hungry-rice-film.md new file mode 100644 index 00000000..4fa6f7e8 --- /dev/null +++ b/.changeset/hungry-rice-film.md @@ -0,0 +1,5 @@ +--- +"@clack/prompts": patch +--- + +Fixes a withGuide rendering issue leaving extra spaces in text prompts. diff --git a/packages/core/test/prompts/prompt.test.ts b/packages/core/test/prompts/prompt.test.ts index 9aa5bd69..50c1ccda 100644 --- a/packages/core/test/prompts/prompt.test.ts +++ b/packages/core/test/prompts/prompt.test.ts @@ -467,6 +467,7 @@ describe('Prompt', () => { expect(eventSpy).not.toHaveBeenCalled(); expect(instance.state).to.equal('validating'); + // biome-ignore lint/style/noNonNullAssertion: We know resolveValidation is defined resolveValidation!(undefined); await resultPromise; diff --git a/packages/prompts/src/text.ts b/packages/prompts/src/text.ts index 66e5596b..5e958eb3 100644 --- a/packages/prompts/src/text.ts +++ b/packages/prompts/src/text.ts @@ -91,7 +91,7 @@ export const text = (opts: TextOptions) => { return `${title.trim()}\n${errorPrefix}${userInput}\n${errorPrefixEnd}${errorText}\n`; } case 'submit': { - const valueText = value ? ` ${styleText('dim', value)}` : ''; + const valueText = value ? `${hasGuide ? ' ' : ''}${styleText('dim', value)}` : ''; const submitPrefix = hasGuide ? styleText('gray', S_BAR) : ''; return `${title}${submitPrefix}${valueText}`; } diff --git a/packages/prompts/test/__snapshots__/text.test.ts.snap b/packages/prompts/test/__snapshots__/text.test.ts.snap index bed7f5a3..8ce07d82 100644 --- a/packages/prompts/test/__snapshots__/text.test.ts.snap +++ b/packages/prompts/test/__snapshots__/text.test.ts.snap @@ -130,10 +130,15 @@ exports[`text (isCI = false) > global withGuide: false removes guide 1`] = ` _ ", + "", + "", + "", + "x█", + "", "", "", "◇ foo -", +x", " ", "", @@ -339,10 +344,15 @@ exports[`text (isCI = false) > withGuide: false removes guide 1`] = ` _ ", + "", + "", + "", + "x█", + "", "", "", "◇ foo -", +x", " ", "", @@ -479,10 +489,15 @@ exports[`text (isCI = true) > global withGuide: false removes guide 1`] = ` _ ", + "", + "", + "", + "x█", + "", "", "", "◇ foo -", +x", " ", "", @@ -688,10 +703,15 @@ exports[`text (isCI = true) > withGuide: false removes guide 1`] = ` _ ", + "", + "", + "", + "x█", + "", "", "", "◇ foo -", +x", " ", "", diff --git a/packages/prompts/test/text.test.ts b/packages/prompts/test/text.test.ts index 0e534255..dc8e4f62 100644 --- a/packages/prompts/test/text.test.ts +++ b/packages/prompts/test/text.test.ts @@ -216,6 +216,7 @@ describe.each(['true', 'false'])('text (isCI = %s)', (isCI) => { output, }); + input.emit('keypress', 'x', { name: 'x' }); input.emit('keypress', '', { name: 'return' }); await result; @@ -232,6 +233,7 @@ describe.each(['true', 'false'])('text (isCI = %s)', (isCI) => { output, }); + input.emit('keypress', 'x', { name: 'x' }); input.emit('keypress', '', { name: 'return' }); await result;