Fix exec statement and syntax highlighter

This commit is contained in:
Stone_Red
2024-08-07 23:31:53 +02:00
parent cf274e1db9
commit ec2f294796
2 changed files with 33 additions and 29 deletions
+5 -5
View File
@@ -134,7 +134,7 @@ internal partial class SyntaxHighlighter(ReadOnlyCollection<StatementInformation
bool succ = int.TryParse(stringColor, out int colorIndex);
if (succ && colorIndex >= 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<StatementInformation
string result = searchMode switch
{
SearchMode.StartOfLine => 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<StatementInformation
[GeneratedRegex(">[a-zA-Z0-9]+")]
private static partial Regex VariableRegex();
[GeneratedRegex("(?<=(\\r))(.*)(?=\\r)")]
[GeneratedRegex("(?<=(\\v))(.*)(?=\\v)")]
private static partial Regex StringColorRegex();
}
@@ -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<string> 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<string> 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<string> outputStack = new Stack<string>();
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);
}
}