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
@@ -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);
}
}