optimise build log output
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Threading.Channels;
|
||||
using GDExtensionBindgen;
|
||||
using Godot;
|
||||
|
||||
@@ -6,28 +7,26 @@ namespace SharpIDE.Godot.Features.Build;
|
||||
public partial class BuildPanel : Control
|
||||
{
|
||||
private Terminal _terminal = null!;
|
||||
private Task _writeTask = Task.CompletedTask;
|
||||
private ChannelReader<string>? _buildOutputChannelReader;
|
||||
public override void _Ready()
|
||||
{
|
||||
_terminal = new Terminal(GetNode<Control>("%Terminal"));
|
||||
Singletons.BuildService.BuildStarted += OnBuildStarted;
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (_buildOutputChannelReader is null) return;
|
||||
// TODO: Buffer and write once per frame? Investigate if godot-xterm already buffers internally
|
||||
while (_buildOutputChannelReader.TryRead(out var str))
|
||||
{
|
||||
_terminal.Write(str);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task OnBuildStarted()
|
||||
{
|
||||
if (_writeTask.IsCompleted is not true)
|
||||
{
|
||||
// If the write task is already running, just clear the terminal - we reuse the channel for the build output 🤷♂️
|
||||
await this.InvokeAsync(() => _terminal.Clear());
|
||||
return;
|
||||
}
|
||||
_writeTask = Task.GodotRun(async () =>
|
||||
{
|
||||
await this.InvokeAsync(() => _terminal.Clear());
|
||||
await foreach (var str in Singletons.BuildService.BuildTextWriter.ConsoleChannel.Reader.ReadAllAsync().ConfigureAwait(false))
|
||||
{
|
||||
await this.InvokeAsync(() => _terminal.Write(str));
|
||||
}
|
||||
});
|
||||
await this.InvokeAsync(() => _terminal.Clear());
|
||||
_buildOutputChannelReader ??= Singletons.BuildService.BuildTextWriter.ConsoleChannel.Reader;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user