-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[release/6.0.3xx] Backport Improve console output of
dotnet watch
⌚ (…
…#23318) (#23400) * Improve console output of `dotnet watch` ⌚ (#23318) * UTF8->UTF8 with BOM & UTF8 Console Output Encoding * DOTNET_WATCH_SUPPRESS_EMOJIS * Set process encoding * `dotnet watch` test fix search console history (cherry picked from commit 4250693)
- Loading branch information
1 parent
48f9548
commit 93c4356
Showing
30 changed files
with
401 additions
and
229 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Tools.Internal; | ||
|
||
namespace Microsoft.DotNet.Watcher.Tools | ||
{ | ||
public class RudeEditDialog | ||
{ | ||
private readonly IReporter _reporter; | ||
private readonly IRequester _requester; | ||
private readonly IConsole _console; | ||
private bool? _restartImmediatelySessionPreference; // Session preference | ||
|
||
public RudeEditDialog(IReporter reporter, IRequester requester, IConsole console) | ||
{ | ||
_reporter = reporter; | ||
_requester = requester; | ||
_console = console; | ||
|
||
var alwaysRestart = Environment.GetEnvironmentVariable("DOTNET_WATCH_RESTART_ON_RUDE_EDIT"); | ||
|
||
if (alwaysRestart == "1" || string.Equals(alwaysRestart, "true", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
_reporter.Verbose($"DOTNET_WATCH_RESTART_ON_RUDE_EDIT = '{alwaysRestart}'. Restarting without prompt."); | ||
_restartImmediatelySessionPreference = true; | ||
} | ||
} | ||
|
||
public async Task EvaluateAsync(CancellationToken cancellationToken) | ||
{ | ||
if (_restartImmediatelySessionPreference.HasValue) | ||
{ | ||
await GetRudeEditResult(_restartImmediatelySessionPreference.Value, cancellationToken); | ||
return; | ||
} | ||
|
||
var key = await _requester.GetKeyAsync( | ||
"Do you want to restart your app - Yes (y) / No (n) / Always (a) / Never (v)?", | ||
KeyPressed, | ||
cancellationToken); | ||
|
||
switch (key) | ||
{ | ||
case ConsoleKey.Escape: | ||
case ConsoleKey.Y: | ||
await GetRudeEditResult(restartImmediately: true, cancellationToken); | ||
return; | ||
case ConsoleKey.N: | ||
await GetRudeEditResult(restartImmediately: false, cancellationToken); | ||
return; | ||
case ConsoleKey.A: | ||
_restartImmediatelySessionPreference = true; | ||
await GetRudeEditResult(restartImmediately: true, cancellationToken); | ||
return; | ||
case ConsoleKey.V: | ||
_restartImmediatelySessionPreference = false; | ||
await GetRudeEditResult(restartImmediately: false, cancellationToken); | ||
return; | ||
} | ||
|
||
bool KeyPressed(ConsoleKey key) | ||
{ | ||
return key is ConsoleKey.Y or ConsoleKey.N or ConsoleKey.A or ConsoleKey.V; | ||
} | ||
} | ||
|
||
private Task GetRudeEditResult(bool restartImmediately, CancellationToken cancellationToken) | ||
{ | ||
if (restartImmediately) | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
|
||
_reporter.Output("Hot reload suspended. To continue hot reload, press \"Ctrl + R\".", emoji: "🔥"); | ||
|
||
return Task.Delay(-1, cancellationToken); | ||
} | ||
} | ||
} |
95 changes: 0 additions & 95 deletions
95
src/BuiltInTools/dotnet-watch/HotReload/RudeEditPreference.cs
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
Oops, something went wrong.