|
|
|
@ -7,14 +7,31 @@ namespace DiscordChatExporter.Cli.Utils.Extensions
|
|
|
|
|
{
|
|
|
|
|
internal static class ConsoleExtensions
|
|
|
|
|
{
|
|
|
|
|
public static IAnsiConsole CreateAnsiConsole(this IConsole console) => AnsiConsole.Create(
|
|
|
|
|
new AnsiConsoleSettings
|
|
|
|
|
{
|
|
|
|
|
Ansi = AnsiSupport.Detect,
|
|
|
|
|
ColorSystem = ColorSystemSupport.Detect,
|
|
|
|
|
Out = new AnsiConsoleOutput(console.Output)
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
private class NoopExclusivityMode : IExclusivityMode
|
|
|
|
|
{
|
|
|
|
|
public T Run<T>(Func<T> func) => func();
|
|
|
|
|
|
|
|
|
|
public Task<T> Run<T>(Func<Task<T>> func) => func();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static IAnsiConsole CreateAnsiConsole(this IConsole console)
|
|
|
|
|
{
|
|
|
|
|
// Don't require exclusivity in tests.
|
|
|
|
|
// Workaround for: https://github.com/spectreconsole/spectre.console/issues/494
|
|
|
|
|
var exclusivityMode = console is FakeConsole
|
|
|
|
|
? new NoopExclusivityMode()
|
|
|
|
|
: null;
|
|
|
|
|
|
|
|
|
|
return AnsiConsole.Create(
|
|
|
|
|
new AnsiConsoleSettings
|
|
|
|
|
{
|
|
|
|
|
Ansi = AnsiSupport.Detect,
|
|
|
|
|
ColorSystem = ColorSystemSupport.Detect,
|
|
|
|
|
Out = new AnsiConsoleOutput(console.Output),
|
|
|
|
|
ExclusivityMode = exclusivityMode
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Progress CreateProgressTicker(this IConsole console) => console
|
|
|
|
|
.CreateAnsiConsole()
|
|
|
|
|