fix: respect withGuide option in password and path prompts#460
fix: respect withGuide option in password and path prompts#460kaigritun wants to merge 6 commits intobombshell-dev:mainfrom
Conversation
When withGuide: false, password and path (autocomplete) prompts had incorrect leading whitespace in: - User input text - Validation error messages This commit: - password.ts: Makes indent spacing conditional on hasGuide - autocomplete.ts: Adds full withGuide support using settings import Fixes bombshell-dev#458
🦋 Changeset detectedLatest commit: 4990757 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
packages/prompts/src/autocomplete.ts
Outdated
| const options = this.options; | ||
| const placeholder = opts.placeholder; | ||
| const showPlaceholder = userInput === '' && placeholder !== undefined; | ||
| const indent = hasGuide ? ' ' : ''; |
There was a problem hiding this comment.
we shouldn't need this. all other prompts include the indent in the prefix (as it is part of the prefix).
it should be more like:
const label = selected.length > 0 ? color.dim(selected.map(getLabel).join(', ')) : '';
const submitPrefix = hasGuide ? `${color.gray(S_BAR)} ` : '';
return `${headings.join('\n')}\n${submitPrefix}${label}`;Move the indent spacing into the prefix for error/submit/cancel cases in password prompt, matching the pattern used by other prompts. Updated snapshots accordingly.
|
Updated to include the indent in the prefix as suggested. All tests passing with updated snapshots. |
packages/prompts/src/autocomplete.ts
Outdated
| ]; | ||
| const footers = hasGuide | ||
| ? [ | ||
| `${guidePrefix}${color.dim(instructions.join(' • '))}`, |
There was a problem hiding this comment.
the guidePrefix is already empty if it has no guide, so can this be simplified:
const footers = [
`${guidePrefix}${color.dim(instructions.join(' • '))}`,
guidePrefixEnd
`;| "<erase.down>", | ||
| "[32m◇[39m Select a fruit | ||
| [90m│[39m", | ||
| [90m│[39m ", |
|
Fixed both issues:
All tests passing with updated snapshots. |
|
Fixed the trailing spaces issue - moved the indent back into the label/userInputText rather than the prefix, so there are no trailing spaces when the value is empty (e.g., cancel without typing anything). Snapshots updated. |
Summary
When
withGuide: falseis set, thepasswordandpathprompts incorrectly included leading whitespace in:Changes
packages/prompts/src/password.tshasGuidein the error statehasGuide: false, no leading whitespace is added to masked text or error messagepackages/prompts/src/autocomplete.ts(used bypath)settingsfrom@clack/corehasGuidecheck usingopts.withGuide ?? settings.withGuidehasGuidecolumnPaddingfor options based on guide presenceTesting
All 579 tests pass (
pnpm build && pnpm test).Fixes #458