Skip to content

Add option to clear TextPrompt after input#1979

Merged
patriksvensson merged 4 commits intospectreconsole:mainfrom
ThePCJakub:feature/textprompt-clear-on-finish
Feb 25, 2026
Merged

Add option to clear TextPrompt after input#1979
patriksvensson merged 4 commits intospectreconsole:mainfrom
ThePCJakub:feature/textprompt-clear-on-finish

Conversation

@ThePCJakub
Copy link
Copy Markdown
Contributor

@ThePCJakub ThePCJakub commented Dec 10, 2025

fixes #1154

  • I have read the Contribution Guidelines
  • I have commented on the issue above and discussed the intended changes
  • 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

  • Add a ClearOnFinish property to TextPrompt<T> to optionally clear the prompt line after successful input.
  • Add a ClearOnFinish() fluent extension for easier configuration.
  • Clear the prompt line by emitting an ANSI clear-line sequence (ESC[2K) when ANSI is supported.
  • Add an expectation-based test (ClearOnFinish) to verify the output of TextPrompt<string> with ClearOnFinish() enabled.

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

@ThePCJakub
Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

@ThePCJakub ThePCJakub force-pushed the feature/textprompt-clear-on-finish branch 2 times, most recently from a3c87bb to e9c7e9c Compare February 22, 2026 23:47
@ThePCJakub ThePCJakub force-pushed the feature/textprompt-clear-on-finish branch from e9c7e9c to 11f9bf2 Compare February 22, 2026 23:49
@ThePCJakub
Copy link
Copy Markdown
Contributor Author

Rebased on top of main and applied suggestions.

@ThePCJakub
Copy link
Copy Markdown
Contributor Author

The feature has been tested on the example given in the issue #1979.

AnsiConsole.Prompt(
    new TextPrompt<string>("Please provide your ChatGPT API key?")
        .Secret()
        .ClearOnFinish()
);
AnsiConsole.MarkupLine("[green]API key stored successfully.[/]");

Output:

API key stored successfully.

@ThePCJakub ThePCJakub force-pushed the feature/textprompt-clear-on-finish branch from 5154636 to a62e28f Compare February 23, 2026 04:18
@patriksvensson patriksvensson merged commit c5859a4 into spectreconsole:main Feb 25, 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.

Add support for removing TextPrompt after text entry

2 participants