Allow dismissing the default value to submit an empty input#380
Merged
Conversation
Adopt the Inquirer-style default value interaction in InputForm: - Tab inserts the default value into the input buffer for editing - Backspace with nothing typed dismisses the default value, so pressing Enter afterwards submits an empty value (subject to the usual nullability check and validators) Both keys previously just beeped in these states, so existing behavior (Enter on empty input accepts the default) is unchanged. Fixes #297 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Enables an Inquirer-style interaction in Prompt.Input<T>/InputForm<T> so users can edit or dismiss a provided default value, allowing empty submissions when appropriate (notably solving the “can’t return empty if default exists” limitation from #297).
Changes:
- Adds Tab handling to insert the default value into the input buffer for editing.
- Adds Backspace handling on an empty buffer to dismiss the default value.
- Adds interaction tests for the new key behaviors and updates the README to document them.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| tests/Sharprompt.Tests/Forms/FormInteractionTests.cs | Adds interaction tests covering Tab insertion and Backspace dismissal behaviors. |
| src/Sharprompt/Forms/InputForm.cs | Implements Tab insertion and Backspace dismissal by managing _defaultValue vs. the input buffer. |
| README.md | Documents the new Tab/Backspace interaction when a default value is present. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ToString is culture-sensitive while HandleEnter parses input with ConvertFromInvariantString, so Tab-then-Enter could fail to round-trip (e.g. 1.5 becomes "1,5" under de-DE). Add TypeHelper<T>.ConvertToString using ConvertToInvariantString and use it for the inserted text. Also clarify the dismissal comment and README wording: non-nullable types still require input after the default is dismissed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Summary
Resolves the long-standing limitation that
Prompt.Input<T>with a default value could never return an empty result — Enter on empty input always returned the default (#297).This adopts the Inquirer-compatible interaction (the de-facto standard across prompt libraries —
@inquirer/inputprefill: 'tab'and terkelg/prompts both use it):No new API is introduced, and the default behavior is fully preserved: Enter on empty input still accepts the default. Both keys previously just beeped in these states, so this is effectively non-breaking.
For reference, Spectre.Console has the same limitation unresolved (
DefaultValueshort-circuits beforeAllowEmpty), and the stale external PR #300 proposed the same Tab interaction behind an opt-in flag — this implementation makes the flag unnecessary.Fixes #297
Closes #300
Test plan
blue+berry→blueberry), Tab with typed text is a no-op, Backspace dismisses the default (empty submission returns null), dismissed default still enforces required input for non-nullable typesdotnet formatclean🤖 Generated with Claude Code