Console Styling

This commit is contained in:
2023-08-21 12:27:02 +02:00
parent 793f653db0
commit fff07e5da7
26 changed files with 572 additions and 160 deletions

View File

@@ -0,0 +1,9 @@
using FileTime.ConsoleUI.App.Configuration.Theme;
namespace FileTime.ConsoleUI.App.Configuration;
public class StyleConfigurationRoot
{
public string? Theme { get; set; }
public Dictionary<string, ThemeConfiguration> Themes { get; set; } = new();
}

View File

@@ -0,0 +1,6 @@
namespace FileTime.ConsoleUI.App.Configuration.Theme;
public class ConsoleThemeConfiguration
{
public ControlThemesConfiguration ControlThemes { get; set; } = new();
}

View File

@@ -0,0 +1,6 @@
namespace FileTime.ConsoleUI.App.Configuration.Theme;
public class ControlThemesConfiguration
{
public ProgressBarThemeConfiguration? ProgressBar { get; set; }
}

View File

@@ -0,0 +1,7 @@
namespace FileTime.ConsoleUI.App.Configuration.Theme;
public class ListViewItemThemeConfiguration
{
public string? SelectedForegroundColor { get; set; }
public string? SelectedBackgroundColor { get; set; }
}

View File

@@ -0,0 +1,24 @@
using TerminalUI.Models;
namespace FileTime.ConsoleUI.App.Configuration.Theme;
public class ProgressBarThemeConfiguration
{
public string? ForegroundColor { get; set; }
public string? BackgroundColor { get; set; }
public string? UnfilledForeground { get; set; }
public string? UnfilledBackground { get; set; }
public SelectiveChar? FilledCharacter { get; set; }
public SelectiveChar? UnfilledCharacter { get; set; }
public SelectiveChar? Fraction1Per8Character { get; set; }
public SelectiveChar? Fraction2Per8Character { get; set; }
public SelectiveChar? Fraction3Per8Character { get; set; }
public SelectiveChar? Fraction4Per8Character { get; set; }
public SelectiveChar? Fraction5Per8Character { get; set; }
public SelectiveChar? Fraction6Per8Character { get; set; }
public SelectiveChar? Fraction7Per8Character { get; set; }
public SelectiveChar? FractionFull { get; set; }
public SelectiveChar? LeftCap { get; set; }
public SelectiveChar? RightCap { get; set; }
}

View File

@@ -0,0 +1,20 @@
namespace FileTime.ConsoleUI.App.Configuration.Theme;
public class ThemeConfiguration
{
public string? DefaultForegroundColor { get; set; }
public string? DefaultForegroundAccentColor { get; set; }
public string? DefaultBackgroundColor { get; set; }
public string? ElementColor { get; set; }
public string? ContainerColor { get; set; }
public string? MarkedItemForegroundColor { get; set; }
public string? MarkedItemBackgroundColor { get; set; }
public string? MarkedSelectedItemForegroundColor { get; set; }
public string? MarkedSelectedItemBackgroundColor { get; set; }
public string? SelectedItemColor { get; set; }
public string? SelectedTabBackgroundColor { get; set; }
public string? WarningForegroundColor { get; set; }
public string? ErrorForegroundColor { get; set; }
public ConsoleThemeConfiguration? ConsoleTheme { get; set; }
public ListViewItemThemeConfiguration? ListViewItemTheme { get; set; }
}

View File

@@ -1,7 +0,0 @@
namespace FileTime.ConsoleUI.App;
public interface IColorSampleProvider
{
public Type? ForegroundColors { get; }
public Type? BackgroundColors { get; }
}

View File

@@ -1,11 +1,6 @@
using FileTime.ConsoleUI.App;
using FileTime.ConsoleUI.App.Styling;
using TerminalUI.Color;
using TerminalUI.Styling;
using TerminalUI.Styling.Controls;
using ITheme = FileTime.ConsoleUI.App.Styling.ITheme;
using TerminalUI.Color;
namespace FileTime.ConsoleUI.Styles;
namespace FileTime.ConsoleUI.App.Styling;
using IConsoleTheme = TerminalUI.Styling.ITheme;
using ConsoleTheme = TerminalUI.Styling.Theme;
@@ -25,11 +20,9 @@ public record Theme(
IColor? WarningForegroundColor,
IColor? ErrorForegroundColor,
ListViewItemTheme ListViewItemTheme,
IConsoleTheme? ConsoleTheme,
Type? ForegroundColors,
Type? BackgroundColors) : ITheme, IColorSampleProvider;
IConsoleTheme? ConsoleTheme) : ITheme;
public static class DefaultThemes
/*public static class DefaultThemes
{
public static Theme Color256Theme => new(
DefaultForegroundColor: null,
@@ -100,4 +93,4 @@ public static class DefaultThemes
ForegroundColors: typeof(ConsoleColors.Foregrounds),
BackgroundColors: typeof(ConsoleColors.Backgrounds)
);
}
}*/

