Markit命令+整理代码树+更新文档

This commit is contained in:
2026-03-14 21:52:47 +08:00
parent fbb90da10e
commit d44fca86a3
14 changed files with 445 additions and 5 deletions

View File

@@ -1 +1 @@
2026-03-14 15:36:36 2026-03-14 21:51:05

View File

@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>

42
Examples/example.mi Normal file
View File

@@ -0,0 +1,42 @@
欢迎使用Markit语言
{color:red}这是红色文字{/color}
{bg:blue}这是蓝色背景{/bg}
{color:green}{bg:yellow}绿色文字黄色背景{/bg}{/color}
{color:magenta}{bg:cyan}洋红色文字青色背景{/bg}{/color}
{color:white}{bg:black}白色文字黑色背景{/bg}{/color}
{color:yellow}黄色文字{/color}
{color:cyan}青色文字{/color}
{color:darkred}深红色文字{/color}
{color:darkgreen}深绿色文字{/color}
{color:darkblue}深蓝色文字{/color}
{color:darkmagenta}深洋红色文字{/color}
{color:darkyellow}深黄色文字{/color}
{color:darkgray}深灰色文字{/color}
{color:gray}灰色文字{/color}
{color:darkcyan}深青色文字{/color}
{color:black}{bg:white}黑色文字白色背景{/bg}{/color}
组合使用:
{color:red}{bg:yellow}警告:这是一个重要信息!{/bg}{/color}
{color:green}{bg:black}成功:操作已完成!{/bg}{/color}
{color:yellow}{bg:red}错误:发生了一个错误!{/bg}{/color}
{color:cyan}{bg:blue}信息:这是一条普通信息{/bg}{/color}

View File

@@ -1 +1 @@
3e196e7 fbb90da

View File

