write to console on run

This commit is contained in:
Matt Parker
2025-08-25 18:53:24 +10:00
parent feffc0d7a8
commit 31884214bc
4 changed files with 61 additions and 4 deletions

View File

@@ -1,3 +1,6 @@
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Threading.Tasks;
using GDExtensionBindgen;
using Godot;
using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence;
@@ -7,16 +10,36 @@ namespace SharpIDE.Godot.Features.Run;
public partial class RunPanelTab : Control
{
private Terminal _terminal = null!;
private Task _writeTask = Task.CompletedTask;
public SharpIdeProjectModel Project { get; set; } = null!;
public int TabBarTab { get; set; }
public override void _Ready()
{
_terminal = new Terminal();
AddChild(_terminal);
var terminalControl = GetNode<Control>("Terminal");
_terminal = new Terminal(terminalControl);
}
public void StartWritingFromProjectOutput()
{
if (_writeTask.IsCompleted is not true)
{
GD.PrintErr("Attempted to start writing from project output, but a write task is already running.");
return;
}
_writeTask = GodotTask.Run(async () =>
{
await foreach (var array in Project.RunningOutputChannel!.Reader.ReadAllAsync().ConfigureAwait(false))
{
//_terminal.Write(array);
//await this.InvokeAsync(() => _terminal.Write(array));
var str = System.Text.Encoding.UTF8.GetString(array);
await this.InvokeAsync(() => _terminal.Write(str));
}
});
}
public void ClearTerminal()
{
_terminal.Clear();