@using LANCommander.Launcher.Services.PowerShell @using XtermBlazor @using LogLevel = Microsoft.Extensions.Logging.LogLevel @namespace LANCommander.Launcher.UI @inject ScriptDebugger Debugger
@code { private bool Visible { get; set; } private Terminal? _terminal; private TerminalOptions _options = new() { CursorBlink = true, CursorStyle = CursorStyle.Bar, }; protected override void OnInitialized() { Debugger.OnDebugStart = async _ => { if (_terminal is null) return; await _terminal.Clear(); Visible = true; await InvokeAsync(StateHasChanged); await _terminal.FitAsync(); }; Debugger.OnOutput = async (level, message) => { if (_terminal is not null) await _terminal.WriteLine(message, level); }; Debugger.OnDebugBreak = async context => { 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; await InvokeAsync(StateHasChanged); }; } private async Task OnFirstRender() { if (_terminal is not null) await _terminal.FitAsync(); } }