From 96eb0c07bffe00b89bc96b9c8e4d2d398cced025 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81d=C3=A1m=20Kov=C3=A1cs?= Date: Mon, 27 May 2024 07:59:13 +0200 Subject: [PATCH] Debugger symbol for ConsoleApp --- .../IRootViewModel.cs | 1 + src/ConsoleApp/FileTime.ConsoleUI.App/MainWindow.cs | 12 +++++++++++- .../FileTime.ConsoleUI.App/RootViewModel.cs | 10 ++++++++-- src/Library/TerminalUI/RenderEngine.cs | 4 ++++ src/Library/TerminalUI/Traits/IBeforeRender.cs | 6 ++++++ 5 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 src/Library/TerminalUI/Traits/IBeforeRender.cs diff --git a/src/ConsoleApp/FileTime.ConsoleUI.App.Abstractions/IRootViewModel.cs b/src/ConsoleApp/FileTime.ConsoleUI.App.Abstractions/IRootViewModel.cs index cc387f3..d8b565a 100644 --- a/src/ConsoleApp/FileTime.ConsoleUI.App.Abstractions/IRootViewModel.cs +++ b/src/ConsoleApp/FileTime.ConsoleUI.App.Abstractions/IRootViewModel.cs @@ -25,5 +25,6 @@ public interface IRootViewModel IItemPreviewService ItemPreviewService { get; } IClipboardService ClipboardService { get; } IAdminElevationManager AdminElevationManager { get; } + IDeclarativeProperty IsDebuggerAttached { get; } event Action? FocusReadInputElement; } \ No newline at end of file diff --git a/src/ConsoleApp/FileTime.ConsoleUI.App/MainWindow.cs b/src/ConsoleApp/FileTime.ConsoleUI.App/MainWindow.cs index bde95fa..be86339 100644 --- a/src/ConsoleApp/FileTime.ConsoleUI.App/MainWindow.cs +++ b/src/ConsoleApp/FileTime.ConsoleUI.App/MainWindow.cs @@ -1,4 +1,5 @@ -using System.Globalization; +using System.Diagnostics; +using System.Globalization; using FileTime.App.Core.Models.Enums; using FileTime.App.Core.ViewModels; using FileTime.ConsoleUI.App.Configuration; @@ -172,6 +173,15 @@ public class MainWindow }.Setup(t => t.Bind( t, dc => dc!.ClipboardService.Content.Count > 1, + tb => tb.IsVisible)), + new TextBlock + { + Text = /*_consoleApplicationConfiguration.Value.ClipboardMultipleIcon ??*/ + (_consoleApplicationConfiguration.Value.DisableUtf8 ? "DB " : "\udb80\udce4"), + AsciiOnly = false + }.Setup(t => t.Bind( + t, + dc => dc.IsDebuggerAttached.Value, tb => tb.IsVisible)) } }, diff --git a/src/ConsoleApp/FileTime.ConsoleUI.App/RootViewModel.cs b/src/ConsoleApp/FileTime.ConsoleUI.App/RootViewModel.cs index 1598b69..c9c2e06 100644 --- a/src/ConsoleApp/FileTime.ConsoleUI.App/RootViewModel.cs +++ b/src/ConsoleApp/FileTime.ConsoleUI.App/RootViewModel.cs @@ -1,4 +1,5 @@ -using DeclarativeProperty; +using System.Diagnostics; +using DeclarativeProperty; using FileTime.App.CommandPalette.ViewModels; using FileTime.App.Core.Services; using FileTime.App.Core.ViewModels; @@ -8,11 +9,13 @@ using FileTime.ConsoleUI.App.Services; using FileTime.Core.Interactions; using FileTime.Core.Models; using FileTime.Providers.LocalAdmin; +using TerminalUI.Traits; namespace FileTime.ConsoleUI.App; -public partial class RootViewModel : IRootViewModel +public partial class RootViewModel : IRootViewModel, IBeforeRender { + private readonly DeclarativeProperty _isDebuggerAttached = new(Debugger.IsAttached); public string UserName => Environment.UserName; public string MachineName => Environment.MachineName; public IPossibleCommandsViewModel PossibleCommands { get; } @@ -25,6 +28,7 @@ public partial class RootViewModel : IRootViewModel public IDialogService DialogService { get; } public ITimelineViewModel TimelineViewModel { get; } public IDeclarativeProperty VolumeSizeInfo { get; } + public IDeclarativeProperty IsDebuggerAttached => _isDebuggerAttached; public event Action? FocusReadInputElement; @@ -73,4 +77,6 @@ public partial class RootViewModel : IRootViewModel .Switch() .Map(async l => l is null ? null : await l.Provider.GetVolumeSizeInfoAsync(l.FullName!)); } + + public void BeforeRender() => _isDebuggerAttached.SetValue(Debugger.IsAttached); } \ No newline at end of file diff --git a/src/Library/TerminalUI/RenderEngine.cs b/src/Library/TerminalUI/RenderEngine.cs index 548270c..11199d2 100644 --- a/src/Library/TerminalUI/RenderEngine.cs +++ b/src/Library/TerminalUI/RenderEngine.cs @@ -209,6 +209,10 @@ public class RenderEngine : IRenderEngine { view.Attached = true; view.GetRequestedSize(); + if (view.DataContext is IBeforeRender beforeRenderHandler) + { + beforeRenderHandler.BeforeRender(); + } view.Render(renderContext, position, size); } catch (Exception e) diff --git a/src/Library/TerminalUI/Traits/IBeforeRender.cs b/src/Library/TerminalUI/Traits/IBeforeRender.cs new file mode 100644 index 0000000..0cd5bb5 --- /dev/null +++ b/src/Library/TerminalUI/Traits/IBeforeRender.cs @@ -0,0 +1,6 @@ +namespace TerminalUI.Traits; + +public interface IBeforeRender +{ + void BeforeRender(); +} \ No newline at end of file