From 9a6f1d780608480fc4eae089e6c3fd4b1660c008 Mon Sep 17 00:00:00 2001
From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com>
Date: Thu, 8 Aug 2024 23:57:40 +0200
Subject: [PATCH] Escape invisible character is debug mode
---
YesNt.CodeEditor/Editor.cs | 11 +++--
YesNt.CodeEditor/YesNt.CodeEditor.csproj | 4 ++
YesNt.Interpreter/Runtime/YesNtInterpreter.cs | 8 +--
.../Statements/ConsoleStatements.cs | 2 +-
.../Statements/ProcessingStatements.cs | 2 +-
.../Utilities/ConsoleExtentions.cs | 49 +++++++++----------
6 files changed, 42 insertions(+), 34 deletions(-)
diff --git a/YesNt.CodeEditor/Editor.cs b/YesNt.CodeEditor/Editor.cs
index 11e1eb5..f3f7698 100644
--- a/YesNt.CodeEditor/Editor.cs
+++ b/YesNt.CodeEditor/Editor.cs
@@ -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;
}
diff --git a/YesNt.CodeEditor/YesNt.CodeEditor.csproj b/YesNt.CodeEditor/YesNt.CodeEditor.csproj
index b7ba18b..5b45dec 100644
--- a/YesNt.CodeEditor/YesNt.CodeEditor.csproj
+++ b/YesNt.CodeEditor/YesNt.CodeEditor.csproj
@@ -10,6 +10,10 @@
+
+
+
+
diff --git a/YesNt.Interpreter/Runtime/YesNtInterpreter.cs b/YesNt.Interpreter/Runtime/YesNtInterpreter.cs
index fdfd80d..0559a7c 100644
--- a/YesNt.Interpreter/Runtime/YesNtInterpreter.cs
+++ b/YesNt.Interpreter/Runtime/YesNtInterpreter.cs
@@ -52,20 +52,20 @@ public class YesNtInterpreter
Assembly assembly = Assembly.GetExecutingAssembly();
Type[] types = assembly.GetTypes();
- IEnumerable statementRuntimeInfos = types.Where(t => t.IsSubclassOf(typeof(StatementRuntimeInformation)));
+ IEnumerable 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();
if (statementAttribute is not null)
diff --git a/YesNt.Interpreter/Statements/ConsoleStatements.cs b/YesNt.Interpreter/Statements/ConsoleStatements.cs
index 406db42..b7f1fdb 100644
--- a/YesNt.Interpreter/Statements/ConsoleStatements.cs
+++ b/YesNt.Interpreter/Statements/ConsoleStatements.cs
@@ -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();
diff --git a/YesNt.Interpreter/Statements/ProcessingStatements.cs b/YesNt.Interpreter/Statements/ProcessingStatements.cs
index e606aea..60af01f 100644
--- a/YesNt.Interpreter/Statements/ProcessingStatements.cs
+++ b/YesNt.Interpreter/Statements/ProcessingStatements.cs
@@ -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
{
diff --git a/YesNt.Interpreter/Utilities/ConsoleExtentions.cs b/YesNt.Interpreter/Utilities/ConsoleExtentions.cs
index a394935..f401e52 100644
--- a/YesNt.Interpreter/Utilities/ConsoleExtentions.cs
+++ b/YesNt.Interpreter/Utilities/ConsoleExtentions.cs
@@ -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);
}
}
}
\ No newline at end of file