Compare commits

...

4 Commits

Author SHA1 Message Date
Leonmmcoset
9b783e057a 增加显示颜色测试 2026-02-24 21:48:08 +08:00
Leonmmcoset
14149aab9d 语法高亮 2026-02-24 21:15:38 +08:00
Leonmmcoset
e0e7da7ac2 用户名空白检测+修复一重大bug 2026-02-24 20:09:10 +08:00
Leonmmcoset
0386511a00 增加版权信息 2026-02-19 17:37:42 +08:00
6 changed files with 179 additions and 25 deletions

View File

@@ -1 +1 @@
2026-02-19 17:19:17
2026-02-24 21:45:40

View File

@@ -1 +1 @@
8e60a49
14149aa

View File

@@ -72,7 +72,7 @@ namespace CMLeonOS
Console.Clear();
Console.WriteLine("Kernel load done!");
Console.WriteLine(@"-------------------------------------------------");
Console.WriteLine(@"----------------------------------------------------------");
Console.WriteLine(@" ____ __ __ _ ___ ____ ");
Console.WriteLine(@" / ___| \/ | | ___ ___ _ __ / _ \/ ___| ");
Console.WriteLine(@" | | | |\/| | | / _ \/ _ \| '_ \| | | \___ \ ");
@@ -80,8 +80,8 @@ namespace CMLeonOS
Console.WriteLine(@" \____|_| |_|_____\___|\___/|_| |_|____/|____/ ");
Console.WriteLine();
Console.WriteLine("The CMLeonOS Project");
Console.WriteLine("By LeonOS 2 Developement Team");
Console.WriteLine(@"-------------------------------------------------");
Console.WriteLine("(C) LeonOS 2 Developer Team 2025-2026. All rights reserved.");
Console.WriteLine(@"----------------------------------------------------------");
// 注册VFS
_logger.Info("Kernel", "Starting VFS initialization");
@@ -254,6 +254,8 @@ namespace CMLeonOS
// 检查并执行启动脚本
ExecuteStartupScript();
ExecuteStartupTest();
if (System.IO.File.Exists("0:\\system\\zen"))
{
Console.WriteLine("=====================================");
@@ -471,6 +473,44 @@ namespace CMLeonOS
}
}
private void ExecuteStartupTest()
{
Console.BackgroundColor = ConsoleColor.Red;
Console.Write(" ");
Console.BackgroundColor = ConsoleColor.Yellow;
Console.Write(" ");
Console.BackgroundColor = ConsoleColor.Green;
Console.Write(" ");
Console.BackgroundColor = ConsoleColor.Cyan;
Console.Write(" ");
Console.BackgroundColor = ConsoleColor.Blue;
Console.Write(" ");
Console.BackgroundColor = ConsoleColor.Magenta;
Console.Write(" ");
Console.BackgroundColor = ConsoleColor.White;
Console.Write(" ");
Console.BackgroundColor = ConsoleColor.DarkBlue;
Console.Write(" ");
Console.BackgroundColor = ConsoleColor.DarkCyan;
Console.Write(" ");
Console.BackgroundColor = ConsoleColor.DarkGreen;
Console.Write(" ");
Console.BackgroundColor = ConsoleColor.DarkYellow;
Console.Write(" ");
Console.BackgroundColor = ConsoleColor.DarkRed;
Console.Write(" ");
Console.BackgroundColor = ConsoleColor.Gray;
Console.Write(" ");
Console.BackgroundColor = ConsoleColor.DarkGray;
Console.Write(" ");
Console.BackgroundColor = ConsoleColor.DarkMagenta;
Console.Write(" ");
Console.BackgroundColor = ConsoleColor.Black;
Console.Write(" ");
Console.WriteLine("");
Console.ResetColor();
}
private string FormatBytes(long bytes)
{
string[] units = { "B", "KB", "MB", "GB", "TB" };

View File

@@ -308,7 +308,11 @@ namespace CMLeonOS
{
if (File.Exists(fullPath))
{
return File.ReadAllText(fullPath);
using (FileStream fs = new FileStream(fullPath, FileMode.Open, FileAccess.Read))
using (StreamReader sr = new StreamReader(fs))
{
return sr.ReadToEnd();
}
}
else
{
@@ -389,15 +393,15 @@ namespace CMLeonOS
return currentDirectory;
}
char[] invalidChars = { '<', '>', ':', '"', '|', '?', '*' };
foreach (char c in invalidChars)
{
if (path.Contains(c.ToString()))
{
Console.WriteLine($"Error: Invalid character in path: '{c}'");
return currentDirectory;
}
}
//char[] invalidChars = { '<', '>', ':', '"', '|', '?', '*' };
//foreach (char c in invalidChars)
//{
// if (path.Contains(c.ToString()))
// {
// Console.WriteLine($"Error: Invalid character in path: '{c}'");
// return currentDirectory;
// }
//}
if (path.Contains("//") || path.Contains("\\\\"))
{

View File

@@ -55,7 +55,7 @@ namespace CMLeonOS
private static bool ContainsInvalidChars(string input)
{
char[] invalidChars = { '<', '>', ':', '"', '|', '?', '*', '/', '\\' };
char[] invalidChars = { '<', '>', ':', '"', '|', '?', '*', '/', '\\', ' ' };
foreach (char c in invalidChars)
{
if (input.Contains(c.ToString()))
@@ -405,7 +405,7 @@ namespace CMLeonOS
{
CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.Red, global::System.ConsoleColor.Black);
global::System.Console.SetCursorPosition(7, 24);
global::System.Console.Write("Username contains invalid characters: < > : \" | ? / \\ ");
global::System.Console.Write("Username contains invalid characters: < > : \" | ? * / \\ space");
CMLeonOS.UI.TUIHelper.SetColors(global::System.ConsoleColor.White, global::System.ConsoleColor.Black);
global::System.Console.SetCursorPosition(7, 7);
global::System.Console.Write("Username: ");

View File

@@ -47,15 +47,22 @@ namespace CMLeonOS
if (value != null && fileSystem != null)
{
string fullPath = fileSystem.GetFullPath(value);
if (System.IO.File.Exists(fullPath))
try
{
string fullPath = fileSystem.GetFullPath(value);
string text = fileSystem.ReadFile(fullPath);
text = text.Replace("\r\n", "\n");
lines.AddRange(text.Split('\n'));
if (!string.IsNullOrEmpty(text))
{
text = text.Replace("\r\n", "\n");
lines.AddRange(text.Split('\n'));
}
else
{
lines.Add(string.Empty);
}
}
else
catch
{
lines.Add(string.Empty);
}
@@ -90,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)
@@ -100,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)));
}
}
}
@@ -111,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()
{