Skip to content

Allow dismissing the default value to submit an empty input#380

Merged
shibayan merged 2 commits into
masterfrom
feature/dismissable-default-value
Jul 5, 2026
Merged

Allow dismissing the default value to submit an empty input#380
shibayan merged 2 commits into
masterfrom
feature/dismissable-default-value

Conversation

@shibayan

@shibayan shibayan commented Jul 5, 2026

Copy link
Copy Markdown
Owner

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/input prefill: 'tab' and terkelg/prompts both use it):

  • Tab inserts the default value into the input buffer for editing
  • Backspace with nothing typed dismisses the default value (the hint disappears); pressing Enter afterwards submits an empty value, subject to the usual non-nullable check and validators

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 (DefaultValue short-circuits before AllowEmpty), 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

  • 4 new interaction tests: Tab inserts default for editing (blue + berryblueberry), 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 types
  • Full suite: 334 passed, dotnet format clean
  • README updated with the key behavior

🤖 Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings July 5, 2026 13:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/Sharprompt/Forms/InputForm.cs
Comment thread src/Sharprompt/Forms/InputForm.cs Outdated
Comment thread README.md Outdated
@shibayan shibayan self-assigned this Jul 5, 2026
@shibayan shibayan added the enhancement New feature or request label Jul 5, 2026
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>
@shibayan shibayan merged commit bc79912 into master Jul 5, 2026
5 checks passed
@shibayan shibayan deleted the feature/dismissable-default-value branch July 5, 2026 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

How to reset the default value to an empty string

2 participants