Console base WIP 2
This commit is contained in:
@@ -12,15 +12,17 @@ public class App : IApplication
|
||||
private readonly IConsoleAppState _consoleAppState;
|
||||
private readonly IAppKeyService<Key> _appKeyService;
|
||||
private readonly MainWindow _mainWindow;
|
||||
private readonly IKeyInputHandlerService _keyInputHandlerService = null!;
|
||||
private readonly IKeyInputHandlerService _keyInputHandlerService;
|
||||
|
||||
public App(
|
||||
ILifecycleService lifecycleService,
|
||||
IKeyInputHandlerService keyInputHandlerService,
|
||||
IConsoleAppState consoleAppState,
|
||||
IAppKeyService<Key> appKeyService,
|
||||
MainWindow mainWindow)
|
||||
{
|
||||
_lifecycleService = lifecycleService;
|
||||
_keyInputHandlerService = keyInputHandlerService;
|
||||
_consoleAppState = consoleAppState;
|
||||
_appKeyService = appKeyService;
|
||||
_mainWindow = mainWindow;
|
||||
@@ -28,6 +30,7 @@ public class App : IApplication
|
||||
|
||||
public void Run()
|
||||
{
|
||||
Console.WriteLine("Loading...");
|
||||
Task.Run(async () => await _lifecycleService.InitStartupHandlersAsync()).Wait();
|
||||
|
||||
_mainWindow.Initialize();
|
||||
@@ -41,14 +44,10 @@ public class App : IApplication
|
||||
|
||||
Application.RootKeyEvent += e =>
|
||||
{
|
||||
if (e.ToGeneralKeyEventArgs(_appKeyService) is { } args)
|
||||
{
|
||||
_keyInputHandlerService.HandleKeyInput(args);
|
||||
if (e.ToGeneralKeyEventArgs(_appKeyService) is not { } args) return false;
|
||||
_keyInputHandlerService.HandleKeyInput(args);
|
||||
|
||||
return args.Handled;
|
||||
}
|
||||
|
||||
return false;
|
||||
return args.Handled;
|
||||
};
|
||||
|
||||
Application.Run();
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
|
||||
<PackageReference Include="Serilog" Version="3.0.1" />
|
||||
<PackageReference Include="Terminal.Gui" Version="1.13.5" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -16,23 +16,24 @@ public class KeyInputHandlerService : IKeyInputHandlerService
|
||||
|
||||
public KeyInputHandlerService(
|
||||
IAppState appState,
|
||||
IDefaultModeKeyInputHandler defaultModeKeyInputHandler,
|
||||
IDefaultModeKeyInputHandler defaultModeKeyInputHandler,
|
||||
IRapidTravelModeKeyInputHandler rapidTravelModeKeyInputHandler)
|
||||
{
|
||||
_appState = appState;
|
||||
_defaultModeKeyInputHandler = defaultModeKeyInputHandler;
|
||||
_rapidTravelModeKeyInputHandler = rapidTravelModeKeyInputHandler;
|
||||
}
|
||||
|
||||
public void HandleKeyInput(GeneralKeyEventArgs keyEvent)
|
||||
{
|
||||
var specialKeysStatus = new SpecialKeysStatus(_isAltPressed, _isShiftPressed, _isCtrlPressed);
|
||||
if (_appState.ViewMode.Value == ViewMode.Default)
|
||||
{
|
||||
_defaultModeKeyInputHandler.HandleInputKey(keyEvent, specialKeysStatus);
|
||||
Task.Run(async () => await _defaultModeKeyInputHandler.HandleInputKey(keyEvent, specialKeysStatus)).Wait();
|
||||
}
|
||||
else
|
||||
{
|
||||
_rapidTravelModeKeyInputHandler.HandleInputKey(keyEvent, specialKeysStatus);
|
||||
Task.Run(async () => await _rapidTravelModeKeyInputHandler.HandleInputKey(keyEvent, specialKeysStatus)).Wait();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
using DeclarativeProperty;
|
||||
using System.Collections.ObjectModel;
|
||||
using DeclarativeProperty;
|
||||
using FileTime.App.Core.ViewModels;
|
||||
using FileTime.ConsoleUI.App.Controls;
|
||||
using FileTime.Core.Models;
|
||||
using ObservableComputations;
|
||||
using Terminal.Gui;
|
||||
|
||||
namespace FileTime.ConsoleUI.App;
|
||||
@@ -17,12 +19,12 @@ public class MainWindow
|
||||
|
||||
_selectedItemsView = new() {X = 1, Y = 0, Width = Dim.Fill(), Height = Dim.Fill()};
|
||||
_selectedItemsView.AddKeyBinding(Key.Space, Command.ToggleChecked);
|
||||
_selectedItemsView.OpenSelectedItem += (e) =>
|
||||
/*_selectedItemsView.OpenSelectedItem += (e) =>
|
||||
{
|
||||
if (e.Value is IItemViewModel {BaseItem: IContainer container}
|
||||
&& consoleAppState.SelectedTab.Value?.Tab is { } tab)
|
||||
tab.SetCurrentLocation(container);
|
||||
};
|
||||
};*/
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
@@ -32,6 +34,22 @@ public class MainWindow
|
||||
.Map(t => t.CurrentItems)
|
||||
.Switch();
|
||||
|
||||
var selectedItem = _consoleAppState.SelectedTab
|
||||
.Map(t => t.CurrentSelectedItem)
|
||||
.Switch();
|
||||
|
||||
DeclarativePropertyHelpers.CombineLatest(
|
||||
selectedItem,
|
||||
selectedsItems,
|
||||
(selected, items) => Task.FromResult(items.IndexOf(selected)))
|
||||
.Subscribe((index, _) =>
|
||||
{
|
||||
if (index == -1) return;
|
||||
_selectedItemsView.SelectedItem = index;
|
||||
_selectedItemsView.EnsureSelectedItemVisible();
|
||||
_selectedItemsView.SetNeedsDisplay();
|
||||
});
|
||||
|
||||
var renderer = new ItemRenderer(selectedsItems, _selectedItemsView);
|
||||
_selectedItemsView.Source = renderer;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
using System.Diagnostics;
|
||||
using Serilog.Core;
|
||||
using Serilog.Events;
|
||||
|
||||
namespace FileTime.ConsoleUI.App.Services;
|
||||
|
||||
public class CustomLoggerSink : ILogEventSink
|
||||
{
|
||||
public void Emit(LogEvent logEvent)
|
||||
{
|
||||
if (logEvent.Level >= LogEventLevel.Error)
|
||||
{
|
||||
var message = logEvent.RenderMessage();
|
||||
if (logEvent.Exception is not null)
|
||||
message += $" {logEvent.Exception.Message}";
|
||||
Debug.WriteLine(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using FileTime.App.Core.Services;
|
||||
using FileTime.Core.Models;
|
||||
using Terminal.Gui;
|
||||
|
||||
namespace FileTime.ConsoleUI.App.Services;
|
||||
|
||||
public class SystemClipboardService : ISystemClipboardService
|
||||
{
|
||||
public Task CopyToClipboardAsync(string text)
|
||||
{
|
||||
Clipboard.TrySetClipboardData(text);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task<IEnumerable<FullName>> GetFilesAsync() => throw new NotImplementedException();
|
||||
|
||||
public Task SetFilesAsync(IEnumerable<FullName> files) => throw new NotImplementedException();
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using FileTime.App.Core.Services;
|
||||
using FileTime.App.Core.ViewModels;
|
||||
using FileTime.ConsoleUI.App.KeyInputHandling;
|
||||
using FileTime.ConsoleUI.App.Services;
|
||||
using FileTime.Core.Interactions;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
@@ -19,6 +20,8 @@ public static class Startup
|
||||
services.TryAddSingleton<IUserCommunicationService, ConsoleUserCommunicationService>();
|
||||
services.TryAddSingleton<IKeyInputHandlerService, KeyInputHandlerService>();
|
||||
services.TryAddSingleton<IAppKeyService<Key>, ConsoleAppKeyService>();
|
||||
services.TryAddSingleton<ISystemClipboardService, SystemClipboardService>();
|
||||
services.AddSingleton<CustomLoggerSink>();
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user