Escape invisible character is debug mode

This commit is contained in:
Stone_Red
2024-08-08 23:57:40 +02:00
parent ec2f294796
commit 9a6f1d7806
6 changed files with 42 additions and 34 deletions
+8 -3
View File
@@ -203,12 +203,17 @@ internal class TextEditor
return padding;
}
private static string ToLiteral(string input)
{
return Microsoft.CodeAnalysis.CSharp.SymbolDisplay.FormatLiteral(input, false);
}
private void YesNtInterpreter_OnDebugOutput(string output)
{
debugOutput.Add(output);
}
private void YesNtInterpreter_OnLineExecuted(Interpreter.Runtime.DebugEventArgs e)
private void YesNtInterpreter_OnLineExecuted(DebugEventArgs e)
{
lock (Console.Out)
{
@@ -221,11 +226,11 @@ internal class TextEditor
if (e.OriginalLine == e.CurrentLine)
{
Console.WriteLine($"{sharedString}[{e.CurrentLine}] ==>");
Console.WriteLine($"{sharedString}[{ToLiteral(e.CurrentLine)}] ==>");
}
else
{
Console.WriteLine($"{sharedString}[{e.OriginalLine}] => [{e.CurrentLine}] ==>");
Console.WriteLine($"{sharedString}[{ToLiteral(e.OriginalLine)}] => [{ToLiteral(e.CurrentLine)}] ==>");
}
Console.ForegroundColor = ConsoleColor.Gray;
}
+4
View File
@@ -10,6 +10,10 @@
<None Include="..\.editorconfig" Link=".editorconfig" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.10.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\YesNt.Interpreter\YesNt.Interpreter.csproj" />
</ItemGroup>
@@ -52,20 +52,20 @@ public class YesNtInterpreter
Assembly assembly = Assembly.GetExecutingAssembly();
Type[] types = assembly.GetTypes();
IEnumerable<Type> statementRuntimeInfos = types.Where(t => t.IsSubclassOf(typeof(StatementRuntimeInformation)));
IEnumerable<Type> allStatementRuntimeInfo = types.Where(t => t.IsSubclassOf(typeof(StatementRuntimeInformation)));
statements.Clear();
foreach (Type type in statementRuntimeInfos)
foreach (Type type in allStatementRuntimeInfo)
{
object statementInfo = Activator.CreateInstance(type);
MethodInfo[] methodInfos = statementInfo.GetType().GetMethods();
MethodInfo[] allMethodInfo = statementInfo.GetType().GetMethods();
StatementRuntimeInformation statementRuntimeInfo = statementInfo as StatementRuntimeInformation;
statementRuntimeInfo.RuntimeInfo = runtimeInfo;
foreach (MethodInfo methodInfo in methodInfos)
foreach (MethodInfo methodInfo in allMethodInfo)
{
StatementAttribute statementAttribute = methodInfo.GetCustomAttribute<StatementAttribute>();
if (statementAttribute is not null)
@@ -51,7 +51,7 @@ internal class ConsoleStatements : StatementRuntimeInformation
args += " ";
while (args.Contains("%cr"))
{
string input = ConsoleExtentions.ReadKey(RuntimeInfo).ToString();
string input = ConsoleExtensions.ReadKey(RuntimeInfo).ToString();
args = args.ReplaceFirstOccurrence("%cr ", input.ToSafeString() + " ");
}
RuntimeInfo.CurrentLine = args.TrimEnd();
@@ -62,7 +62,7 @@ internal partial class ProcessingStatements : StatementRuntimeInformation
{
if (int.TryParse(args, out int millisecondsTimeout))
{
ConsoleExtentions.Sleep(millisecondsTimeout, RuntimeInfo);
ConsoleExtensions.Sleep(millisecondsTimeout, RuntimeInfo);
}
else
{
@@ -4,35 +4,34 @@ using System.Threading;
using YesNt.Interpreter.Runtime;
namespace YesNt.Interpreter.Utilities
{
internal static class ConsoleExtentions
{
public static char ReadKey(RuntimeInformation runtimeInformation)
{
while (!runtimeInformation.Stop)
{
if (Console.KeyAvailable)
{
return Console.ReadKey().KeyChar;
}
Thread.Sleep(10);
}
return ' ';
}
namespace YesNt.Interpreter.Utilities;
public static void Sleep(int millisecondsTimeout, RuntimeInformation runtimeInformation)
internal static class ConsoleExtensions
{
public static char ReadKey(RuntimeInformation runtimeInformation)
{
while (!runtimeInformation.Stop)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
while (!runtimeInformation.Stop)
if (Console.KeyAvailable)
{
if (stopwatch.ElapsedMilliseconds > millisecondsTimeout)
{
return;
}
Thread.Sleep(10);
return Console.ReadKey().KeyChar;
}
Thread.Sleep(10);
}
return ' ';
}
public static void Sleep(int millisecondsTimeout, RuntimeInformation runtimeInformation)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
while (!runtimeInformation.Stop)
{
if (stopwatch.ElapsedMilliseconds > millisecondsTimeout)
{
return;
}
Thread.Sleep(10);
}
}
}