View File

@@ -0,0 +1,6 @@
namespace FileTime.ConsoleUI.App.Styling;
public interface IThemeProvider
{
ITheme CurrentTheme { get; }
}

View File

@@ -1,8 +1,10 @@
using System.Collections.Specialized;
using System.ComponentModel;
using FileTime.App.Core.Services;
using FileTime.App.Core.ViewModels;
using FileTime.ConsoleUI.App.Configuration;
using FileTime.ConsoleUI.App.KeyInputHandling;
using FileTime.ConsoleUI.App.Styling;
using GeneralInputKey;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
@@ -26,6 +28,7 @@ public class App : IApplication
private readonly IApplicationContext _applicationContext;
private readonly IConsoleDriver _consoleDriver;
private readonly IAppState _appState;
private readonly IThemeProvider _themeProvider;
private readonly ILogger<App> _logger;
private readonly IKeyInputHandlerService _keyInputHandlerService;
private readonly Thread _renderThread;
@@ -38,6 +41,7 @@ public class App : IApplication
IApplicationContext applicationContext,
IConsoleDriver consoleDriver,
IAppState appState,
IThemeProvider themeProvider,
IOptions<ConsoleApplicationConfiguration> consoleApplicationConfiguration,
ILogger<App> logger)
{
@@ -48,13 +52,30 @@ public class App : IApplication
_applicationContext = applicationContext;
_consoleDriver = consoleDriver;
_appState = appState;
_themeProvider = themeProvider;
_logger = logger;
if (themeProvider is INotifyPropertyChanged notifyPropertyChanged)
notifyPropertyChanged.PropertyChanged += ThemeProviderPropertyChanged;
_applicationContext.Theme = themeProvider.CurrentTheme.ConsoleTheme ?? _applicationContext.Theme;
_applicationContext.SupportUtf8Output = !consoleApplicationConfiguration.Value.DisableUtf8;
_renderThread = new Thread(Render);
}
private void ThemeProviderPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(IThemeProvider.CurrentTheme))
{
UpdateConsoleTheme();
}
}
private void UpdateConsoleTheme()
=> _applicationContext.Theme = _themeProvider.CurrentTheme.ConsoleTheme;
public void Run()
{
Task.Run(async () => await _lifecycleService.InitStartupHandlersAsync()).Wait();
@@ -117,7 +138,7 @@ public class App : IApplication
Thread.Sleep(10);
}
Task.Run(async () => await _lifecycleService.ExitAsync()).Wait();
}

View File

