diff --git a/Robust.Client/Console/Completions.cs b/Robust.Client/Console/Completions.cs index bc601c075e8..4f9a0c8d63f 100644 --- a/Robust.Client/Console/Completions.cs +++ b/Robust.Client/Console/Completions.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Collections.Immutable; using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.CustomControls; @@ -83,7 +84,7 @@ public Entry(LiteResult result) { MouseFilter = MouseFilterMode.Stop; Result = result; - var compl = new FormattedMessage.Builder(); + var compl = new List
(); var dim = Color.FromHsl((0f, 0f, 0.8f, 1f)); // warning: ew ahead @@ -106,21 +107,26 @@ public Entry(LiteResult result) basen = "field name"; Color basec = ScriptingColorScheme.ColorScheme[basen]; - compl.PushColor(basec * dim); - compl.AddText(Result.DisplayTextPrefix); - compl.PushColor(basec); - compl.AddText(Result.DisplayText); - compl.PushColor(basec * dim); - compl.AddText(Result.DisplayTextSuffix); - compl.AddText(" [" + String.Join(", ", Result.Tags) + "]"); + Color dimmed = basec * dim; + compl.AddRange(new [] + { + new Section() { Color=dimmed.ToArgb(), Content=Result.DisplayTextPrefix }, + new Section() { Color=basec.ToArgb(), Content=Result.DisplayText }, + new Section() { Color=dimmed.ToArgb(), Content=Result.DisplayTextSuffix } + } + ); + + compl.Add(new Section() { Color=dimmed.ToArgb(), Content=" [" + String.Join(", ", Result.Tags) + "]" }); if (Result.InlineDescription.Length != 0) { - compl.PushNewline(); - compl.AddText(": "); - compl.PushColor(Color.LightSlateGray); - compl.AddText(Result.InlineDescription); + compl.AddRange(new [] + { + new Section() { Color=(basec * dim).ToArgb(), Content="\n: " }, + new Section() { Color=Color.LightSlateGray.ToArgb(), Content=Result.InlineDescription } + } + ); } - SetMessage(compl.Build()); + SetMessage(new FormattedMessage(compl.ToArray())); } } } diff --git a/Robust.Client/Console/ScriptClient.ScriptConsoleServer.cs b/Robust.Client/Console/ScriptClient.ScriptConsoleServer.cs index 73e0031501a..c27efdaf57f 100644 --- a/Robust.Client/Console/ScriptClient.ScriptConsoleServer.cs +++ b/Robust.Client/Console/ScriptClient.ScriptConsoleServer.cs @@ -1,6 +1,5 @@ using Robust.Client.UserInterface.CustomControls; using Robust.Shared.Localization; -using Robust.Shared.Maths; using Robust.Shared.Network.Messages; using Robust.Shared.Utility; @@ -95,11 +94,13 @@ public void ReceiveResponse(MsgScriptResponse response) _linesEntered = 0; // Echo entered script. - var echoMessage = new FormattedMessage.Builder(); - echoMessage.PushColor(Color.FromHex("#D4D4D4")); - echoMessage.AddText("> "); - echoMessage.AddMessage(response.Echo); - OutputPanel.AddMessage(echoMessage.Build()); + OutputPanel.AddMessage(new FormattedMessage(new [] + { + new Section() { Color=unchecked((int) 0xFFD4D4D4), Content="> " }, + } + )); + + OutputPanel.AddMessage(response.Echo); OutputPanel.AddMessage(response.Response); diff --git a/Robust.Client/Console/ScriptConsoleClient.cs b/Robust.Client/Console/ScriptConsoleClient.cs index 62df23c189f..9a408911086 100644 --- a/Robust.Client/Console/ScriptConsoleClient.cs +++ b/Robust.Client/Console/ScriptConsoleClient.cs @@ -128,12 +128,11 @@ protected override async void Run() newScript.Compile(); // Echo entered script. - var echoMessage = new FormattedMessage.Builder(); - echoMessage.PushColor(Color.FromHex("#D4D4D4")); - echoMessage.AddText("> "); + var echoMessage = new List
(); + echoMessage.Add(new Section() { Color=unchecked((int) 0xFFD4D4D4), Content="> " }); ScriptInstanceShared.AddWithSyntaxHighlighting(newScript, echoMessage, code, _highlightWorkspace); - OutputPanel.AddMessage(echoMessage.Build()); + OutputPanel.AddMessage(new FormattedMessage(echoMessage.ToArray())); try { @@ -148,17 +147,17 @@ protected override async void Run() } catch (CompilationErrorException e) { - var msg = new FormattedMessage.Builder(); - - msg.PushColor(Color.Crimson); + var strb = new StringBuilder(); foreach (var diagnostic in e.Diagnostics) - { - msg.AddText(diagnostic.ToString()); - msg.AddText("\n"); - } + strb.Append(diagnostic.ToString() + "\n"); + + OutputPanel.AddMessage(new FormattedMessage(new [] + { + new Section() { Color=Color.Crimson.ToArgb(), Content=strb.ToString() } + } + )); - OutputPanel.AddMessage(msg.Build()); OutputPanel.AddText(">"); PromptAutoImports(e.Diagnostics, code); @@ -167,16 +166,19 @@ protected override async void Run() if (_state.Exception != null) { - var msg = new FormattedMessage.Builder(); - msg.PushColor(Color.Crimson); - msg.AddText(CSharpObjectFormatter.Instance.FormatException(_state.Exception)); - OutputPanel.AddMessage(msg.Build()); + OutputPanel.AddMessage(new FormattedMessage(new [] + { + new Section() { Color=Color.Crimson.ToArgb(), Content=CSharpObjectFormatter.Instance.FormatException(_state.Exception) } + } + )); } else if (ScriptInstanceShared.HasReturnValue(newScript)) { - var msg = new FormattedMessage.Builder(); - msg.AddText(ScriptInstanceShared.SafeFormat(_state.ReturnValue)); - OutputPanel.AddMessage(msg.Build()); + OutputPanel.AddMessage(new FormattedMessage(new [] + { + new Section() { Content=ScriptInstanceShared.SafeFormat(_state.ReturnValue) } + } + )); } OutputPanel.AddText(">"); diff --git a/Robust.Client/Log/DebugConsoleLogHandler.cs b/Robust.Client/Log/DebugConsoleLogHandler.cs index 9935af0ee18..a47db5a5921 100644 --- a/Robust.Client/Log/DebugConsoleLogHandler.cs +++ b/Robust.Client/Log/DebugConsoleLogHandler.cs @@ -1,4 +1,5 @@ -using Robust.Client.Console; +using System.Collections.Generic; +using Robust.Client.Console; using Robust.Shared.Log; using Robust.Shared.Maths; using Robust.Shared.Utility; @@ -23,24 +24,21 @@ public void Log(string sawmillName, LogEvent message) if (sawmillName == "CON") return; - var formatted = new FormattedMessage.Builder(); + var formatted = new List
(); var robustLevel = message.Level.ToRobust(); - formatted.PushColor(Color.DarkGray); - formatted.AddText("["); - formatted.PushColor(LogLevelToColor(robustLevel)); - formatted.AddText(LogMessage.LogLevelToName(robustLevel)); - formatted.Pop(); - formatted.AddText($"] {sawmillName}: "); - formatted.Pop(); - formatted.PushColor(Color.LightGray); - formatted.AddText(message.RenderMessage()); - formatted.Pop(); + formatted.AddRange(new [] + { + new Section() { Color=Color.DarkGray.ToArgb(), Content="[" }, + new Section() { Color=LogLevelToColor(robustLevel).ToArgb(), Content=LogMessage.LogLevelToName(robustLevel) }, + new Section() { Color=Color.DarkGray.ToArgb(), Content=$"] {sawmillName}: " }, + new Section() { Color=Color.LightGray.ToArgb(), Content=message.RenderMessage() } + } + ); + if (message.Exception != null) - { - formatted.AddText("\n"); - formatted.AddText(message.Exception.ToString()); - } - Console.AddFormattedLine(formatted.Build()); + formatted.Add(new Section() { Content="\n" + message.Exception.ToString() }); + + Console.AddFormattedLine(new FormattedMessage(formatted.ToArray())); } private static Color LogLevelToColor(LogLevel level) diff --git a/Robust.Client/UserInterface/Controls/OutputPanel.cs b/Robust.Client/UserInterface/Controls/OutputPanel.cs index 6ca00e63fd1..e9106fab861 100644 --- a/Robust.Client/UserInterface/Controls/OutputPanel.cs +++ b/Robust.Client/UserInterface/Controls/OutputPanel.cs @@ -66,12 +66,12 @@ public void RemoveEntry(Index index) _invalidateEntries(); } - public void AddText(string text) - { - var msg = new FormattedMessage.Builder(); - msg.AddText(text); - AddMessage(msg.Build()); - } + public void AddText(string text) => + AddMessage(new FormattedMessage(new [] + { + new Section() { Content=text } + } + )); public void AddMessage(FormattedMessage message) { diff --git a/Robust.Client/UserInterface/Controls/RichTextLabel.cs b/Robust.Client/UserInterface/Controls/RichTextLabel.cs index 60498561b91..c46d4ea9356 100644 --- a/Robust.Client/UserInterface/Controls/RichTextLabel.cs +++ b/Robust.Client/UserInterface/Controls/RichTextLabel.cs @@ -17,12 +17,12 @@ public void SetMessage(FormattedMessage message) InvalidateMeasure(); } - public void SetMessage(string message) - { - var msg = new FormattedMessage.Builder(); - msg.AddText(message); - SetMessage(msg.Build()); - } + public void SetMessage(string message) => + SetMessage(new FormattedMessage(new [] + { + new Section { Content=message } + } + )); protected override Vector2 MeasureOverride(Vector2 availableSize) { diff --git a/Robust.Client/UserInterface/CustomControls/DebugConsole.xaml.cs b/Robust.Client/UserInterface/CustomControls/DebugConsole.xaml.cs index 244ce70b42f..82b7a2c47b3 100644 --- a/Robust.Client/UserInterface/CustomControls/DebugConsole.xaml.cs +++ b/Robust.Client/UserInterface/CustomControls/DebugConsole.xaml.cs @@ -129,14 +129,12 @@ private void OnHistoryChanged() _flushHistoryToDisk(); } - public void AddLine(string text, Color color) - { - var formatted = new FormattedMessage.Builder(); - formatted.PushColor(color); - formatted.AddText(text); - formatted.Pop(); - AddFormattedLine(formatted.Build()); - } + public void AddLine(string text, Color color) => + AddFormattedLine(new FormattedMessage(new [] + { + new Section() { Color=color.ToArgb(), Content=text } + } + )); public void AddLine(string text) { diff --git a/Robust.Server/Scripting/ScriptHost.cs b/Robust.Server/Scripting/ScriptHost.cs index feb90da11c2..28f3fe22604 100644 --- a/Robust.Server/Scripting/ScriptHost.cs +++ b/Robust.Server/Scripting/ScriptHost.cs @@ -184,12 +184,12 @@ private async void ReceiveScriptEval(MsgScriptEval message) newScript.Compile(); // Echo entered script. - var echoMessage = new FormattedMessage.Builder(); + var echoMessage = new List
(); ScriptInstanceShared.AddWithSyntaxHighlighting(newScript, echoMessage, code, instance.HighlightWorkspace); - replyMessage.Echo = echoMessage.Build(); + replyMessage.Echo = new FormattedMessage(echoMessage.ToArray()); - var msg = new FormattedMessage.Builder(); + var msg = new List
(); try { @@ -205,17 +205,15 @@ private async void ReceiveScriptEval(MsgScriptEval message) } catch (CompilationErrorException e) { - msg.PushColor(Color.Crimson); + var s = new Section(); + s.Color = Color.Crimson.ToArgb(); foreach (var diagnostic in e.Diagnostics) - { - msg.AddText(diagnostic.ToString()); - msg.AddText("\n"); - } + s.Content = diagnostic.ToString() + "\n"; - PromptAutoImports(e.Diagnostics, code, msg, instance); + s.Content += PromptAutoImports(e.Diagnostics, code, instance); - replyMessage.Response = msg.Build(); + replyMessage.Response = new FormattedMessage(new [] { s }); _netManager.ServerSendMessage(replyMessage, message.MsgChannel); return; } @@ -226,21 +224,25 @@ private async void ReceiveScriptEval(MsgScriptEval message) if (instance.OutputBuffer.Length != 0) { - msg.AddText(instance.OutputBuffer.ToString()); + msg.Add(new Section() { Content=instance.OutputBuffer.ToString() }); instance.OutputBuffer.Clear(); } if (instance.State.Exception != null) { - msg.PushColor(Color.Crimson); - msg.AddText(CSharpObjectFormatter.Instance.FormatException(instance.State.Exception)); + msg.Add(new Section() { + Color=Color.Crimson.ToArgb(), + Content=CSharpObjectFormatter.Instance.FormatException(instance.State.Exception) + }); } else if (ScriptInstanceShared.HasReturnValue(newScript)) { - msg.AddText(ScriptInstanceShared.SafeFormat(instance.State.ReturnValue)); + msg.Add(new Section() { + Content=ScriptInstanceShared.SafeFormat(instance.State.ReturnValue) + }); } - replyMessage.Response = msg.Build(); + replyMessage.Response = new FormattedMessage(msg.ToArray()); _netManager.ServerSendMessage(replyMessage, message.MsgChannel); } @@ -313,18 +315,16 @@ private async void ReceiveScriptCompletion(MsgScriptCompletion message) _netManager.ServerSendMessage(replyMessage, message.MsgChannel); } - private void PromptAutoImports( + private string PromptAutoImports( IEnumerable diags, string code, - FormattedMessage.Builder output, ScriptInstance instance) { if (!ScriptInstanceShared.CalcAutoImports(_reflectionManager, diags, out var found)) - return; - - output.AddText($"Auto-import {string.Join(", ", found)} (enter 'y')?"); + return String.Empty; instance.AutoImportRepeatBuffer = (found.ToArray(), code); + return $"Auto-import {string.Join(", ", found)} (enter 'y')?" ; } diff --git a/Robust.Shared.Scripting/ScriptInstanceShared.cs b/Robust.Shared.Scripting/ScriptInstanceShared.cs index 8f281d621b8..a335ddea0f0 100644 --- a/Robust.Shared.Scripting/ScriptInstanceShared.cs +++ b/Robust.Shared.Scripting/ScriptInstanceShared.cs @@ -77,7 +77,7 @@ static ScriptInstanceShared() "var x = 5 + 5; var y = (object) \"foobar\"; void Foo(object a) { } Foo(y); Foo(x)"; var script = await CSharpScript.RunAsync(code); - var msg = new FormattedMessage.Builder(); + var msg = new List
(); // Even run the syntax highlighter! AddWithSyntaxHighlighting(script.Script, msg, code, new AdhocWorkspace()); }); @@ -101,7 +101,7 @@ public static bool HasReturnValue(Script script) return _getDiagnosticArguments(diag); } - public static void AddWithSyntaxHighlighting(Script script, FormattedMessage.Builder msg, string code, + public static void AddWithSyntaxHighlighting(Script script, List
msg, string code, Workspace workspace) { var compilation = script.GetCompilation(); @@ -115,7 +115,7 @@ public static void AddWithSyntaxHighlighting(Script script, FormattedMessage.Bui var start = span.TextSpan.Start; if (start > current) { - msg.AddText(code[current..start]); + msg.Add(new Section() { Content=code[current..start] }); } if (current > start) @@ -129,13 +129,11 @@ public static void AddWithSyntaxHighlighting(Script script, FormattedMessage.Bui if (!ScriptingColorScheme.ColorScheme.TryGetValue(span.ClassificationType, out var color)) color = ScriptingColorScheme.ColorScheme[ScriptingColorScheme.Default]; - msg.PushColor(color); - msg.AddText(src); - msg.Pop(); + msg.Add(new Section() { Content=src, Color=color.ToArgb() }); current = span.TextSpan.End; } - msg.AddText(code[current..]); + msg.Add(new Section() { Content=code[current..] }); } private static IEnumerable GetDefaultReferences(IReflectionManager reflectionManager)