From ec2f29479628cb5b8f6b721073ddb007482c4624 Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Wed, 7 Aug 2024 23:31:53 +0200 Subject: [PATCH] Fix exec statement and syntax highlighter --- YesNt.CodeEditor/SyntaxHighlighter.cs | 10 ++-- .../Statements/SystemStatements.cs | 52 ++++++++++--------- 2 files changed, 33 insertions(+), 29 deletions(-) diff --git a/YesNt.CodeEditor/SyntaxHighlighter.cs b/YesNt.CodeEditor/SyntaxHighlighter.cs index 12c664e..5aaf33f 100644 --- a/YesNt.CodeEditor/SyntaxHighlighter.cs +++ b/YesNt.CodeEditor/SyntaxHighlighter.cs @@ -134,7 +134,7 @@ internal partial class SyntaxHighlighter(ReadOnlyCollection= 0 && colorIndex < 16) { - messagePart = Base64Decode(messagePart.Replace($"\r{stringColor}\r", string.Empty)); + messagePart = Base64Decode(messagePart.Replace($"\v{stringColor}\v", string.Empty)); consoleColor = (ConsoleColor)colorIndex; } else @@ -160,9 +160,9 @@ internal partial class SyntaxHighlighter(ReadOnlyCollection originalString.ReplaceFirstOccurrence(value, $"\0\r{(int)color}\r{base64Value}\0" + new string(' ', spacesAtEnd)), - SearchMode.EndOfLine => originalString.ReplaceLastOccurrence(value, $"\0\r{(int)color}\r{base64Value}\0" + new string(' ', spacesAtEnd)), - _ => originalString.Replace(value, $"\0\r{(int)color}\r{base64Value}\0" + new string(' ', spacesAtEnd)) + SearchMode.StartOfLine => originalString.ReplaceFirstOccurrence(value, $"\0\v{(int)color}\v{base64Value}\0" + new string(' ', spacesAtEnd)), + SearchMode.EndOfLine => originalString.ReplaceLastOccurrence(value, $"\0\v{(int)color}\v{base64Value}\0" + new string(' ', spacesAtEnd)), + _ => originalString.Replace(value, $"\0\v{(int)color}\v{base64Value}\0" + new string(' ', spacesAtEnd)) }; return result; } @@ -176,6 +176,6 @@ internal partial class SyntaxHighlighter(ReadOnlyCollection[a-zA-Z0-9]+")] private static partial Regex VariableRegex(); - [GeneratedRegex("(?<=(\\r))(.*)(?=\\r)")] + [GeneratedRegex("(?<=(\\v))(.*)(?=\\v)")] private static partial Regex StringColorRegex(); } \ No newline at end of file diff --git a/YesNt.Interpreter/Statements/SystemStatements.cs b/YesNt.Interpreter/Statements/SystemStatements.cs index c8d1e32..c5b603a 100644 --- a/YesNt.Interpreter/Statements/SystemStatements.cs +++ b/YesNt.Interpreter/Statements/SystemStatements.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.IO; @@ -60,10 +61,34 @@ internal class SystemStatements : StatementRuntimeInformation } } + private static void Process_ErrorDataReceived(Utilities.DataReceivedEventArgs e, Stack outputStack) + { + if (string.IsNullOrWhiteSpace(e.Data)) + { + return; + } + + outputStack.Push(e.Data.ToSafeString()); + Console.Write("Error: " + e.Data); + } + + private static void Process_OutputDataReceived(Utilities.DataReceivedEventArgs e, Stack outputStack) + { + if (string.IsNullOrWhiteSpace(e.Data)) + { + return; + } + + outputStack.Push(e.Data.ToSafeString()); + Console.Write(e.Data); + } + private void StartProcess(string name, string args) { RuntimeInfo.OutParametersStack.Clear(); + Stack outputStack = new Stack(); + FixedProcess process = new FixedProcess { StartInfo = new ProcessStartInfo() @@ -75,8 +100,8 @@ internal class SystemStatements : StatementRuntimeInformation } }; - process.OutputDataReceived += Process_OutputDataReceived; - process.ErrorDataReceived += Process_ErrorDataReceived; + process.OutputDataReceived += (s, e) => Process_OutputDataReceived(e, outputStack); + process.ErrorDataReceived += (s, e) => Process_ErrorDataReceived(e, outputStack); _ = process.Start(); process.BeginOutputReadLine(); @@ -85,28 +110,7 @@ internal class SystemStatements : StatementRuntimeInformation RuntimeInfo.InParametersStack.Clear(); + RuntimeInfo.OutParametersStack = new(outputStack); RuntimeInfo.OutParametersStack.Push(process.ExitCode.ToString()); } - - private void Process_ErrorDataReceived(object sender, Utilities.DataReceivedEventArgs e) - { - if (string.IsNullOrWhiteSpace(e.Data)) - { - return; - } - - RuntimeInfo.OutParametersStack.Push(e.Data); - Console.Write("Error: " + e.Data); - } - - private void Process_OutputDataReceived(object sender, Utilities.DataReceivedEventArgs e) - { - if (string.IsNullOrWhiteSpace(e.Data)) - { - return; - } - - RuntimeInfo.OutParametersStack.Push(e.Data); - Console.Write(e.Data); - } } \ No newline at end of file