TerminalUI theming, Commands panel

This commit is contained in:
2023-08-15 20:23:58 +02:00
parent b792639635
commit d175c7bf7e
27 changed files with 604 additions and 77 deletions

View File

@@ -3,4 +3,5 @@
public class ConsoleApplicationConfiguration
{
public string? ConsoleDriver { get; set; }
public bool DisableUtf8 { get; set; }
}

View File

@@ -1,6 +1,7 @@
using TerminalUI.Color;
namespace FileTime.ConsoleUI.App.Styling;
using IConsoleTheme = TerminalUI.Styling.ITheme;
public interface ITheme
{
@@ -17,5 +18,6 @@ public interface ITheme
IColor? SelectedTabBackgroundColor { get; }
IColor? WarningForegroundColor { get; }
IColor? ErrorForegroundColor { get; }
IConsoleTheme? ConsoleTheme { get; }
ListViewItemTheme ListViewItemTheme { get; }
}

View File

@@ -1,13 +1,11 @@
using System.Collections.Specialized;
using FileTime.App.Core.Services;
using FileTime.App.Core.ViewModels;
using FileTime.ConsoleUI.App.Configuration;
using FileTime.ConsoleUI.App.KeyInputHandling;
using FileTime.Core.Command.CreateContainer;
using FileTime.Core.Models;
using FileTime.Core.Timeline;
using GeneralInputKey;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using TerminalUI;
using TerminalUI.ConsoleDrivers;
@@ -23,40 +21,36 @@ public class App : IApplication
private readonly ILifecycleService _lifecycleService;
private readonly IConsoleAppState _consoleAppState;
private readonly IAppKeyService<ConsoleKey> _appKeyService;
private readonly MainWindow _mainWindow;
private readonly IApplicationContext _applicationContext;
private readonly IConsoleDriver _consoleDriver;
private readonly IAppState _appState;
private readonly ILogger<App> _logger;
private readonly IServiceProvider _serviceProvider;
private readonly IKeyInputHandlerService _keyInputHandlerService;
private readonly Thread _renderThread;
public App(
ILifecycleService lifecycleService,
IKeyInputHandlerService keyInputHandlerService,
IConsoleAppState consoleAppState,
IAppKeyService<ConsoleKey> appKeyService,
MainWindow mainWindow,
IApplicationContext applicationContext,
IConsoleDriver consoleDriver,
IAppState appState,
ILogger<App> logger,
IServiceProvider serviceProvider)
IOptions<ConsoleApplicationConfiguration> consoleApplicationConfiguration,
ILogger<App> logger)
{
_lifecycleService = lifecycleService;
_keyInputHandlerService = keyInputHandlerService;
_consoleAppState = consoleAppState;
_appKeyService = appKeyService;
_mainWindow = mainWindow;
_applicationContext = applicationContext;
_consoleDriver = consoleDriver;
_appState = appState;
_logger = logger;
_serviceProvider = serviceProvider;
_applicationContext.SupportUtf8Output = !consoleApplicationConfiguration.Value.DisableUtf8;
_renderThread = new Thread(Render);
}
@@ -81,12 +75,6 @@ public class App : IApplication
var focusManager = _applicationContext.FocusManager;
var command = _serviceProvider.GetRequiredService<CreateContainerCommand>();
command.Init(new FullName("local/C:/Test3"), "container1");
var scheduler = _serviceProvider.GetRequiredService<ICommandScheduler>();
scheduler.AddCommand(command);
while (_applicationContext.IsRunning)
{
try

View File

@@ -1,32 +1,87 @@
using FileTime.App.Core.ViewModels.Timeline;
using FileTime.ConsoleUI.App.Styling;
using TerminalUI.Controls;
using TerminalUI.Extensions;
using TerminalUI.Models;
using TerminalUI.Styling.Controls;
using TerminalUI.ViewExtensions;
namespace FileTime.ConsoleUI.App.Controls;
public class Timeline
{
private readonly IProgressBarTheme? _progressBarTheme;
public Timeline(ITheme theme)
{
_progressBarTheme = theme.ConsoleTheme?.ControlThemes.ProgressBar;
}
public IView<IRootViewModel> View()
{
var root = new Grid<IRootViewModel>
{
ChildInitializer =
{
new ItemsControl<IRootViewModel, ICommandTimeStateViewModel>()
new ItemsControl<IRootViewModel, ICommandTimeStateViewModel>
{
Orientation = Orientation.Horizontal,
ItemTemplate = () =>
{
var grid = new Grid<ICommandTimeStateViewModel>()
var grid = new Grid<ICommandTimeStateViewModel>
{
Margin = "0 0 1 0",
Width = 20,
RowDefinitionsObject = "Auto Auto",
ChildInitializer =
{
new TextBlock<ICommandTimeStateViewModel>()
new Grid<ICommandTimeStateViewModel>
{
}.Setup(t => t.Bind(
t,
dc => dc.DisplayLabel.Value,
t => t.Text))
ColumnDefinitionsObject = "* Auto",
ChildInitializer =
{
new TextBlock<ICommandTimeStateViewModel>().Setup(t => t.Bind(
t,
dc => dc.DisplayLabel.Value,
t => t.Text)),
new TextBlock<ICommandTimeStateViewModel>
{
Width = 5,
TextAlignment = TextAlignment.Right,
Extensions = {new GridPositionExtension(1, 0)}
}.Setup(t => t.Bind(
t,
dc => dc.TotalProgress.Value,
t => t.Text,
v => $"{v}%")),
}
},
new ProgressBar<ICommandTimeStateViewModel>
{
Theme = new ProgressBarTheme
{
ForegroundColor = _progressBarTheme?.ForegroundColor,
UnfilledForeground = _progressBarTheme?.UnfilledForeground,
FilledCharacter = '\u2594',
UnfilledCharacter = '\u2594',
Fraction1Per8Character = '\u2594',
Fraction2Per8Character = '\u2594',
Fraction3Per8Character = '\u2594',
Fraction4Per8Character = '\u2594',
Fraction5Per8Character = '\u2594',
Fraction6Per8Character = '\u2594',
Fraction7Per8Character = '\u2594',
FractionFull = '\u2594',
},
Extensions =
{
new GridPositionExtension(0, 1)
}
}
.Setup(p => p.Bind(
p,
dc => dc.TotalProgress.Value,
p => p.Value)),
}
};

View File

@@ -1,9 +1,15 @@
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;
namespace FileTime.ConsoleUI.Styles;
using IConsoleTheme = TerminalUI.Styling.ITheme;
using ConsoleTheme = TerminalUI.Styling.Theme;
public record Theme(
IColor? DefaultForegroundColor,
IColor? DefaultForegroundAccentColor,
@@ -19,6 +25,7 @@ public record Theme(
IColor? WarningForegroundColor,
IColor? ErrorForegroundColor,
ListViewItemTheme ListViewItemTheme,
IConsoleTheme? ConsoleTheme,
Type? ForegroundColors,
Type? BackgroundColors) : ITheme, IColorSampleProvider;
@@ -42,6 +49,19 @@ public static class DefaultThemes
SelectedBackgroundColor: Color256Colors.Backgrounds.Gray,
SelectedForegroundColor: Color256Colors.Foregrounds.Black
),
ConsoleTheme: new ConsoleTheme
{
ControlThemes = new ControlThemes
{
ProgressBar = new ProgressBarTheme
{
ForegroundColor = Color256Colors.Foregrounds.Blue,
BackgroundColor = Color256Colors.Backgrounds.Gray,
UnfilledForeground = Color256Colors.Foregrounds.Gray,
UnfilledBackground = Color256Colors.Backgrounds.Gray,
}
}
},
ForegroundColors: typeof(Color256Colors.Foregrounds),
BackgroundColors: typeof(Color256Colors.Backgrounds)
);
@@ -64,6 +84,19 @@ public static class DefaultThemes
SelectedBackgroundColor: ConsoleColors.Backgrounds.Gray,
SelectedForegroundColor: ConsoleColors.Foregrounds.Black
),
ConsoleTheme: new ConsoleTheme
{
ControlThemes = new ControlThemes
{
ProgressBar = new ProgressBarTheme
{
ForegroundColor = ConsoleColors.Foregrounds.Blue,
BackgroundColor = ConsoleColors.Backgrounds.Gray,
UnfilledForeground = ConsoleColors.Foregrounds.Gray,
UnfilledBackground = ConsoleColors.Backgrounds.Gray
}
}
},
ForegroundColors: typeof(ConsoleColors.Foregrounds),
BackgroundColors: typeof(ConsoleColors.Backgrounds)
);

View File

@@ -9,8 +9,13 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Serilog;
using Serilog.Debugging;
using TerminalUI;
using TerminalUI.Color;
using TerminalUI.ConsoleDrivers;
using TerminalUI.Styling;
using ITheme = FileTime.ConsoleUI.App.Styling.ITheme;
Console.OutputEncoding = System.Text.Encoding.UTF8;
IConsoleDriver? driver = null;
(AppDataRoot, EnvironmentName) = Init.InitDevelopment();
@@ -27,6 +32,11 @@ try
Log.Logger.Debug("Using driver {Driver}", driver.GetType().Name);
driver.SetCursorVisible(false);
var applicationContext = serviceProvider.GetRequiredService<IApplicationContext>();
var theme = serviceProvider.GetRequiredService<ITheme>();
applicationContext.Theme = theme.ConsoleTheme;
var app = serviceProvider.GetRequiredService<IApplication>();
app.Run();