2025-12-10 20:55:38 -06:00
|
|
|
@using LANCommander.SDK.PowerShell
|
2025-12-10 21:46:46 -06:00
|
|
|
@using LANCommander.SDK.Services
|
2025-12-10 20:55:38 -06:00
|
|
|
@using LANCommander.Server.Services.PowerShell
|
|
|
|
|
@using XtermBlazor
|
|
|
|
|
@using LogLevel = Microsoft.Extensions.Logging.LogLevel
|
2025-12-10 21:46:46 -06:00
|
|
|
@inject ScriptDebugger ScriptDebugger
|
|
|
|
|
@inject ScriptClient ScriptClient
|
|
|
|
|
@inject GameService GameService
|
2025-12-10 20:55:38 -06:00
|
|
|
|
2025-12-10 21:46:46 -06:00
|
|
|
<div class="terminal @(Active ? "" : "hidden")">
|
2026-01-07 18:24:24 -06:00
|
|
|
<Terminal @ref="_terminal" Id="@Id.ToString()" Options="_options" />
|
2025-12-10 20:55:38 -06:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
@code {
|
2025-12-10 21:46:46 -06:00
|
|
|
[Parameter] public Guid Id { get; set; }
|
|
|
|
|
[Parameter] public bool Active { get; set; }
|
|
|
|
|
[Parameter] public EventCallback<bool> ActiveChanged { get; set; }
|
|
|
|
|
|
2026-01-04 00:03:31 -06:00
|
|
|
private Terminal? _terminal;
|
2025-12-10 20:55:38 -06:00
|
|
|
|
2026-01-04 00:03:31 -06:00
|
|
|
private readonly TerminalOptions _options = new()
|
2025-12-10 20:55:38 -06:00
|
|
|
{
|
|
|
|
|
CursorBlink = true,
|
|
|
|
|
CursorStyle = CursorStyle.Bar,
|
|
|
|
|
};
|
|
|
|
|
|
2025-12-10 21:46:46 -06:00
|
|
|
async Task SetActive(bool active)
|
|
|
|
|
{
|
|
|
|
|
Active = active;
|
|
|
|
|
|
|
|
|
|
if (ActiveChanged.HasDelegate)
|
|
|
|
|
await ActiveChanged.InvokeAsync(Active);
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-10 20:55:38 -06:00
|
|
|
public async Task DebugPackagingScript(Guid gameId)
|
|
|
|
|
{
|
2025-12-10 21:46:46 -06:00
|
|
|
ScriptDebugger.OnBreak = Break;
|
|
|
|
|
ScriptDebugger.OnStart = Start;
|
|
|
|
|
ScriptDebugger.OnEnd = End;
|
|
|
|
|
ScriptDebugger.OnOutput = Output;
|
|
|
|
|
|
|
|
|
|
ScriptClient.Debug = true;
|
|
|
|
|
|
|
|
|
|
await GameService.PackageAsync(gameId);
|
2025-12-10 20:55:38 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task Start(IScriptDebugContext context)
|
|
|
|
|
{
|
2026-01-04 00:03:31 -06:00
|
|
|
if (_terminal is null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
await _terminal.Clear();
|
2025-12-10 21:46:46 -06:00
|
|
|
await SetActive(true);
|
2025-12-10 20:55:38 -06:00
|
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
|
|
2026-01-04 00:03:31 -06:00
|
|
|
await _terminal.Focus();
|
|
|
|
|
await _terminal.FitAsync();
|
2025-12-10 20:55:38 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task End(IScriptDebugContext context)
|
|
|
|
|
{
|
2025-12-10 21:46:46 -06:00
|
|
|
await SetActive(false);
|
2025-12-10 20:55:38 -06:00
|
|
|
await InvokeAsync(StateHasChanged);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task Break(IScriptDebugContext context)
|
|
|
|
|
{
|
2026-01-04 00:03:31 -06:00
|
|
|
if (_terminal is null)
|
|
|
|
|
return;
|
|
|
|
|
|
2025-12-10 20:55:38 -06:00
|
|
|
while (true)
|
|
|
|
|
{
|
2026-01-04 00:03:31 -06:00
|
|
|
var input = await _terminal.ReadLineAsync();
|
2025-12-10 20:55:38 -06:00
|
|
|
|
|
|
|
|
if (input.Trim().Equals("exit", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (input.StartsWith('$'))
|
|
|
|
|
input = "Write-Host " + input;
|
|
|
|
|
|
|
|
|
|
await context.ExecuteAsync(input);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task Output(IScriptDebugContext context, LogLevel level, string message)
|
|
|
|
|
{
|
2026-01-04 00:03:31 -06:00
|
|
|
if (_terminal is null)
|
|
|
|
|
return;
|
|
|
|
|
|
2025-12-10 21:46:46 -06:00
|
|
|
try
|
2025-12-10 20:55:38 -06:00
|
|
|
{
|
2026-01-04 00:03:31 -06:00
|
|
|
await _terminal.WriteLine(message, level);
|
2025-12-10 21:46:46 -06:00
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
|
2025-12-10 20:55:38 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|