BasicColor fixes

This commit is contained in:
2022-01-07 10:41:27 +01:00
parent 61c94d1d85
commit ee82603f2f
7 changed files with 35 additions and 9 deletions

View File

@@ -169,7 +169,7 @@ namespace FileTime.ConsoleUI.App
{ {
if (_selectedPane!.CurrentLocation.IsExists(newPath)) if (_selectedPane!.CurrentLocation.IsExists(newPath))
{ {
_coloredConsoleRenderer.ForegroundColor = AnsiColor.From8bit(1); _coloredConsoleRenderer.ForegroundColor = _styles.ErrorColor;
} }
else else
{ {

View File

@@ -25,6 +25,7 @@ namespace FileTime.ConsoleUI.App
private readonly IColoredConsoleRenderer _coloredConsoleRenderer; private readonly IColoredConsoleRenderer _coloredConsoleRenderer;
private readonly CommandExecutor _commandExecutor; private readonly CommandExecutor _commandExecutor;
private readonly ConsoleReader _consoleReader; private readonly ConsoleReader _consoleReader;
private readonly IStyles _styles;
private readonly List<ConsoleKeyInfo> _previousKeys = new(); private readonly List<ConsoleKeyInfo> _previousKeys = new();
public bool IsRunning { get; private set; } = true; public bool IsRunning { get; private set; } = true;
@@ -34,13 +35,15 @@ namespace FileTime.ConsoleUI.App
IClipboard clipboard, IClipboard clipboard,
IColoredConsoleRenderer coloredConsoleRenderer, IColoredConsoleRenderer coloredConsoleRenderer,
CommandExecutor commandExecutor, CommandExecutor commandExecutor,
ConsoleReader consoleReader) ConsoleReader consoleReader,
IStyles styles)
{ {
_serviceProvider = serviceProvider; _serviceProvider = serviceProvider;
_clipboard = clipboard; _clipboard = clipboard;
_coloredConsoleRenderer = coloredConsoleRenderer; _coloredConsoleRenderer = coloredConsoleRenderer;
_commandExecutor = commandExecutor; _commandExecutor = commandExecutor;
_consoleReader = consoleReader; _consoleReader = consoleReader;
_styles = styles;
InitCommandBindings(); InitCommandBindings();
} }

View File

@@ -53,7 +53,7 @@ namespace FileTime.ConsoleUI.App.UI.Color
} }
else if (BackgroundColor.GetType() != ForegroundColor.GetType()) else if (BackgroundColor.GetType() != ForegroundColor.GetType())
{ {
throw new Exception($"Type of {nameof(BackgroundColor)} and {nameof(ForegroundColor)} must be the same."); throw new Exception($"Type of {nameof(BackgroundColor)} ({BackgroundColor.GetType()}) and {nameof(ForegroundColor)} ({ForegroundColor.GetType()}) must be the same.");
} }
else else
{ {

View File

@@ -14,5 +14,7 @@ namespace FileTime.ConsoleUI.App.UI
IConsoleColor? ElementSpecialForeground { get; } IConsoleColor? ElementSpecialForeground { get; }
IConsoleColor? SelectedItemBackground { get; } IConsoleColor? SelectedItemBackground { get; }
IConsoleColor? SelectedItemForeground { get; } IConsoleColor? SelectedItemForeground { get; }
IConsoleColor? ErrorColor { get; }
IConsoleColor? AccentForeground { get; }
} }
} }

View File

