Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix: resolve default value and placeholder collision in InputForm (#192)
Fixes #192
Summary
InputForm<T>renderedDefaultValueandPlaceholderindependently, so configuring both produced two adjacent hints with no separator and the sameHintcolor:The placeholder looked like editable text following the default, and it was unclear which value Enter would submit.
This change makes the two hints mutually exclusive: while a default value is active, the default hint wins and the placeholder is not drawn. The placeholder is revealed only after the default is dismissed.
Behavior
DefaultValue = "blue",Placeholder = "type a color"? Pick a color: (blue) ▏"blue"[Backspace]on the empty buffer? Pick a color: ▏type a colornull(string) / validation error (non-nullable)Placeholderonly? Pick a color: ▏type a colorDefaultValueonly? Pick a color: (blue) ▏"blue"No public API changes. The placeholder remains non-submittable, and
DefaultValueremains the value used by Enter/Tab.Before / After
Before — both hints drawn, no separation:
After — default suppresses the placeholder:
After —
[Backspace]dismisses the default and reveals the placeholder:Implementation
src/Sharprompt/Forms/InputForm.cs— the placeholder branch inInputTemplate()becomes anelse ifof the default-value branch:This relies on the existing
HandleBackspace()behavior, which already clears_defaultValuewhen Backspace is pressed on an empty buffer.Tests
Added three tests in
tests/Sharprompt.Tests/Forms/FormInteractionTests.cs:InputForm_DefaultValueAndPlaceholder_RendersDefaultOnly— asserts(blue)is rendered and the placeholder is absent.InputForm_BackspaceDismissesDefaultValue_RevealsPlaceholder— asserts the post-backspace frame contains the placeholder and no longer the default.InputForm_EmptyInputWithDefaultValueAndPlaceholder_ReturnsDefaultValue— asserts Enter on an empty buffer resolves to the default value.Verification
dotnet format --verify-no-changesreports no formatting changes. Bothnet8.0andnet10.0targets build successfully.Compatibility
DefaultValuebehave exactly as before.