From 2b0518c9d8ec27da05f51b666787b96a64f70f65 Mon Sep 17 00:00:00 2001
From: Matt Parker <61717342+MattParkerDev@users.noreply.github.com>
Date: Sun, 10 Aug 2025 00:01:03 +1000
Subject: [PATCH] refactor to reusable terminal display
---
.../Components/RunOutputDisplay.razor | 71 ++-----------------
.../Components/TerminalDisplay.razor | 71 +++++++++++++++++++
2 files changed, 76 insertions(+), 66 deletions(-)
create mode 100644 src/SharpIDE.Photino/Components/TerminalDisplay.razor
diff --git a/src/SharpIDE.Photino/Components/RunOutputDisplay.razor b/src/SharpIDE.Photino/Components/RunOutputDisplay.razor
index 42d59fd..201e339 100644
--- a/src/SharpIDE.Photino/Components/RunOutputDisplay.razor
+++ b/src/SharpIDE.Photino/Components/RunOutputDisplay.razor
@@ -1,45 +1,16 @@
@using Ardalis.GuardClauses
-@using SharpIDE.Application.Features.Build
@using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence
-@using XtermBlazor
-
-@inject BuildService BuildService
@implements IDisposable
-
-
-
-
+
@code {
[Parameter, EditorRequired]
public SharpIdeProjectModel Project { get; set; } = null!;
- private Xterm _terminalRef;
-
- private readonly TerminalOptions _options = new TerminalOptions
- {
- CursorBlink = true,
- CursorStyle = CursorStyle.Bar,
- Columns = 140,
- FontFamily = "Cascadia Code",
- FontWeightBold = "400",
- Theme =
- {
- BrightGreen = "#98c379",
- BrightRed = "#e06c75",
- Foreground = "#dcdfe4",
- Background = "#282c34",
- },
- };
-
- private HashSet _addons = ["addon-fit"];
+ private TerminalDisplay _terminalDisplayRef = null!;
protected override async Task OnInitializedAsync()
{
@@ -52,14 +23,15 @@
{
Guard.Against.Null(Project);
Guard.Against.Null(Project.RunningOutputChannel, nameof(Project.RunningOutputChannel));
- await ClearPreviousOutput();
+ if (_terminalDisplayRef is not null) await _terminalDisplayRef.Clear();
_ = Task.Run(async () =>
{
try
{
await foreach (var log in Project.RunningOutputChannel.Reader.ReadAllAsync())
{
- await _terminalRef.Write(log);
+ // Better hope you don't get a log until we get the component ref lol
+ await _terminalDisplayRef.Write(log);
}
}
catch (Exception e)
@@ -69,38 +41,5 @@
});
}
- private async Task ClearPreviousOutput()
- {
- if (_terminalRef is not null)
- {
- await _terminalRef.Clear();
- await InvokeAsync(StateHasChanged);
- }
- }
-
public void Dispose() => Project.ProjectStartedRunning -= OnProjectStartedRunning;
-
- private async Task OnFirstRender()
- {
- await _terminalRef.Addon("addon-fit").InvokeVoidAsync("fit");
- _ = Task.Run(async () =>
- {
- try
- {
- while (true)
- {
- await Task.Delay(500).ConfigureAwait(false);
- await InvokeAsync(async () =>
- {
- await _terminalRef.Addon("addon-fit").InvokeVoidAsync("fit");
- });
- }
-
- }
- catch (Exception e)
- {
- await DispatchExceptionAsync(e);
- }
- });
- }
}
diff --git a/src/SharpIDE.Photino/Components/TerminalDisplay.razor b/src/SharpIDE.Photino/Components/TerminalDisplay.razor
new file mode 100644
index 0000000..d1d9679
--- /dev/null
+++ b/src/SharpIDE.Photino/Components/TerminalDisplay.razor
@@ -0,0 +1,71 @@
+@using XtermBlazor
+
+
+
+
+
+
+
+@code {
+ private Xterm _terminalRef;
+
+ private readonly TerminalOptions _options = new TerminalOptions
+ {
+ CursorBlink = true,
+ CursorStyle = CursorStyle.Bar,
+ Columns = 140,
+ FontFamily = "Cascadia Code",
+ FontWeightBold = "400",
+ Theme =
+ {
+ BrightGreen = "#98c379",
+ BrightRed = "#e06c75",
+ Foreground = "#dcdfe4",
+ Background = "#282c34",
+ },
+ };
+
+ private HashSet _addons = ["addon-fit"];
+
+ public async Task Write(string line)
+ {
+ await _terminalRef.Write(line);
+ }
+
+ public async Task Clear()
+ {
+ if (_terminalRef is not null)
+ {
+ await _terminalRef.Clear();
+ await InvokeAsync(StateHasChanged);
+ }
+ }
+
+ private async Task OnFirstRender()
+ {
+ await _terminalRef.Addon("addon-fit").InvokeVoidAsync("fit");
+ _ = Task.Run(async () =>
+ {
+ try
+ {
+ while (true)
+ {
+ await Task.Delay(500).ConfigureAwait(false);
+ await InvokeAsync(async () =>
+ {
+ await _terminalRef.Addon("addon-fit").InvokeVoidAsync("fit");
+ });
+ }
+
+ }
+ catch (Exception e)
+ {
+ await DispatchExceptionAsync(e);
+ }
+ });
+ }
+}