@@ -133,13 +133,13 @@ namespace FileTime.ConsoleUI.App.UI
{ {
Console.SetCursorPosition(0, 0); Console.SetCursorPosition(0, 0);
_coloredRenderer.ResetColor(); _coloredRenderer.ResetColor();
_coloredRenderer.ForegroundColor = AnsiColor.From8bit(2); _coloredRenderer.ForegroundColor = _appStyle.AccentForeground;
_coloredRenderer.Write(Environment.UserName + "@" + Environment.MachineName); _coloredRenderer.Write(Environment.UserName + "@" + Environment.MachineName);
_coloredRenderer.ResetColor(); _coloredRenderer.ResetColor();
_coloredRenderer.Write(' '); _coloredRenderer.Write(' ');
_coloredRenderer.ForegroundColor = AnsiColor.From8bit(4); _coloredRenderer.ForegroundColor = _appStyle.ContainerForeground;
var path = Pane!.CurrentLocation.FullName + "/"; var path = Pane!.CurrentLocation.FullName + "/";
_coloredRenderer.Write(path); _coloredRenderer.Write(path);

View File

@@ -15,6 +15,9 @@ namespace FileTime.ConsoleUI.App.UI
public IConsoleColor? SelectedItemBackground { get; } public IConsoleColor? SelectedItemBackground { get; }
public IConsoleColor? SelectedItemForeground { get; } public IConsoleColor? SelectedItemForeground { get; }
public IConsoleColor? ErrorColor { get; }
public IConsoleColor? AccentForeground { get; }
public Styles(bool useAnsiColors) public Styles(bool useAnsiColors)
{ {
if (useAnsiColors) if (useAnsiColors)
@@ -23,17 +26,25 @@ namespace FileTime.ConsoleUI.App.UI
ElementForeground = AnsiColor.From8bit(14); ElementForeground = AnsiColor.From8bit(14);
ElementSpecialForeground = AnsiColor.From8bit(2); ElementSpecialForeground = AnsiColor.From8bit(2);
SelectedItemForeground = AnsiColor.From8bit(3); SelectedItemForeground = AnsiColor.From8bit(3);
ElementBackground = AnsiColor.From8bit(0);
DefaultForeground = ElementForeground; ErrorColor = AnsiColor.From8bit(1);
SelectedItemBackground = ElementSpecialBackground = ContainerBackground = DefaultBackground = ElementBackground = AnsiColor.From8bit(0); AccentForeground = AnsiColor.From8bit(2);
} }
else else
{ {
ContainerBackground = new BasicColor(Console.BackgroundColor);
ContainerForeground = new BasicColor(ConsoleColor.Blue); ContainerForeground = new BasicColor(ConsoleColor.Blue);
ElementBackground = new BasicColor(Console.BackgroundColor); ElementBackground = new BasicColor(Console.BackgroundColor);
ElementForeground = new BasicColor(Console.ForegroundColor); ElementForeground = new BasicColor(Console.ForegroundColor);
ElementSpecialForeground = new BasicColor(ConsoleColor.DarkGreen);
SelectedItemForeground = new BasicColor(ConsoleColor.DarkCyan);
ErrorColor = new BasicColor(ConsoleColor.Red);
AccentForeground = new BasicColor(ConsoleColor.Green);
} }
DefaultForeground = ElementForeground;
SelectedItemBackground = ElementSpecialBackground = ContainerBackground = DefaultBackground = ElementBackground;
} }
} }
} }

View File

@@ -87,12 +87,22 @@ namespace FileTime.ConsoleUI
} }
} }
private static bool IsAnsiColorSupported()
{
Console.CursorLeft = 0;
Console.CursorTop = 0;
Console.Write("\u001b[0ma");
return Console.CursorLeft == 1 && Console.CursorTop == 0;
}
private static ServiceProvider CreateServiceProvider() private static ServiceProvider CreateServiceProvider()
{ {
return new ServiceCollection() return new ServiceCollection()
.AddLogging((builder) => builder.AddConsole().AddDebug()) .AddLogging((builder) => builder.AddConsole().AddDebug())
.AddSingleton<Application>() .AddSingleton<Application>()
.AddSingleton<IStyles>(new Styles(true)) .AddSingleton<IStyles>(new Styles(IsAnsiColorSupported()))
.AddSingleton<IColoredConsoleRenderer, ColoredConsoleRenderer>() .AddSingleton<IColoredConsoleRenderer, ColoredConsoleRenderer>()
.AddSingleton<IClipboard, Clipboard>() .AddSingleton<IClipboard, Clipboard>()
.AddSingleton<LocalContentProvider>() .AddSingleton<LocalContentProvider>()