[dotnet watch] Fix target framework selector being stuck#53675
Merged
jonathanpeppers merged 1 commit intorelease/10.0.3xxfrom Apr 2, 2026
Merged
[dotnet watch] Fix target framework selector being stuck#53675jonathanpeppers merged 1 commit intorelease/10.0.3xxfrom
jonathanpeppers merged 1 commit intorelease/10.0.3xxfrom
Conversation
PhysicalConsole runs Console.ReadKey() in a tight background loop, consuming all key presses and dispatching them via the KeyPressed event. When SpectreBuildParametersSelectionPrompt returned AnsiConsole.Console for non-redirected stdin, Spectre.Console would also call Console.ReadKey() internally, creating a race where PhysicalConsole steals every key press and the selection prompt appears completely stuck (arrow keys, typing, and search all do nothing). Fix by always using KeyPressedAnsiConsole, which reads keys from PhysicalConsole.KeyPressed events instead of competing for Console.ReadKey(). This ensures a single key reader (PhysicalConsole) distributes keys to all consumers including Spectre.Console. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
tmat
approved these changes
Apr 2, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes dotnet watch interactive selection prompts (target framework / device) becoming unresponsive by ensuring Spectre.Console reads keystrokes via PhysicalConsole’s KeyPressed event stream rather than competing with a second Console.ReadKey() loop.
Changes:
- Removes the conditional that returned
AnsiConsole.Consolewhen stdin isn’t redirected. - Always constructs a Spectre console wrapper (
KeyPressedAnsiConsole) that sources input fromIConsole.KeyPressed.
Comments suppressed due to low confidence (1)
src/Dotnet.Watch/dotnet-watch/UI/SpectreBuildParametersSelectionPrompt.cs:88
- CreateConsole now forces
AnsiSupport.Yesand setsProfile.Capabilities.Ansi/Interactive = truefor all runs. That bypasses Spectre.Console’s normal capability detection (e.g., output redirection / NO_COLOR / terminals without ANSI), and can lead to escape sequences or interactive prompting in contexts where the defaultAnsiConsole.Consolewould correctly downgrade. Consider keeping auto-detection for ANSI/output and only swapping the input source (wrapAnsiConsole.Consoleand overrideInput, and only forceInteractivewhen you specifically need to override redirected-stdin behavior).
var ansiConsole = AnsiConsole.Create(new AnsiConsoleSettings
{
Ansi = AnsiSupport.Yes,
Interactive = InteractionSupport.Yes,
});
ansiConsole.Profile.Capabilities.Interactive = true;
ansiConsole.Profile.Capabilities.Ansi = true;
return new KeyPressedAnsiConsole(ansiConsole, watchConsole);
54 tasks
jonathanpeppers
added a commit
that referenced
this pull request
Apr 27, 2026
Testing `dotnet-watch` end-to end on a `dotnet new maui` project... I found the Spectre.Console input was just "stuck", neither up/down arrows or typing to search did anything! `PhysicalConsole` runs `Console.ReadKey()` in a tight background loop, consuming all key presses and dispatching them via the `KeyPressed` event. When `SpectreBuildParametersSelectionPrompt` returned `AnsiConsole.Console` for non-redirected stdin, Spectre.Console would also call `Console.ReadKey()` internally, creating a race where `PhysicalConsole` steals every key press and the selection prompt appears completely stuck (arrow keys, typing, and search all do nothing). Fix by always using `KeyPressedAnsiConsole`, which reads keys from `PhysicalConsole.KeyPressed` events instead of competing for `Console.ReadKey()`. This ensures a single key reader (`PhysicalConsole`) distributes keys to all consumers including Spectre.Console. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
22 tasks
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.
Testing
dotnet-watchend-to end on adotnet new mauiproject:I found the Spectre.Console input was just "stuck", neither up/down arrows or typing to search did anything!
PhysicalConsolerunsConsole.ReadKey()in a tight background loop, consuming all key presses and dispatching them via theKeyPressedevent. WhenSpectreBuildParametersSelectionPromptreturnedAnsiConsole.Consolefor non-redirected stdin, Spectre.Console would also callConsole.ReadKey()internally, creating a race wherePhysicalConsolesteals every key press and the selection prompt appears completely stuck (arrow keys, typing, and search all do nothing).Fix by always using
KeyPressedAnsiConsole, which reads keys fromPhysicalConsole.KeyPressedevents instead of competing forConsole.ReadKey(). This ensures a single key reader (PhysicalConsole) distributes keys to all consumers including Spectre.Console.