make terminal write synchronous

This commit is contained in:
Matt Parker
2026-01-19 19:29:01 +10:00
parent 67b875e72d
commit 3ada44e439
3 changed files with 5 additions and 7 deletions

View File

@@ -37,7 +37,7 @@ public partial class DebugPanelTab : Control
{ {
await foreach (var array in Project.RunningOutputChannel!.Reader.ReadAllAsync().ConfigureAwait(false)) await foreach (var array in Project.RunningOutputChannel!.Reader.ReadAllAsync().ConfigureAwait(false))
{ {
await _terminal.WriteAsync(array); _terminal.Write(array);
} }
}); });
} }

View File

@@ -28,7 +28,7 @@ public partial class RunPanelTab : Control
{ {
await foreach (var array in Project.RunningOutputChannel!.Reader.ReadAllAsync().ConfigureAwait(false)) await foreach (var array in Project.RunningOutputChannel!.Reader.ReadAllAsync().ConfigureAwait(false))
{ {
await _terminal.WriteAsync(array); _terminal.Write(array);
} }
}); });
} }

View File

@@ -12,19 +12,18 @@ public partial class SharpIdeTerminal : Control
var terminalControl = GetNode<Control>("Terminal"); var terminalControl = GetNode<Control>("Terminal");
_terminal = new Terminal(terminalControl); _terminal = new Terminal(terminalControl);
} }
[RequiresGodotUiThread]
public void Write(string text) public void Write(string text)
{ {
_terminal.Write(text); _terminal.Write(text);
} }
public async Task WriteAsync(byte[] text) public void Write(byte[] text)
{ {
var (processedArray, length, wasRented) = ProcessLineEndings(text); var (processedArray, length, wasRented) = ProcessLineEndings(text);
try try
{ {
await this.InvokeAsync(() => _terminal.Write(processedArray.AsSpan(0, length))); _terminal.Write(processedArray.AsSpan(0, length));
} }
finally finally
{ {
@@ -36,7 +35,6 @@ public partial class SharpIdeTerminal : Control
_previousArrayEndedInCr = text.Length > 0 && text[^1] == (byte)'\r'; _previousArrayEndedInCr = text.Length > 0 && text[^1] == (byte)'\r';
} }
[RequiresGodotUiThread]
public void ClearTerminal() public void ClearTerminal()
{ {
// .Clear removes all text except for the bottom row, so lets make sure we have a blank line, and cursor at start // .Clear removes all text except for the bottom row, so lets make sure we have a blank line, and cursor at start