@@ -42,6 +42,14 @@ namespace CMLeonOS
{ {
public class Kernel : Sys.Kernel public class Kernel : Sys.Kernel
{ {
// fuck Windows
// fuck Linux
// fuck Unix
// fuck macOS
// fuck ALL!!!
// a femboy's operating system :3
private static CMLeonOS.Logger.Logger _logger = CMLeonOS.Logger.Logger.Instance; private static CMLeonOS.Logger.Logger _logger = CMLeonOS.Logger.Logger.Instance;
// 创建全局CosmosVFS实例 // 创建全局CosmosVFS实例
@@ -89,7 +97,7 @@ namespace CMLeonOS
private void InitializeSystem() private void InitializeSystem()
{ {
// 修改光标样式等 // 修改光标样式等
Console.CursorSize = 14; Console.CursorSize = 100;
// 注册VFS // 注册VFS
_logger.Info("Kernel", "Starting VFS initialization"); _logger.Info("Kernel", "Starting VFS initialization");

View File

@@ -51,6 +51,26 @@ date
uptime uptime
``` ```
### ps
显示当前运行的进程列表。
**用法:**
```bash
ps
```
**输出信息:**
- ID进程ID
- Name进程名称
- Type进程类型
- Parent父进程ID
- Status运行状态
**示例:**
```bash
ps
```
### whoami ### whoami
显示当前登录的用户名。 显示当前登录的用户名。
@@ -72,6 +92,24 @@ sleep <seconds>
sleep 5 sleep 5
``` ```
### kill
终止指定的进程。
**用法:**
```bash
kill <process_id>
```
**示例:**
```bash
kill 123
```
**说明:**
- process_id要终止的进程ID
- 使用ps命令查看进程列表
- 无法终止Shell进程使用exit命令退出
## 文件系统命令 ## 文件系统命令
### ls ### ls
@@ -327,8 +365,24 @@ nano <file>
**示例:** **示例:**
```bash ```bash
nano myfile.txt nano myfile.txt
nano example.mi
``` ```
**说明:**
- 支持多种文件类型的语法高亮
- 自动根据文件扩展名应用语法高亮
- 支持的文件类型:
- Lua 文件:.lua, .los, .losb
- Ini 配置文件:.ini, .cfg, .conf, .config
- Json 文件:.json
- Markit 标记文件:.mi
- 支持智能缩进、自动补全括号和引号、智能删除
**语法高亮颜色方案:**
- Lua 文件:关键字(青色)、注释(绿色)、字符串(黄色)、数字(洋红色)、函数名(深洋红色)
- Ini 文件:节(青色)、键(黄色)、值(白色)、注释(绿色)
- Json 文件字符串绿色、数字洋红色、布尔值深洋红色、null深灰色、键黄色
- Markit 文件:标签(青色)、颜色名称(黄色)、普通文本(白色)
### hex ### hex
使用16进制编辑器编辑二进制文件。 使用16进制编辑器编辑二进制文件。
@@ -383,6 +437,62 @@ Controls:
Q - Quit Q - Quit
``` ```
### markit
渲染并显示 Markit 标记语言文件(.mi
**用法:**
```bash
markit <filename>
```
**示例:**
```bash
markit example.mi
markit /path/to/file.mi
```
**说明:**
- Markit 是一种简单的标记语言,支持文字颜色和背景色
- 文件扩展名:.mi
- 支持相对路径和绝对路径
- 自动根据文件扩展名应用语法高亮
**Markit 语法:**
```
{color:颜色名}文字{/color}
{bg:颜色名}文字{/bg}
{color:前景色}{bg:背景色}文字{/bg}{/color}
```
**支持的颜色:**
- 前景色和背景色black, darkblue, darkgreen, darkcyan, darkred, darkmagenta, darkyellow, gray, darkgray, blue, green, cyan, red, magenta, yellow, white
**语法示例:**
```
{color:red}红色文字{/color}
{bg:blue}蓝色背景{/bg}
{color:green}{bg:yellow}绿色文字黄色背景{/bg}{/color}
{color:white}{bg:black}白色文字黑色背景{/bg}{/color}
```
**实际应用示例:**
```
{color:green}{bg:black}✓ 成功:操作已完成!{/bg}{/color}
{color:red}{bg:yellow}⚠ 警告:这是一个重要信息!{/bg}{/color}
{color:white}{bg:blue} 信息:这是一条普通信息{/bg}{/color}
```
**控制键:**
- 无特殊控制键
- 直接渲染文件内容到控制台
- 支持所有颜色和背景色组合
**编辑器支持:**
- Nano 编辑器自动识别 .mi 文件并应用语法高亮
- 标签显示为青色
- 颜色名称显示为黄色
- 普通文本显示为白色
## 用户管理命令 ## 用户管理命令
### user ### user
@@ -630,6 +740,28 @@ calc 10*5
calc (3+5)*2 calc (3+5)*2
``` ```
### calcgui
启动图形化计算器界面。
**用法:**
```bash
calcgui
```
**功能:**
- 图形化计算器界面
- 支持基本运算:加、减、乘、除
- 支持键盘和鼠标操作
- 方向键导航按钮Enter选择Esc退出
**快捷键:**
- 数字键 0-9输入数字
- + - * /:选择运算符
- Enter计算结果
- C清除
- Backspace删除
- Esc/Q退出
### history ### history
显示命令历史记录。 显示命令历史记录。
@@ -665,6 +797,24 @@ background 000000
background FF0000 background FF0000
``` ```
### exportbackground
导出当前系统壁纸到指定路径。
**用法:**
```bash
exportbackground [output_path]
```
**示例:**
```bash
exportbackground
exportbackground 0:\mywallpaper.bmp
```
**说明:**
- 如果不指定输出路径,默认导出到 0:\background.bmp
- 导出的壁纸为BMP格式
### beep ### beep
播放系统提示音。 播放系统提示音。
@@ -947,6 +1097,27 @@ env PATH
env MYVAR hello env MYVAR hello
``` ```
### logs
显示系统日志。
**用法:**
```bash
logs
```
**说明:**
- 显示最近20条日志记录
- 日志级别DEBUG、INFO、WARN、ERROR、SUCCESS
- 不同级别使用不同颜色显示
- 如果日志超过20条会显示剩余数量
**日志级别颜色:**
- DEBUG灰色
- INFO青色
- WARN黄色
- ERROR红色
- SUCCESS绿色
## 注意事项 ## 注意事项
1. 所有命令不区分大小写 1. 所有命令不区分大小写

View File

@@ -200,6 +200,10 @@ namespace CMLeonOS
{ {
RenderJsonLine(line, consoleWidth); RenderJsonLine(line, consoleWidth);
} }
else if (IsMarkitFile() && settings.EnableSyntaxHighlight)
{
RenderMarkitLine(line, consoleWidth);
}
else else
{ {
Console.Write(line + new string(' ', Math.Max(0, consoleWidth - line.Length))); Console.Write(line + new string(' ', Math.Max(0, consoleWidth - line.Length)));
@@ -244,6 +248,16 @@ namespace CMLeonOS
return false; return false;
} }
private bool IsMarkitFile()
{
if (path != null)
{
string extension = System.IO.Path.GetExtension(path)?.ToLower();
return extension == ".mi";
}
return false;
}
private void RenderLuaLine(string line, int consoleWidth) private void RenderLuaLine(string line, int consoleWidth)
{ {
int pos = 0; int pos = 0;
@@ -615,6 +629,96 @@ namespace CMLeonOS
Console.ResetColor(); Console.ResetColor();
} }
private void RenderMarkitLine(string line, int consoleWidth)
{
int pos = 0;
bool inTag = false;
bool inColorTag = false;
bool inBgTag = false;
bool inCloseTag = false;
bool inColorName = false;
bool inBgName = false;
while (pos < line.Length && pos < consoleWidth)
{
char c = line[pos];
if (inTag)
{
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write(c);
pos++;
if (c == '}')
{
inTag = false;
inColorTag = false;
inBgTag = false;
inCloseTag = false;
inColorName = false;
inBgName = false;
}
else if (c == ':' && (inColorTag || inBgTag))
{
inColorName = inColorTag;
inBgName = inBgTag;
}
else if (inColorName || inBgName)
{
Console.ForegroundColor = ConsoleColor.Yellow;
}
}
else if (c == '{')
{
if (pos + 1 < line.Length && line[pos + 1] == '/')
{
inTag = true;
inCloseTag = true;
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write(c);
pos++;
Console.Write(line[pos]);
pos++;
}
else if (pos + 6 < line.Length && line.Substring(pos, 7) == "{color:")
{
inTag = true;
inColorTag = true;
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write(c);
pos++;
}
else if (pos + 4 < line.Length && line.Substring(pos, 5) == "{bg:")
{
inTag = true;
inBgTag = true;
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write(c);
pos++;
}
else
{
Console.ForegroundColor = ConsoleColor.White;
Console.Write(c);
pos++;
}
}
else
{
Console.ForegroundColor = ConsoleColor.White;
Console.Write(c);
pos++;
}
}
if (pos < consoleWidth)
{
Console.Write(new string(' ', consoleWidth - pos));
}
Console.ResetColor();
}
private bool IsLuaNumber(string line, int pos) private bool IsLuaNumber(string line, int pos)
{ {
if (pos >= line.Length) return false; if (pos >= line.Length) return false;
@@ -1606,7 +1710,7 @@ namespace CMLeonOS
"2. Auto Complete Brackets (All Files)", "2. Auto Complete Brackets (All Files)",
"3. Auto Complete Quotes (All Files)", "3. Auto Complete Quotes (All Files)",
"4. Smart Delete (All Files)", "4. Smart Delete (All Files)",
"5. Syntax Highlight (Lua/Ini/Json)", "5. Syntax Highlight (Lua/Ini/Json/Markit)",
"6. Save and Exit" "6. Save and Exit"
}; };

View File

@@ -233,6 +233,9 @@ namespace CMLeonOS.shell
case "hex": case "hex":
shell.EditHexFile(args); shell.EditHexFile(args);
break; break;
case "markit":
shell.ProcessMarkit(args);
break;
case "alias": case "alias":
shell.ProcessAlias(args); shell.ProcessAlias(args);
break; break;

View File

@@ -0,0 +1,107 @@
using System;
namespace CMLeonOS.Commands
{
public static class MarkitCommand
{
public static void Execute(string args, Shell shell, CMLeonOS.FileSystem fileSystem)
{
if (string.IsNullOrWhiteSpace(args))
{
Console.WriteLine("Usage: markit <filename>");
Console.WriteLine("Markit syntax:");
Console.WriteLine(" {color:red}Red text{/color}");
Console.WriteLine(" {bg:blue}Blue background{/bg}");
Console.WriteLine(" {color:green}{bg:yellow}Green text on yellow background{/bg}{/color}");
return;
}
string filePath = args.Trim();
try
{
string content = fileSystem.ReadFile(filePath);
if (content == null)
{
Console.WriteLine($"Error: File '{filePath}' not found.");
return;
}
RenderMarkit(content);
}
catch (Exception ex)
{
Console.WriteLine($"Error reading file: {ex.Message}");
}
}
private static void RenderMarkit(string content)
{
int i = 0;
while (i < content.Length)
{
if (content.Substring(i).StartsWith("{color:"))
{
int end = content.IndexOf('}', i);
if (end > i + 7)
{
string colorName = content.Substring(i + 7, end - i - 7).ToLower();
ConsoleColor color = ParseColor(colorName);
Console.ForegroundColor = color;
i = end + 1;
continue;
}
}
else if (content.Substring(i).StartsWith("{bg:"))
{
int end = content.IndexOf('}', i);
if (end > i + 4)
{
string colorName = content.Substring(i + 4, end - i - 4).ToLower();
ConsoleColor color = ParseColor(colorName);
Console.BackgroundColor = color;
i = end + 1;
continue;
}
}
else if (content.Substring(i).StartsWith("{/color}"))
{
Console.ForegroundColor = ConsoleColor.White;
i += 8;
continue;
}
else if (content.Substring(i).StartsWith("{/bg}"))
{
Console.BackgroundColor = ConsoleColor.Black;
i += 5;
continue;
}
Console.Write(content[i]);
i++;
}
Console.ResetColor();
}
private static ConsoleColor ParseColor(string colorName)
{
if (colorName == "black") return ConsoleColor.Black;
if (colorName == "darkblue") return ConsoleColor.DarkBlue;
if (colorName == "darkgreen") return ConsoleColor.DarkGreen;
if (colorName == "darkcyan") return ConsoleColor.DarkCyan;
if (colorName == "darkred") return ConsoleColor.DarkRed;
if (colorName == "darkmagenta") return ConsoleColor.DarkMagenta;
if (colorName == "darkyellow") return ConsoleColor.DarkYellow;
if (colorName == "gray") return ConsoleColor.Gray;
if (colorName == "darkgray") return ConsoleColor.DarkGray;
if (colorName == "blue") return ConsoleColor.Blue;
if (colorName == "green") return ConsoleColor.Green;
if (colorName == "cyan") return ConsoleColor.Cyan;
if (colorName == "red") return ConsoleColor.Red;
if (colorName == "magenta") return ConsoleColor.Magenta;
if (colorName == "yellow") return ConsoleColor.Yellow;
if (colorName == "white") return ConsoleColor.White;
return ConsoleColor.White;
}
}
}

View File

@@ -1087,6 +1087,11 @@ namespace CMLeonOS
Commands.Utility.HexCommand.EditHexFile(args); Commands.Utility.HexCommand.EditHexFile(args);
} }
public void ProcessMarkit(string args)
{
Commands.MarkitCommand.Execute(args, this, fileSystem);
}
public void CreateFTP() public void CreateFTP()
{ {
Console.WriteLine("===================================="); Console.WriteLine("====================================");