refactor v2
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
@implements IDisposable
|
@implements IDisposable
|
||||||
|
|
||||||
<TerminalDisplay @ref="_terminalDisplayRef"/>
|
<TerminalDisplay @ref="@_terminalDisplayRef"/>
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
|
|
||||||
|
|||||||
@@ -1,40 +1,13 @@
|
|||||||
@using SharpIDE.Application.Features.Build
|
@using SharpIDE.Application.Features.Build
|
||||||
@using XtermBlazor
|
|
||||||
|
|
||||||
@inject BuildService BuildService
|
@inject BuildService BuildService
|
||||||
|
|
||||||
@implements IDisposable
|
@implements IDisposable
|
||||||
<style>
|
|
||||||
.xterm-underline-5.xterm-underline-5 { /* Specificity hack lol */
|
|
||||||
text-decoration: dotted underline;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<div style="width: 100%; height: 100%; overflow: auto">
|
<TerminalDisplay @ref="@_terminalDisplayRef"/>
|
||||||
<MudText>Terminal</MudText>
|
|
||||||
<Xterm @ref="@_terminalRef" Options="@_options" Style="height: calc(100% - 24px)" Addons="@_addons" OnFirstRender="@OnFirstRender"/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
private Xterm _terminalRef;
|
private TerminalDisplay _terminalDisplayRef = null!;
|
||||||
|
|
||||||
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<string> _addons = ["addon-fit"];
|
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
@@ -45,7 +18,7 @@
|
|||||||
{
|
{
|
||||||
await foreach (var logLine in BuildService.BuildTextWriter.ConsoleChannel.Reader.ReadAllAsync())
|
await foreach (var logLine in BuildService.BuildTextWriter.ConsoleChannel.Reader.ReadAllAsync())
|
||||||
{
|
{
|
||||||
await _terminalRef.Write(logLine);
|
await _terminalDisplayRef.Write(logLine);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@@ -57,33 +30,9 @@
|
|||||||
|
|
||||||
private async Task ClearPreviousOutput()
|
private async Task ClearPreviousOutput()
|
||||||
{
|
{
|
||||||
await _terminalRef.Clear();
|
await _terminalDisplayRef.Clear();
|
||||||
await InvokeAsync(StateHasChanged);
|
await InvokeAsync(StateHasChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose() => BuildService.BuildStarted -= ClearPreviousOutput;
|
public void Dispose() => BuildService.BuildStarted -= ClearPreviousOutput;
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user