@using LANCommander.Launcher.Services.PowerShell @using XtermBlazor @using LogLevel = Microsoft.Extensions.Logging.LogLevel @namespace LANCommander.Launcher.UI @inject ScriptDebugger Debugger
@code { [Parameter] public bool Visible { get; set; } [Parameter] public EventCallback VisibleChanged { get; set; } private Terminal? _terminal; private TerminalOptions _options = new() { CursorBlink = true, CursorStyle = CursorStyle.Bar, }; protected override void OnInitialized() { Debugger.OnDebugStart = async _ => { await InvokeAsync(async () => { if (_terminal is null) return; await _terminal.Clear(); Visible = true; if (VisibleChanged.HasDelegate) await VisibleChanged.InvokeAsync(Visible); StateHasChanged(); await _terminal.FitAsync(); }); }; Debugger.OnOutput = async (level, message) => { await InvokeAsync(async () => { if (_terminal is not null) await _terminal.WriteLine(message, level); }); }; Debugger.OnDebugBreak = async context => { await InvokeAsync(async () => { if (_terminal is null) return; while (true) { var input = await _terminal.ReadLineAsync(); if (input.Trim().Equals("exit", StringComparison.OrdinalIgnoreCase)) break; if (input.StartsWith('$')) input = "Write-Host " + input; await context.ExecuteAsync(input); } Visible = false; if (VisibleChanged.HasDelegate) await VisibleChanged.InvokeAsync(Visible); StateHasChanged(); }); }; } private async Task OnFirstRender() { if (_terminal is not null) await _terminal.FitAsync(); Debugger.SignalReady(); } }