Skip to content

Commit 31c74d7

Browse files
committed
Made partial updates to drastically speed up printing large amounts of different colored ANSI text to the screen in one large burst.
1 parent 58e8894 commit 31c74d7

File tree

2 files changed

+37
-18
lines changed

2 files changed

+37
-18
lines changed

Org.Edgerunner.Moo.Editor/Controls/ConsoleWindowEmulator.cs

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ protected override void OnLoad(EventArgs e)
7676
WordWrapMode = WordWrapMode.WordWrapControlWidth;
7777
PreferredLineWidth = 0;
7878
ReadOnly = true;
79+
FoldingHighlightEnabled = false;
80+
HighlightFoldingIndicator = false;
81+
ShowFoldingLines = false;
7982
var testStyle = new TextStyle(new SolidBrush(Color.Red), null, FontStyle.Regular);
8083
}
8184

@@ -137,28 +140,36 @@ public void WriteLine(string text, Style style)
137140
public void WriteAnsi(string text)
138141
{
139142
// Match Ansi color codes and process them
140-
var match = Regex.Match(text, @"\e\[(?<codes>(\d+;)*\d+);*m");
141-
while (match.Captures.Count != 0)
143+
try
142144
{
143-
var codes = match.Groups["codes"].Value;
144-
if (match.Index != 0)
145+
SuspendLayout();
146+
var match = Regex.Match(text, @"\e\[(?<codes>(\d+;)*\d+);*m");
147+
while (match.Captures.Count != 0)
145148
{
149+
var codes = match.Groups["codes"].Value;
150+
if (match.Index != 0)
151+
{
152+
if (AnsiManager.Blinking)
153+
WriteWithStyles(text[..(match.Index)], new Style[] { CurrentStyle, DefaultBlinkingStyle });
154+
else
155+
Write(text[..(match.Index)], CurrentStyle);
156+
}
157+
CurrentStyle = AnsiManager.ProcessCodes(codes.Split(';').ToList().Select(int.Parse).ToList());
158+
text = match.Index + match.Length < text.Length ? text[(match.Index + match.Length)..] : string.Empty;
159+
match = Regex.Match(text, @"\e\[(?<codes>(\d+;)*\d+);*m");
160+
}
161+
162+
if (!string.IsNullOrEmpty(text))
146163
if (AnsiManager.Blinking)
147-
WriteWithStyles(text[..(match.Index)], new Style[] {CurrentStyle, DefaultBlinkingStyle });
164+
WriteWithStyles(text, new Style[] { CurrentStyle, DefaultBlinkingStyle });
148165
else
149-
Write(text[..(match.Index)], CurrentStyle);
150-
Application.DoEvents();
151-
}
152-
CurrentStyle = AnsiManager.ProcessCodes(codes.Split(';').ToList().Select(int.Parse).ToList());
153-
text = match.Index + match.Length < text.Length ? text[(match.Index + match.Length)..] : string.Empty;
154-
match = Regex.Match(text, @"\e\[(?<codes>(\d+;)*\d+);*m");
166+
Write(text, CurrentStyle);
167+
}
168+
finally
169+
{
170+
ResumeLayout();
171+
Application.DoEvents();
155172
}
156-
157-
if (!string.IsNullOrEmpty(text))
158-
if (AnsiManager.Blinking)
159-
WriteWithStyles(text, new Style[] {CurrentStyle, DefaultBlinkingStyle });
160-
else
161-
Write(text, CurrentStyle);
162173
}
163174

164175
/// <summary>

Org.Edgerunner.Moo.Editor/Controls/MooClientTerminal.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,15 @@ void SafeWrite()
623623
consoleSim.GoEnd();
624624
}
625625

626-
Invoke(SafeWrite);
626+
try
627+
{
628+
Invoke(SafeWrite);
629+
}
630+
catch (InvalidOperationException)
631+
{
632+
Debug.WriteLine("Our terminal was disposed of");
633+
return;
634+
}
627635
}
628636

629637
NewMessageReceived?.InvokeOnUI(new object[] { this, EventArgs.Empty });

0 commit comments

Comments
 (0)