diff --git a/BuildTime.txt b/BuildTime.txt index 9201770..d9a4671 100644 --- a/BuildTime.txt +++ b/BuildTime.txt @@ -1 +1 @@ -2026-02-24 20:06:20 \ No newline at end of file +2026-02-24 20:31:52 \ No newline at end of file diff --git a/GitCommit.txt b/GitCommit.txt index 297fba9..b957985 100644 --- a/GitCommit.txt +++ b/GitCommit.txt @@ -1 +1 @@ -0386511 \ No newline at end of file +e0e7da7 \ No newline at end of file diff --git a/editor/Nano.cs b/editor/Nano.cs index a4f666d..fdbe546 100644 --- a/editor/Nano.cs +++ b/editor/Nano.cs @@ -97,7 +97,6 @@ namespace CMLeonOS { int y = i - scrollY + TITLEBAR_HEIGHT; if (y < TITLEBAR_HEIGHT || y >= consoleHeight - SHORTCUT_BAR_HEIGHT) continue; - Console.SetCursorPosition(0, y); if (i >= lines.Count || scrollX >= lines[i].Length) @@ -107,7 +106,15 @@ namespace CMLeonOS else { string line = lines[i].Substring(scrollX, Math.Min(consoleWidth, lines[i].Length - scrollX)); - Console.Write(line + new string(' ', Math.Max(0, consoleWidth - line.Length))); + + if (IsLuaFile()) + { + RenderLuaLine(line, consoleWidth); + } + else + { + Console.Write(line + new string(' ', Math.Max(0, consoleWidth - line.Length))); + } } } @@ -118,6 +125,102 @@ namespace CMLeonOS Console.SetCursorPosition(linePos - scrollX, currentLine + TITLEBAR_HEIGHT - scrollY); } + private bool IsLuaFile() + { + if (path != null) + { + string extension = System.IO.Path.GetExtension(path)?.ToLower(); + return extension == ".lua"; + } + return false; + } + + private void RenderLuaLine(string line, int consoleWidth) + { + int pos = 0; + bool inString = false; + bool inComment = false; + + while (pos < line.Length && pos < consoleWidth) + { + if (inComment) + { + Console.ForegroundColor = ConsoleColor.Green; + Console.Write(line[pos]); + pos++; + } + else if (line.Substring(pos).StartsWith("--")) + { + inComment = true; + Console.ForegroundColor = ConsoleColor.Green; + Console.Write(line.Substring(pos)); + break; + } + else if (inString) + { + if (line[pos] == '"' || line[pos] == '\'') + { + Console.ForegroundColor = ConsoleColor.Yellow; + Console.Write(line[pos]); + inString = false; + } + else + { + Console.ForegroundColor = ConsoleColor.Yellow; + Console.Write(line[pos]); + } + pos++; + } + else + { + if (line[pos] == '"' || line[pos] == '\'') + { + inString = true; + Console.ForegroundColor = ConsoleColor.Yellow; + Console.Write(line[pos]); + pos++; + } + else if (IsLuaKeyword(line, pos)) + { + Console.ForegroundColor = ConsoleColor.Cyan; + Console.Write(line[pos]); + pos++; + } + else + { + Console.ForegroundColor = ConsoleColor.White; + Console.Write(line[pos]); + pos++; + } + } + } + + if (pos < consoleWidth) + { + Console.Write(new string(' ', consoleWidth - pos)); + } + + Console.ResetColor(); + } + + private bool IsLuaKeyword(string line, int pos) + { + string[] keywords = { "function", "end", "if", "then", "else", "elseif", "while", "do", "for", "return", "local", "true", "false", "nil", "and", "or", "not", "break", "repeat", "until" }; + + foreach (string keyword in keywords) + { + if (pos + keyword.Length <= line.Length && line.Substring(pos, keyword.Length) == keyword) + { + char nextChar = pos + keyword.Length < line.Length ? line[pos + keyword.Length] : ' '; + if (!char.IsLetterOrDigit(nextChar)) + { + return true; + } + } + } + return false; + } + // Insert a new line at the cursor. private void InsertLine() {