mirror of
https://github.com/Stone-Red-Code/YesNt-Interpreter.git
synced 2026-09-09 07:56:06 +02:00
Escape invisible character is debug mode
This commit is contained in:
@@ -203,12 +203,17 @@ internal class TextEditor
|
|||||||
return padding;
|
return padding;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string ToLiteral(string input)
|
||||||
|
{
|
||||||
|
return Microsoft.CodeAnalysis.CSharp.SymbolDisplay.FormatLiteral(input, false);
|
||||||
|
}
|
||||||
|
|
||||||
private void YesNtInterpreter_OnDebugOutput(string output)
|
private void YesNtInterpreter_OnDebugOutput(string output)
|
||||||
{
|
{
|
||||||
debugOutput.Add(output);
|
debugOutput.Add(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void YesNtInterpreter_OnLineExecuted(Interpreter.Runtime.DebugEventArgs e)
|
private void YesNtInterpreter_OnLineExecuted(DebugEventArgs e)
|
||||||
{
|
{
|
||||||
lock (Console.Out)
|
lock (Console.Out)
|
||||||
{
|
{
|
||||||
@@ -221,11 +226,11 @@ internal class TextEditor
|
|||||||
|
|
||||||
if (e.OriginalLine == e.CurrentLine)
|
if (e.OriginalLine == e.CurrentLine)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"{sharedString}[{e.CurrentLine}] ==>");
|
Console.WriteLine($"{sharedString}[{ToLiteral(e.CurrentLine)}] ==>");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Console.WriteLine($"{sharedString}[{e.OriginalLine}] => [{e.CurrentLine}] ==>");
|
Console.WriteLine($"{sharedString}[{ToLiteral(e.OriginalLine)}] => [{ToLiteral(e.CurrentLine)}] ==>");
|
||||||
}
|
}
|
||||||
Console.ForegroundColor = ConsoleColor.Gray;
|
Console.ForegroundColor = ConsoleColor.Gray;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,10 @@
|
|||||||
<None Include="..\.editorconfig" Link=".editorconfig" />
|
<None Include="..\.editorconfig" Link=".editorconfig" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.10.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\YesNt.Interpreter\YesNt.Interpreter.csproj" />
|
<ProjectReference Include="..\YesNt.Interpreter\YesNt.Interpreter.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -52,20 +52,20 @@ public class YesNtInterpreter
|
|||||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
Assembly assembly = Assembly.GetExecutingAssembly();
|
||||||
Type[] types = assembly.GetTypes();
|
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();
|
statements.Clear();
|
||||||
|
|
||||||
foreach (Type type in statementRuntimeInfos)
|
foreach (Type type in allStatementRuntimeInfo)
|
||||||
{
|
{
|
||||||
object statementInfo = Activator.CreateInstance(type);
|
object statementInfo = Activator.CreateInstance(type);
|
||||||
|
|
||||||
MethodInfo[] methodInfos = statementInfo.GetType().GetMethods();
|
MethodInfo[] allMethodInfo = statementInfo.GetType().GetMethods();
|
||||||
|
|
||||||
StatementRuntimeInformation statementRuntimeInfo = statementInfo as StatementRuntimeInformation;
|
StatementRuntimeInformation statementRuntimeInfo = statementInfo as StatementRuntimeInformation;
|
||||||
statementRuntimeInfo.RuntimeInfo = runtimeInfo;
|
statementRuntimeInfo.RuntimeInfo = runtimeInfo;
|
||||||
|
|
||||||
foreach (MethodInfo methodInfo in methodInfos)
|
foreach (MethodInfo methodInfo in allMethodInfo)
|
||||||
{
|
{
|
||||||
StatementAttribute statementAttribute = methodInfo.GetCustomAttribute<StatementAttribute>();
|
StatementAttribute statementAttribute = methodInfo.GetCustomAttribute<StatementAttribute>();
|
||||||
if (statementAttribute is not null)
|
if (statementAttribute is not null)
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ internal class ConsoleStatements : StatementRuntimeInformation
|
|||||||
args += " ";
|
args += " ";
|
||||||
while (args.Contains("%cr"))
|
while (args.Contains("%cr"))
|
||||||
{
|
{
|
||||||
string input = ConsoleExtentions.ReadKey(RuntimeInfo).ToString();
|
string input = ConsoleExtensions.ReadKey(RuntimeInfo).ToString();
|
||||||
args = args.ReplaceFirstOccurrence("%cr ", input.ToSafeString() + " ");
|
args = args.ReplaceFirstOccurrence("%cr ", input.ToSafeString() + " ");
|
||||||
}
|
}
|
||||||
RuntimeInfo.CurrentLine = args.TrimEnd();
|
RuntimeInfo.CurrentLine = args.TrimEnd();
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ internal partial class ProcessingStatements : StatementRuntimeInformation
|
|||||||
{
|
{
|
||||||
if (int.TryParse(args, out int millisecondsTimeout))
|
if (int.TryParse(args, out int millisecondsTimeout))
|
||||||
{
|
{
|
||||||
ConsoleExtentions.Sleep(millisecondsTimeout, RuntimeInfo);
|
ConsoleExtensions.Sleep(millisecondsTimeout, RuntimeInfo);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,35 +4,34 @@ using System.Threading;
|
|||||||
|
|
||||||
using YesNt.Interpreter.Runtime;
|
using YesNt.Interpreter.Runtime;
|
||||||
|
|
||||||
namespace YesNt.Interpreter.Utilities
|
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 ' ';
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
if (Console.KeyAvailable)
|
||||||
stopwatch.Start();
|
|
||||||
while (!runtimeInformation.Stop)
|
|
||||||
{
|
{
|
||||||
if (stopwatch.ElapsedMilliseconds > millisecondsTimeout)
|
return Console.ReadKey().KeyChar;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Thread.Sleep(10);
|
|
||||||
}
|
}
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user