mirror of
https://github.com/Stone-Red-Code/YesNt-Interpreter.git
synced 2026-09-07 23:43:07 +02:00
- Add global variables
- Add task id's - Fixed editor bugs - Fix input handler bugs
This commit is contained in:
+22
-11
@@ -13,7 +13,6 @@ namespace YesNt.CodeEditor
|
||||
private readonly List<string> debugOutput = new();
|
||||
|
||||
public YesNtInterpreter yesNtInterpreter { get; } = new();
|
||||
|
||||
public int LineOffset { get; set; } = 0;
|
||||
public List<string> Lines { get; } = new();
|
||||
public Point CursorPosition { get; } = new(0, 0);
|
||||
@@ -47,12 +46,15 @@ namespace YesNt.CodeEditor
|
||||
{
|
||||
Display(false);
|
||||
} while (inputHandler.HandleInput());
|
||||
|
||||
Console.Clear();
|
||||
}
|
||||
|
||||
public void Display(bool drawAll)
|
||||
{
|
||||
Console.CursorVisible = false;
|
||||
Console.ForegroundColor = ConsoleColor.Gray;
|
||||
Console.BackgroundColor = ConsoleColor.Black;
|
||||
|
||||
Console.SetCursorPosition(0, 0);
|
||||
|
||||
@@ -138,6 +140,10 @@ namespace YesNt.CodeEditor
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(Path.GetExtension(path)))
|
||||
{
|
||||
path = Path.ChangeExtension(path, "ynt");
|
||||
}
|
||||
CurrentPath = path;
|
||||
}
|
||||
else if (!string.IsNullOrWhiteSpace(CurrentPath))
|
||||
@@ -151,7 +157,7 @@ namespace YesNt.CodeEditor
|
||||
}
|
||||
else
|
||||
{
|
||||
inputHandler.WriteStatus("File path is empty!");
|
||||
inputHandler.WriteStatus("File path is empty! (Save the file before you can use this command)");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -187,17 +193,22 @@ namespace YesNt.CodeEditor
|
||||
{
|
||||
lock (Console.Out)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Magenta;
|
||||
if (e.OriginalLine == e.CurrentLine)
|
||||
if (e is not null)
|
||||
{
|
||||
Console.WriteLine($"{Environment.NewLine}[{e.LineNumber}] [{e.CurrentLine}] ==>");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"{Environment.NewLine}[{e.LineNumber}] [{e.OriginalLine}] => [{e.CurrentLine}] ==>");
|
||||
}
|
||||
Console.ResetColor();
|
||||
Console.ForegroundColor = ConsoleColor.Magenta;
|
||||
|
||||
string taskId = e.IsTask ? $"[Task: {e.TaskId}] " : string.Empty;
|
||||
if (e.OriginalLine == e.CurrentLine)
|
||||
{
|
||||
Console.WriteLine($"{Environment.NewLine}{taskId}[{e.LineNumber}] [{e.CurrentLine}] ==>");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"{Environment.NewLine}{taskId}[{e.LineNumber}] [{e.OriginalLine}] => [{e.CurrentLine}] ==>");
|
||||
}
|
||||
Console.ForegroundColor = ConsoleColor.Gray;
|
||||
|
||||
}
|
||||
string[] outputs = debugOutput.ToArray();
|
||||
debugOutput.Clear();
|
||||
|
||||
|
||||
@@ -13,6 +13,10 @@ namespace YesNt.CodeEditor
|
||||
|
||||
public bool HandleInput()
|
||||
{
|
||||
while (Console.KeyAvailable)
|
||||
{
|
||||
Console.ReadKey(true);
|
||||
}
|
||||
if (textEditor.EditMode == Mode.Edit)
|
||||
{
|
||||
ConsoleKeyInfo keyInfo = Console.ReadKey(true);
|
||||
@@ -23,7 +27,7 @@ namespace YesNt.CodeEditor
|
||||
{
|
||||
case ConsoleKey.C:
|
||||
textEditor.EditMode = Mode.Command;
|
||||
break;
|
||||
return true;
|
||||
|
||||
case ConsoleKey.B:
|
||||
int position = textEditor.Lines.Count;
|
||||
@@ -31,18 +35,18 @@ namespace YesNt.CodeEditor
|
||||
textEditor.LineOffset = Math.Max(position - Console.WindowHeight + 3, 0);
|
||||
|
||||
textEditor.Display(true);
|
||||
break;
|
||||
return true;
|
||||
|
||||
case ConsoleKey.T:
|
||||
textEditor.CursorPosition.Y = 0;
|
||||
textEditor.LineOffset = 0;
|
||||
|
||||
textEditor.Display(true);
|
||||
break;
|
||||
return true;
|
||||
|
||||
case ConsoleKey.S:
|
||||
textEditor.CursorPosition.X = 0;
|
||||
break;
|
||||
return true;
|
||||
|
||||
case ConsoleKey.E:
|
||||
if (textEditor.Lines.Count > textEditor.CursorPosition.Y)
|
||||
@@ -53,10 +57,10 @@ namespace YesNt.CodeEditor
|
||||
{
|
||||
textEditor.CursorPosition.X = 0;
|
||||
}
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (keyInfo.Key == ConsoleKey.DownArrow)
|
||||
if (keyInfo.Key == ConsoleKey.DownArrow)
|
||||
{
|
||||
textEditor.CursorPosition.Y++;
|
||||
if (textEditor.CursorPosition.Y - textEditor.LineOffset >= Console.WindowHeight - 3)
|
||||
@@ -228,6 +232,7 @@ namespace YesNt.CodeEditor
|
||||
{
|
||||
textEditor.EditMode = Mode.Debug;
|
||||
Console.Clear();
|
||||
Console.CursorVisible = true;
|
||||
textEditor.yesNtInterpreter.Execute(textEditor.CurrentPath);
|
||||
while (Console.KeyAvailable)
|
||||
{
|
||||
@@ -244,6 +249,7 @@ namespace YesNt.CodeEditor
|
||||
{
|
||||
textEditor.EditMode = Mode.Debug;
|
||||
Console.Clear();
|
||||
Console.CursorVisible = true;
|
||||
textEditor.yesNtInterpreter.Execute(textEditor.CurrentPath, true);
|
||||
while (Console.KeyAvailable)
|
||||
{
|
||||
|
||||
@@ -65,6 +65,12 @@ namespace YesNt.CodeEditor
|
||||
input = AddColorInformation(input, matches[i].Value, ConsoleColor.DarkCyan, SearchMode.StartOfLine);
|
||||
}
|
||||
|
||||
matches = Regex.Matches(input, @"^!<[a-zA-Z0-9]+");
|
||||
for (int i = 0; i < matches.Count; i++)
|
||||
{
|
||||
input = AddColorInformation(input, matches[i].Value, ConsoleColor.Blue, SearchMode.StartOfLine);
|
||||
}
|
||||
|
||||
foreach (string part in input.Split("\0"))
|
||||
{
|
||||
ConsoleColor consoleColor;
|
||||
@@ -88,7 +94,7 @@ namespace YesNt.CodeEditor
|
||||
}
|
||||
Console.ForegroundColor = consoleColor;
|
||||
Console.Write(messagePart, consoleColor);
|
||||
Console.ResetColor();
|
||||
Console.ForegroundColor = ConsoleColor.Gray;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user