Skip to content

Text prompt editable default#2016

Merged
patriksvensson merged 8 commits intospectreconsole:mainfrom
MapelSiroup:text-prompt-editable-default
Mar 11, 2026
Merged

Text prompt editable default#2016
patriksvensson merged 8 commits intospectreconsole:mainfrom
MapelSiroup:text-prompt-editable-default

Conversation

@MapelSiroup
Copy link
Copy Markdown
Contributor

@MapelSiroup MapelSiroup commented Feb 17, 2026

fixes #

  • I have read the Contribution Guidelines
  • I have commented on the issue above and discussed the intended changes my proposal for #595
  • A maintainer has signed off on the changes and the issue was assigned to me
  • All newly added code is adequately covered by tests
  • All existing tests are still running without errors
  • The documentation was modified to reflect the changes OR no documentation changes are required.

Changes

This PR allows the insertion of the default value inside text field/input buffer making it editable and already available instead of the current DefaultValue behavior to simply set the text variable with the default when empty.

  1. TextPrompt.cs: Added a bool DefaultInput { get; set; } property and, when showing the prompt, if enabled the default value is placed into the editable input field.

  2. TextPromptExtensions.cs: Added matching extension DefaultInput<T>(this TextPrompt<T> obj, bool state) to enable/disable the editable default behavior when creating TextPrompts.

  3. AnsiConsoleExtensions.Input.cs: Added a new ReadLine() overload that accepts an initialInput (string?) and enqueues a ConsoleKeyInfo per character. The overload consumes those queued key events first, then falls back to console.Input.ReadKeyAsync().

  4. TextPromptTests.cs: Added a unit test Should_Return_Error_If_Default_Choice_Invalid that checks the default input system (Testing the validity checks whether the input matches a valid choice in the list).

Affected files:

  • src/Spectre.Console/Prompts/TextPrompt.cs
  • src/Spectre.Console/Prompts/TextPromptExtensions.cs
  • src/Spectre.Console/Extensions/AnsiConsoleExtensions.Input.cs
  • src/Spectre.Console.Tests/Unit/Prompts/TextPromptTests.cs
  • src/Spectre.Console.Tests/Expectations/Prompts/Text/InvalidDefaultChoice.Output.verified.txt

Please upvote 👍 this pull request if you are interested in it.

@MapelSiroup
Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

@patriksvensson
Copy link
Copy Markdown
Contributor

@MapelSiroup PR is failing to build

@MapelSiroup
Copy link
Copy Markdown
Contributor Author

@MapelSiroup PR is failing to build

Should be good now, i hadn't noticed the failed build 👍

@patriksvensson
Copy link
Copy Markdown
Contributor

@MapelSiroup Seems to be a merge conflict now that needs to be resolved

@patriksvensson patriksvensson merged commit 5369ef9 into spectreconsole:main Mar 11, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants