Add step debug mode and refactor command handling for run/debug

This commit is contained in:
Stone_Red
2026-03-04 16:01:23 +01:00
parent e99df1e3f2
commit 7f58fb4aaf
2 changed files with 85 additions and 28 deletions
+10 -1
View File
@@ -20,6 +20,7 @@ internal class TextEditor
public Point CursorPosition { get; } = new(0, 0); public Point CursorPosition { get; } = new(0, 0);
public Mode EditMode { get; set; } = Mode.Command; public Mode EditMode { get; set; } = Mode.Command;
public string CurrentPath { get; set; } = string.Empty; public string CurrentPath { get; set; } = string.Empty;
public bool IsStepDebugMode { get; set; }
public TextEditor(string path) : this() public TextEditor(string path) : this()
{ {
@@ -241,6 +242,14 @@ internal class TextEditor
{ {
Console.Write(output); Console.Write(output);
} }
if (IsStepDebugMode && e is not null && !e.IsTask)
{
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.WriteLine("[Step] Press any key for next line (Ctrl+C to stop)...");
Console.ForegroundColor = ConsoleColor.Gray;
_ = Console.ReadKey(true);
}
} }
} }
@@ -279,4 +288,4 @@ internal enum Mode
Edit, Edit,
Command, Command,
Debug Debug
} }
+75 -27
View File
@@ -225,36 +225,18 @@ internal class InputHandler(TextEditor textEditor)
break; break;
case "run": case "run":
if (textEditor.Save(input, true)) ExecuteWithDebugScreen(input, false, false);
{
textEditor.EditMode = Mode.Debug;
Console.Clear();
Console.CursorVisible = true;
textEditor.YesNtInterpreter.Execute(textEditor.CurrentPath);
while (Console.KeyAvailable)
{
_ = Console.ReadKey(true);
}
_ = Console.ReadKey();
WriteStatus(string.Empty);
textEditor.EditMode = Mode.Command;
}
break; break;
case "debug": case "debug":
if (textEditor.Save(input, true)) if (TryParseDebugCommand(input, out bool stepMode, out string parsedPath))
{ {
textEditor.EditMode = Mode.Debug; string saveInput = string.IsNullOrWhiteSpace(parsedPath) ? "debug" : $"debug {parsedPath}";
Console.Clear(); ExecuteWithDebugScreen(saveInput, true, stepMode);
Console.CursorVisible = true; }
textEditor.YesNtInterpreter.Execute(textEditor.CurrentPath, true); else
while (Console.KeyAvailable) {
{ WriteStatus("Invalid arguments!");
_ = Console.ReadKey(true);
}
_ = Console.ReadKey();
WriteStatus(string.Empty);
textEditor.EditMode = Mode.Command;
} }
break; break;
@@ -309,4 +291,70 @@ internal class InputHandler(TextEditor textEditor)
Console.SetCursorPosition(0, Console.WindowHeight - 1); Console.SetCursorPosition(0, Console.WindowHeight - 1);
Console.Write(input + new string(' ', Console.WindowWidth - input.Length - 1)); Console.Write(input + new string(' ', Console.WindowWidth - input.Length - 1));
} }
}
private static bool TryParseDebugCommand(string input, out bool stepMode, out string path)
{
stepMode = false;
path = string.Empty;
string[] parts = input.Split(' ', StringSplitOptions.RemoveEmptyEntries);
if (parts.Length == 0 || !parts[0].Equals("debug", StringComparison.OrdinalIgnoreCase))
{
return false;
}
for (int i = 1; i < parts.Length; i++)
{
string token = parts[i];
if (token.Equals("step", StringComparison.OrdinalIgnoreCase))
{
if (stepMode)
{
return false;
}
stepMode = true;
continue;
}
if (string.IsNullOrWhiteSpace(path))
{
path = token;
continue;
}
return false;
}
return true;
}
private void ExecuteWithDebugScreen(string saveInput, bool debugMode, bool stepMode)
{
if (textEditor.Save(saveInput, true))
{
textEditor.EditMode = Mode.Debug;
textEditor.IsStepDebugMode = stepMode;
Console.Clear();
Console.CursorVisible = true;
if (debugMode)
{
textEditor.YesNtInterpreter.Execute(textEditor.CurrentPath, true);
}
else
{
textEditor.YesNtInterpreter.Execute(textEditor.CurrentPath);
}
while (Console.KeyAvailable)
{
_ = Console.ReadKey(true);
}
_ = Console.ReadKey();
WriteStatus(string.Empty);
textEditor.IsStepDebugMode = false;
textEditor.EditMode = Mode.Command;
}
}
}