@@ -41,11 +41,10 @@ public class MainWindow
private readonly IOptions<ConsoleApplicationConfiguration> _consoleApplicationConfiguration;
private readonly Lazy<IView> _root;
public MainWindow(
IRootViewModel rootViewModel,
IApplicationContext applicationContext,
ITheme theme,
IThemeProvider themeProvider,
CommandPalette commandPalette,
FrequencyNavigation frequencyNavigation,
Dialogs dialogs,
@@ -55,7 +54,7 @@ public class MainWindow
{
_rootViewModel = rootViewModel;
_applicationContext = applicationContext;
_theme = theme;
_theme = themeProvider.CurrentTheme;
_commandPalette = commandPalette;
_frequencyNavigation = frequencyNavigation;
_dialogs = dialogs;

View File

@@ -0,0 +1,123 @@
using FileTime.ConsoleUI.App.Configuration;
using FileTime.ConsoleUI.App.Configuration.Theme;
using FileTime.ConsoleUI.App.Styling;
using Microsoft.Extensions.Options;
using PropertyChanged.SourceGenerator;
using TerminalUI.Color;
using TerminalUI.Styling;
using TerminalUI.Styling.Controls;
using IConsoleTheme = TerminalUI.Styling.ITheme;
using ConsoleTheme = TerminalUI.Styling.Theme;
using ITheme = FileTime.ConsoleUI.App.Styling.ITheme;
using Theme = FileTime.ConsoleUI.App.Styling.Theme;
namespace FileTime.ConsoleUI.App.Services;
public partial class ThemeProvider : IThemeProvider
{
private readonly ITheme _defaultTheme;
private readonly IColorProvider _colorProvider;
private readonly IOptionsMonitor<StyleConfigurationRoot> _styleConfiguration;
[Notify] private ITheme _currentTheme = null!;
public ThemeProvider(
ITheme defaultTheme,
IColorProvider colorProvider,
IOptionsMonitor<StyleConfigurationRoot> styleConfiguration
)
{
_defaultTheme = defaultTheme;
_colorProvider = colorProvider;
_styleConfiguration = styleConfiguration;
styleConfiguration.OnChange(ThemeConfigurationChanged);
UpdateCurrentTheme();
}
private void ThemeConfigurationChanged(StyleConfigurationRoot arg1, string? arg2) => UpdateCurrentTheme();
private void UpdateCurrentTheme()
{
var currentThemeName = _styleConfiguration.CurrentValue.Theme;
ThemeConfiguration? currentTheme = null;
if (currentThemeName is not null
&& _styleConfiguration.CurrentValue.Themes.TryGetValue(currentThemeName, out currentTheme)
|| currentTheme is null)
{
CurrentTheme = _defaultTheme;
return;
}
var theme = new Theme(
ParseColor(currentTheme.DefaultForegroundColor) ?? _defaultTheme.DefaultForegroundColor,
ParseColor(currentTheme.DefaultForegroundAccentColor) ?? _defaultTheme.DefaultForegroundAccentColor,
ParseColor(currentTheme.DefaultBackgroundColor) ?? _defaultTheme.DefaultBackgroundColor,
ParseColor(currentTheme.ElementColor) ?? _defaultTheme.ElementColor,
ParseColor(currentTheme.ContainerColor) ?? _defaultTheme.ContainerColor,
ParseColor(currentTheme.MarkedItemForegroundColor) ?? _defaultTheme.MarkedItemForegroundColor,
ParseColor(currentTheme.MarkedItemBackgroundColor) ?? _defaultTheme.MarkedItemBackgroundColor,
ParseColor(currentTheme.MarkedSelectedItemForegroundColor) ?? _defaultTheme.MarkedSelectedItemForegroundColor,
ParseColor(currentTheme.MarkedSelectedItemBackgroundColor) ?? _defaultTheme.MarkedSelectedItemBackgroundColor,
ParseColor(currentTheme.SelectedItemColor) ?? _defaultTheme.SelectedItemColor,
ParseColor(currentTheme.SelectedTabBackgroundColor) ?? _defaultTheme.SelectedTabBackgroundColor,
ParseColor(currentTheme.WarningForegroundColor) ?? _defaultTheme.WarningForegroundColor,
ParseColor(currentTheme.ErrorForegroundColor) ?? _defaultTheme.ErrorForegroundColor,
CreateListViewItemTheme(currentTheme.ListViewItemTheme),
CreateConsoleTheme(currentTheme.ConsoleTheme)
);
CurrentTheme = theme;
}
private IColor? ParseColor(string? colorString, bool foreground = true)
=> colorString is null
? null
: _colorProvider.Parse(colorString, foreground ? ColorType.Foreground : ColorType.Background);
private ListViewItemTheme CreateListViewItemTheme(ListViewItemThemeConfiguration? currentThemeListViewItemTheme)
{
var theme = new ListViewItemTheme(
ParseColor(currentThemeListViewItemTheme?.SelectedForegroundColor) ?? _defaultTheme.ListViewItemTheme.SelectedForegroundColor,
ParseColor(currentThemeListViewItemTheme?.SelectedBackgroundColor) ?? _defaultTheme.ListViewItemTheme.SelectedBackgroundColor
);
return theme;
}
private IConsoleTheme CreateConsoleTheme(ConsoleThemeConfiguration? currentThemeConsoleTheme)
{
var controlThemes = currentThemeConsoleTheme?.ControlThemes;
var progressBarTheme = controlThemes?.ProgressBar;
var defaultControlThemes = _defaultTheme.ConsoleTheme?.ControlThemes;
var defaultProgressBarTheme = defaultControlThemes?.ProgressBar;
var theme = new ConsoleTheme
{
ControlThemes = new ControlThemes
{
ProgressBar = new ProgressBarTheme
{
ForegroundColor = ParseColor(progressBarTheme?.ForegroundColor) ?? defaultProgressBarTheme?.ForegroundColor,
BackgroundColor = ParseColor(progressBarTheme?.BackgroundColor) ?? defaultProgressBarTheme?.BackgroundColor,
UnfilledForeground = ParseColor(progressBarTheme?.UnfilledForeground) ?? defaultProgressBarTheme?.UnfilledForeground,
UnfilledBackground = ParseColor(progressBarTheme?.UnfilledBackground) ?? defaultProgressBarTheme?.UnfilledBackground,
FilledCharacter = progressBarTheme?.FilledCharacter ?? defaultProgressBarTheme?.FilledCharacter,
UnfilledCharacter = progressBarTheme?.UnfilledCharacter ?? defaultProgressBarTheme?.UnfilledCharacter,
Fraction1Per8Character = progressBarTheme?.Fraction1Per8Character ?? defaultProgressBarTheme?.Fraction1Per8Character,
Fraction2Per8Character = progressBarTheme?.Fraction2Per8Character ?? defaultProgressBarTheme?.Fraction2Per8Character,
Fraction3Per8Character = progressBarTheme?.Fraction3Per8Character ?? defaultProgressBarTheme?.Fraction3Per8Character,
Fraction4Per8Character = progressBarTheme?.Fraction4Per8Character ?? defaultProgressBarTheme?.Fraction4Per8Character,
Fraction5Per8Character = progressBarTheme?.Fraction5Per8Character ?? defaultProgressBarTheme?.Fraction5Per8Character,
Fraction6Per8Character = progressBarTheme?.Fraction6Per8Character ?? defaultProgressBarTheme?.Fraction6Per8Character,
Fraction7Per8Character = progressBarTheme?.Fraction7Per8Character ?? defaultProgressBarTheme?.Fraction7Per8Character,
FractionFull = progressBarTheme?.FractionFull ?? defaultProgressBarTheme?.FractionFull,
LeftCap = progressBarTheme?.LeftCap ?? defaultProgressBarTheme?.LeftCap,
RightCap = progressBarTheme?.RightCap ?? defaultProgressBarTheme?.RightCap,
}
}
};
return theme;
}
}

View File

@@ -5,6 +5,7 @@ using FileTime.ConsoleUI.App.Configuration;
using FileTime.ConsoleUI.App.Controls;
using FileTime.ConsoleUI.App.KeyInputHandling;
using FileTime.ConsoleUI.App.Services;
using FileTime.ConsoleUI.App.Styling;
using FileTime.ConsoleUI.App.UserCommand;
using FileTime.Core.Interactions;
using Microsoft.Extensions.Configuration;
@@ -20,6 +21,7 @@ public class StartupHandler : IStartupHandler
identifiableUserCommandService.AddIdentifiableUserCommand(NextPreviewUserCommand.Instance);
identifiableUserCommandService.AddIdentifiableUserCommand(PreviousPreviewUserCommand.Instance);
}
public Task InitAsync() => Task.CompletedTask;
}
@@ -38,10 +40,12 @@ public static class Startup
services.TryAddSingleton<IRootViewModel, RootViewModel>();
services.TryAddSingleton<IDialogService, DialogService>();
services.TryAddSingleton<IUserCommunicationService>(sp => sp.GetRequiredService<IDialogService>());
services.AddSingleton<IUserCommandHandler, ConsoleUserCommandHandler>();
services.TryAddSingleton<IUserCommandHandler, ConsoleUserCommandHandler>();
services.AddSingleton<IStartupHandler, StartupHandler>();
services.TryAddSingleton<IThemeProvider, ThemeProvider>();
services.Configure<ConsoleApplicationConfiguration>(configuration);
services.Configure<StyleConfigurationRoot>(configuration.GetSection("Style"));
return services;
}

