Skip to content

Commit f89f133

Browse files
authored
Handle Ctrl+R in non-interactive mode (#50822)
1 parent e9e8b0f commit f89f133

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

src/BuiltInTools/dotnet-watch/HotReload/HotReloadDotNetWatcher.cs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,18 @@ public async Task WatchAsync(CancellationToken shutdownCancellationToken)
4646
{
4747
CancellationTokenSource? forceRestartCancellationSource = null;
4848

49-
if (!_context.Options.NonInteractive)
50-
{
51-
_context.Logger.Log(MessageDescriptor.HotReloadEnabled);
52-
_context.Logger.Log(MessageDescriptor.PressCtrlRToRestart);
49+
_context.Logger.Log(MessageDescriptor.HotReloadEnabled);
50+
_context.Logger.Log(MessageDescriptor.PressCtrlRToRestart);
5351

54-
_console.KeyPressed += (key) =>
55-
{
56-
if (key.Modifiers.HasFlag(ConsoleModifiers.Control) && key.Key == ConsoleKey.R && forceRestartCancellationSource is { } source)
57-
{
58-
// provide immediate feedback to the user:
59-
_context.Logger.Log(source.IsCancellationRequested ? MessageDescriptor.RestartInProgress : MessageDescriptor.RestartRequested);
60-
source.Cancel();
61-
}
62-
};
63-
}
64-
else
52+
_console.KeyPressed += (key) =>
6553
{
66-
_context.Logger.Log(MessageDescriptor.HotReloadEnabled with { Severity = MessageSeverity.Verbose });
67-
}
54+
if (key.Modifiers.HasFlag(ConsoleModifiers.Control) && key.Key == ConsoleKey.R && forceRestartCancellationSource is { } source)
55+
{
56+
// provide immediate feedback to the user:
57+
_context.Logger.Log(source.IsCancellationRequested ? MessageDescriptor.RestartInProgress : MessageDescriptor.RestartRequested);
58+
source.Cancel();
59+
}
60+
};
6861

6962
using var fileWatcher = new FileWatcher(_context.Logger, _context.EnvironmentOptions);
7063

test/dotnet-watch.Tests/HotReload/ApplyDeltaTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,12 +838,13 @@ public async Task BlazorWasm_Restart()
838838
.WithSource();
839839

840840
var port = TestOptions.GetTestPort();
841-
App.Start(testAsset, ["--urls", "http://localhost:" + port], testFlags: TestFlags.ReadKeyFromStdin | TestFlags.MockBrowser);
841+
App.Start(testAsset, ["--urls", "http://localhost:" + port, "--non-interactive"], testFlags: TestFlags.ReadKeyFromStdin | TestFlags.MockBrowser);
842842

843843
await App.WaitForOutputLineContaining(MessageDescriptor.WaitingForChanges);
844844

845845
App.AssertOutputContains(MessageDescriptor.ConfiguredToUseBrowserRefresh);
846846
App.AssertOutputContains(MessageDescriptor.ConfiguredToLaunchBrowser);
847+
App.AssertOutputContains(MessageDescriptor.PressCtrlRToRestart);
847848

848849
// Browser is launched based on blazor-devserver output "Now listening on: ...".
849850
await App.WaitUntilOutputContains($"dotnet watch ⌚ Launching browser: http://localhost:{port}");

0 commit comments

Comments
 (0)