Console improvements, info providers

This commit is contained in:
2023-08-09 23:24:30 +02:00
parent 7dcca6363b
commit af140ff6b4
21 changed files with 406 additions and 69 deletions

View File

@@ -50,7 +50,7 @@ public class App : IApplication
((INotifyCollectionChanged) _appState.Tabs).CollectionChanged += (_, _) =>
{
if(_appState.Tabs.Count == 0)
if (_appState.Tabs.Count == 0)
_applicationContext.IsRunning = false;
};
@@ -68,13 +68,21 @@ public class App : IApplication
if (_consoleDriver.CanRead())
{
var key = _consoleDriver.ReadKey();
if (_appKeyService.MapKey(key.Key) is { } mappedKey)
{
SpecialKeysStatus specialKeysStatus = new(
(key.Modifiers & ConsoleModifiers.Alt) != 0,
(key.Modifiers & ConsoleModifiers.Shift) != 0,
(key.Modifiers & ConsoleModifiers.Control) != 0
);
var keyEventArgs = new GeneralKeyEventArgs
{
Key = mappedKey
};
_keyInputHandlerService.HandleKeyInput(keyEventArgs);
_keyInputHandlerService.HandleKeyInput(keyEventArgs, specialKeysStatus);
}
}

View File

@@ -10,9 +10,6 @@ public class KeyInputHandlerService : IKeyInputHandlerService
private readonly IAppState _appState;
private readonly IDefaultModeKeyInputHandler _defaultModeKeyInputHandler;
private readonly IRapidTravelModeKeyInputHandler _rapidTravelModeKeyInputHandler;
bool _isCtrlPressed = false;
bool _isShiftPressed = false;
bool _isAltPressed = false;
public KeyInputHandlerService(
IAppState appState,
@@ -24,9 +21,8 @@ public class KeyInputHandlerService : IKeyInputHandlerService
_rapidTravelModeKeyInputHandler = rapidTravelModeKeyInputHandler;
}
public void HandleKeyInput(GeneralKeyEventArgs keyEvent)
public void HandleKeyInput(GeneralKeyEventArgs keyEvent, SpecialKeysStatus specialKeysStatus)
{
var specialKeysStatus = new SpecialKeysStatus(_isAltPressed, _isShiftPressed, _isCtrlPressed);
if (_appState.ViewMode.Value == ViewMode.Default)
{
Task.Run(async () => await _defaultModeKeyInputHandler.HandleInputKey(keyEvent, specialKeysStatus)).Wait();

View File

@@ -6,6 +6,7 @@ using TerminalUI;
using TerminalUI.Color;
using TerminalUI.Controls;
using TerminalUI.Extensions;
using TerminalUI.Models;
using TerminalUI.ViewExtensions;
using ConsoleColor = TerminalUI.Color.ConsoleColor;
@@ -38,15 +39,23 @@ public class MainWindow
RowDefinitionsObject = "Auto *",
ChildInitializer =
{
new TextBlock<IAppState>()
.Setup(t =>
t.Bind(
t,
appState => appState.SelectedTab.Value.CurrentLocation.Value.FullName.Path,
tb => tb.Text,
value => value
)
),
new Grid<IAppState>
{
ColumnDefinitionsObject = "* Auto",
ChildInitializer =
{
new TextBlock<IAppState>()
.Setup(t =>
t.Bind(
t,
appState => appState.SelectedTab.Value.CurrentLocation.Value.FullName.Path,
tb => tb.Text,
value => value
)
),
TabControl()
}
},
new Grid<IAppState>
{
ColumnDefinitionsObject = "* 4* 4*",
@@ -66,6 +75,44 @@ public class MainWindow
_root = root;
}
private IView<IAppState> TabControl()
{
var tabList = new ListView<IAppState, ITabViewModel>
{
Orientation = Orientation.Horizontal,
Extensions =
{
new GridPositionExtension(1, 0)
},
ItemTemplate = item =>
{
var textBlock = item.CreateChild<TextBlock<ITabViewModel>>();
textBlock.Foreground = _theme.DefaultForegroundColor;
textBlock.Bind(
textBlock,
dc => dc.TabNumber.ToString(),
tb => tb.Text,
fallbackValue: "?");
textBlock.Bind(
textBlock,
dc => dc.IsSelected.Value ? _theme.SelectedTabBackgroundColor : null,
tb => tb.Background,
fallbackValue: null
);
return textBlock;
}
};
tabList.Bind(
tabList,
appState => appState == null ? null : appState.Tabs,
v => v.ItemsSource);
return tabList;
}
private ListView<IAppState, IItemViewModel> SelectedItemsView()
{
var list = new ListView<IAppState, IItemViewModel>