View File

@@ -1,13 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\FileTime.ConsoleUI.App.Abstractions\FileTime.ConsoleUI.App.Abstractions.csproj" />
</ItemGroup>
</Project>

View File

@@ -19,7 +19,6 @@
<ProjectReference Include="..\..\Library\TerminalUI.DependencyInjection\TerminalUI.DependencyInjection.csproj" />
<ProjectReference Include="..\..\Tools\FileTime.Tools.Compression\FileTime.Tools.Compression.csproj" />
<ProjectReference Include="..\FileTime.ConsoleUI.App\FileTime.ConsoleUI.App.csproj" />
<ProjectReference Include="..\FileTime.ConsoleUI.Styles\FileTime.ConsoleUI.Styles.csproj" />
</ItemGroup>
<ItemGroup>
@@ -39,4 +38,8 @@
<Content Include="appsettings.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
<ItemGroup Condition="'$(Configuration)' == 'Debug'">
<Content Include="appsettings.Local.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
</Project>

View File

@@ -10,14 +10,15 @@ public static class ColorSchema
{
private const int ColorTextMargin = 5;
public static void PrintColorSchema(ITheme theme, IConsoleDriver consoleDriver)
public static void PrintColorSchema(IThemeProvider themeProvider, IColorProvider colorProvider, IConsoleDriver consoleDriver)
{
var theme = themeProvider.CurrentTheme;
consoleDriver.Dispose();
consoleDriver.ResetStyle();
PrintThemeColors(theme, consoleDriver);
if (theme is IColorSampleProvider colorSampleProvider)
PrintColorPalette(colorSampleProvider, consoleDriver);
PrintColorPalette(colorProvider, consoleDriver);
}
private static void PrintThemeColors(ITheme theme, IConsoleDriver consoleDriver)
@@ -50,37 +51,26 @@ public static class ColorSchema
consoleDriver.Write(Environment.NewLine);
}
private static void PrintColorPalette(IColorSampleProvider colorSampleProvider, IConsoleDriver consoleDriver)
private static void PrintColorPalette(IColorProvider colorSampleProvider, IConsoleDriver consoleDriver)
{
if (colorSampleProvider.ForegroundColors is { } foregroundColors)
{
PrintColorPalette("foreground", foregroundColors, consoleDriver);
}
var colorPalette = colorSampleProvider.GetType();
if (colorSampleProvider.BackgroundColors is { } backgroundColors)
{
PrintColorPalette("background", backgroundColors, consoleDriver);
}
}
private static void PrintColorPalette(string paletteName, Type colorPalette, IConsoleDriver consoleDriver)
{
var colorType = typeof(IColor);
var colorFields = colorPalette
.GetFields()
.Where(f => f.FieldType.IsAssignableTo(colorType) && f.IsStatic)
.ToDictionary(f => f.Name, f => (IColor?) f.GetValue(null));
.Where(f => f.FieldType.IsAssignableTo(colorType) && !f.IsStatic)
.ToDictionary(f => f.Name, f => (IColor?) f.GetValue(colorSampleProvider));
var colorProperties = colorPalette
.GetProperties()
.Where(p => p.PropertyType.IsAssignableTo(colorType) && (p.GetMethod?.IsStatic ?? false))
.ToDictionary(p => p.Name, p => (IColor?) p.GetValue(null));
.Where(p => p.PropertyType.IsAssignableTo(colorType) && p.GetMethod is {IsStatic: false})
.ToDictionary(p => p.Name, p => (IColor?) p.GetValue(colorSampleProvider));
var colors = colorFields
.Concat(colorProperties)
.OrderBy(v => v.Key)
.ToDictionary(k => k.Key, v => v.Value);
consoleDriver.Write("Color palette for " + paletteName + Environment.NewLine);
consoleDriver.Write("Color palette for " + colorPalette.Name + Environment.NewLine);
if (colors.Count == 0)
{
@@ -94,7 +84,7 @@ public static class ColorSchema
{
PrintColor(consoleDriver, key, value, colorTextStartX);
}
consoleDriver.ResetStyle();
consoleDriver.Write(Environment.NewLine);
}

View File

@@ -3,12 +3,14 @@ using FileTime.App.Core;
using FileTime.App.Core.Configuration;
using FileTime.ConsoleUI;
using FileTime.ConsoleUI.App;
using FileTime.ConsoleUI.App.Styling;
using FileTime.ConsoleUI.InfoProviders;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Serilog;
using Serilog.Debugging;
using TerminalUI;
using TerminalUI.Color;
using TerminalUI.ConsoleDrivers;
using ITheme = FileTime.ConsoleUI.App.Styling.ITheme;
@@ -37,9 +39,9 @@ try
driver.SetCursorVisible(false);
var applicationContext = serviceProvider.GetRequiredService<IApplicationContext>();
var theme = serviceProvider.GetRequiredService<ITheme>();
var defaultTheme = serviceProvider.GetRequiredService<ITheme>();
applicationContext.Theme = theme.ConsoleTheme;
applicationContext.Theme = defaultTheme.ConsoleTheme;
var app = serviceProvider.GetRequiredService<IApplication>();
app.Run();
@@ -79,6 +81,7 @@ static IConfigurationRoot CreateConfiguration(string[] strings)
.AddInMemoryCollection(MainConsoleConfiguration.Configuration)
#if DEBUG
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile("appsettings.Local.json", optional: true, reloadOnChange: true)
#endif
;
@@ -103,7 +106,8 @@ static bool HandleInfoProviders(string[] args, IServiceProvider serviceProvider)
{
"--info=colors",
() => ColorSchema.PrintColorSchema(
serviceProvider.GetRequiredService<ITheme>(),
serviceProvider.GetRequiredService<IThemeProvider>(),
serviceProvider.GetRequiredService<IColorProvider>(),
serviceProvider.GetRequiredService<IConsoleDriver>()
)
},

View File

@@ -1,10 +1,15 @@
using FileTime.ConsoleUI.App.Configuration;
using FileTime.ConsoleUI.App.Styling;
using FileTime.ConsoleUI.Styles;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
using TerminalUI.Color;
using TerminalUI.ConsoleDrivers;
using TerminalUI.Styling;
using TerminalUI.Styling.Controls;
using IConsoleTheme = TerminalUI.Styling.ITheme;
using ConsoleTheme = TerminalUI.Styling.Theme;
using ITheme = FileTime.ConsoleUI.App.Styling.ITheme;
using Theme = FileTime.ConsoleUI.App.Styling.Theme;
namespace FileTime.ConsoleUI;
@@ -48,15 +53,54 @@ public static class Startup
public static IServiceCollection AddTheme(this IServiceCollection serviceCollection)
{
serviceCollection.TryAddSingleton<ITheme>(sp =>
{
var colorProvider = sp.GetRequiredService<IColorProvider>();
return new Theme(
DefaultForegroundColor: null,
DefaultForegroundAccentColor: colorProvider.RedForeground,
DefaultBackgroundColor: null,
ElementColor: colorProvider.GrayForeground,
ContainerColor: colorProvider.BlueForeground,
MarkedItemForegroundColor: colorProvider.YellowForeground,
MarkedItemBackgroundColor: null,
MarkedSelectedItemForegroundColor: colorProvider.BlackForeground,
MarkedSelectedItemBackgroundColor: colorProvider.YellowForeground,
SelectedItemColor: colorProvider.BlackForeground,
SelectedTabBackgroundColor: colorProvider.GreenBackground,
WarningForegroundColor: colorProvider.YellowForeground,
ErrorForegroundColor: colorProvider.RedForeground,
ListViewItemTheme: new(
SelectedBackgroundColor: colorProvider.GrayBackground,
SelectedForegroundColor: colorProvider.BlackForeground
),
ConsoleTheme: new ConsoleTheme
{
ControlThemes = new ControlThemes
{
ProgressBar = new ProgressBarTheme
{
ForegroundColor = colorProvider.BlueForeground,
BackgroundColor = colorProvider.GrayBackground,
UnfilledForeground = colorProvider.GrayForeground,
UnfilledBackground = colorProvider.GrayBackground,
}
}
}
);
});
serviceCollection.TryAddSingleton<IColorProvider>(sp =>
{
var driver = sp.GetRequiredService<IConsoleDriver>();
return driver switch
{
XTermDriver _ => DefaultThemes.Color256Theme,
DotnetDriver _ => DefaultThemes.ConsoleColorTheme,
XTermDriver _ => new AnsiColorProvider(),
DotnetDriver _ => new ConsoleColorProvider(),
_ => throw new ArgumentOutOfRangeException(nameof(driver))
};
});
return serviceCollection;