mirror of
https://github.com/Leonmmcoset/CMLeonOS.git
synced 2026-04-21 19:24:00 +00:00
重写BootMenu
This commit is contained in:
327
Branswe.md
327
Branswe.md
@@ -1,327 +0,0 @@
|
|||||||
# Branswe编程语言使用指南
|
|
||||||
|
|
||||||
## 简介
|
|
||||||
|
|
||||||
Branswe是一种简单的编程语言,用于CMLeonOS系统中进行脚本编写和自动化操作。它提供了基本的控制台操作、变量管理、条件判断、循环、文件系统操作等功能。
|
|
||||||
|
|
||||||
## 基本语法
|
|
||||||
|
|
||||||
### 命令格式
|
|
||||||
```
|
|
||||||
命令名 [参数]
|
|
||||||
```
|
|
||||||
|
|
||||||
### 注释
|
|
||||||
```
|
|
||||||
# 这是注释
|
|
||||||
```
|
|
||||||
|
|
||||||
## 变量操作
|
|
||||||
|
|
||||||
### 定义文本变量
|
|
||||||
```
|
|
||||||
var(text) 变量名 = 值
|
|
||||||
```
|
|
||||||
|
|
||||||
### 变量赋值
|
|
||||||
```
|
|
||||||
var() 变量名 = 变量2
|
|
||||||
```
|
|
||||||
|
|
||||||
### 变量删除
|
|
||||||
```
|
|
||||||
var() 变量名 rm
|
|
||||||
```
|
|
||||||
|
|
||||||
### 变量运算
|
|
||||||
```
|
|
||||||
var() 变量名 =+ 变量2
|
|
||||||
var() 变量名 =- 变量2
|
|
||||||
var() 变量名 =* 变量2
|
|
||||||
var() 变量名 =/ 变量2
|
|
||||||
```
|
|
||||||
|
|
||||||
### 获取变量值
|
|
||||||
```
|
|
||||||
ref getvar 变量名
|
|
||||||
```
|
|
||||||
|
|
||||||
## 控制台操作
|
|
||||||
|
|
||||||
### 显示文本(不换行)
|
|
||||||
```
|
|
||||||
conshow 变量名
|
|
||||||
```
|
|
||||||
|
|
||||||
### 显示文本(换行)
|
|
||||||
```
|
|
||||||
conshowl 变量名
|
|
||||||
```
|
|
||||||
|
|
||||||
### 清屏
|
|
||||||
```
|
|
||||||
concls
|
|
||||||
```
|
|
||||||
|
|
||||||
### 输入
|
|
||||||
```
|
|
||||||
coninput 变量名
|
|
||||||
```
|
|
||||||
|
|
||||||
### 蜂鸣
|
|
||||||
```
|
|
||||||
conbeep
|
|
||||||
```
|
|
||||||
|
|
||||||
## 系统引用
|
|
||||||
|
|
||||||
### 鼠标位置
|
|
||||||
```
|
|
||||||
ref mousex
|
|
||||||
ref mousey
|
|
||||||
```
|
|
||||||
|
|
||||||
### 屏幕尺寸
|
|
||||||
```
|
|
||||||
ref screenx
|
|
||||||
ref screeny
|
|
||||||
```
|
|
||||||
|
|
||||||
### 控制台颜色
|
|
||||||
```
|
|
||||||
ref concolour-b
|
|
||||||
ref concolour-f
|
|
||||||
```
|
|
||||||
|
|
||||||
### 磁盘信息
|
|
||||||
```
|
|
||||||
ref getalldisks
|
|
||||||
```
|
|
||||||
|
|
||||||
## 条件判断
|
|
||||||
|
|
||||||
### decide语句
|
|
||||||
```
|
|
||||||
decide 变量1 操作符 变量2
|
|
||||||
```
|
|
||||||
|
|
||||||
支持的操作符:
|
|
||||||
- `==` 等于
|
|
||||||
- `!=` 不等于
|
|
||||||
- `>` 大于
|
|
||||||
- `<` 小于
|
|
||||||
- `>=` 大于等于
|
|
||||||
- `<=` 小于等于
|
|
||||||
|
|
||||||
### if语句
|
|
||||||
```
|
|
||||||
if 条件 then 真代码 else 假代码
|
|
||||||
```
|
|
||||||
|
|
||||||
### 示例
|
|
||||||
```
|
|
||||||
var(text) num1 = 10
|
|
||||||
var(text) num2 = 20
|
|
||||||
decide num1 == num2
|
|
||||||
if [] then conshow match else conshow no match
|
|
||||||
```
|
|
||||||
|
|
||||||
## 循环
|
|
||||||
|
|
||||||
### loop语句
|
|
||||||
```
|
|
||||||
loop << 变量名
|
|
||||||
```
|
|
||||||
|
|
||||||
执行变量中的代码,无限循环。
|
|
||||||
|
|
||||||
### 示例
|
|
||||||
```
|
|
||||||
var(text) code = conshow hello
|
|
||||||
loop << code
|
|
||||||
```
|
|
||||||
|
|
||||||
## 字符串操作
|
|
||||||
|
|
||||||
### 读取字符串并执行
|
|
||||||
```
|
|
||||||
rstr 变量名
|
|
||||||
```
|
|
||||||
|
|
||||||
执行变量中存储的代码(支持\n换行)。
|
|
||||||
|
|
||||||
### 示例
|
|
||||||
```
|
|
||||||
var(text) mycode = conshow hello\nconshow world
|
|
||||||
rstr mycode
|
|
||||||
```
|
|
||||||
|
|
||||||
## 文件系统操作
|
|
||||||
|
|
||||||
### 注册VFS
|
|
||||||
```
|
|
||||||
diskfile reg
|
|
||||||
```
|
|
||||||
|
|
||||||
### 创建文件
|
|
||||||
```
|
|
||||||
diskfile create file 路径
|
|
||||||
```
|
|
||||||
|
|
||||||
### 创建目录
|
|
||||||
```
|
|
||||||
diskfile create dir 路径
|
|
||||||
```
|
|
||||||
|
|
||||||
### 写入文件
|
|
||||||
```
|
|
||||||
diskfile write 内容 to 路径
|
|
||||||
```
|
|
||||||
|
|
||||||
### 示例
|
|
||||||
```
|
|
||||||
diskfile reg
|
|
||||||
diskfile create file /test.txt
|
|
||||||
var(text) content = Hello, World!
|
|
||||||
diskfile write content to /test.txt
|
|
||||||
```
|
|
||||||
|
|
||||||
## 系统功能
|
|
||||||
|
|
||||||
### 睡眠
|
|
||||||
```
|
|
||||||
sleep 变量名
|
|
||||||
```
|
|
||||||
|
|
||||||
### 电源管理
|
|
||||||
```
|
|
||||||
power off
|
|
||||||
power reboot
|
|
||||||
```
|
|
||||||
|
|
||||||
### 结束程序
|
|
||||||
```
|
|
||||||
end
|
|
||||||
```
|
|
||||||
|
|
||||||
## 方法定义
|
|
||||||
|
|
||||||
### 定义方法
|
|
||||||
```
|
|
||||||
method 变量部分 << 代码部分
|
|
||||||
```
|
|
||||||
|
|
||||||
### 调用方法
|
|
||||||
```
|
|
||||||
方法名 参数
|
|
||||||
```
|
|
||||||
|
|
||||||
### 示例
|
|
||||||
```
|
|
||||||
var(text) printname = print
|
|
||||||
var(text) myname = Leon
|
|
||||||
method printname [] << conshow []
|
|
||||||
printname myname
|
|
||||||
```
|
|
||||||
|
|
||||||
## 完整示例
|
|
||||||
|
|
||||||
### 示例1:Hello World
|
|
||||||
```
|
|
||||||
# 简单的Hello World程序
|
|
||||||
var(text) hello = Hello, Branswe!
|
|
||||||
conshow hello
|
|
||||||
```
|
|
||||||
|
|
||||||
### 示例2:变量操作
|
|
||||||
```
|
|
||||||
# 变量定义和运算
|
|
||||||
var(text) num1 = 10
|
|
||||||
var(text) num2 = 20
|
|
||||||
var() num1 =+ num2
|
|
||||||
conshowl num1
|
|
||||||
```
|
|
||||||
|
|
||||||
### 示例3:条件判断
|
|
||||||
```
|
|
||||||
# 条件判断示例
|
|
||||||
var(text) a = 10
|
|
||||||
var(text) b = 20
|
|
||||||
decide a < b
|
|
||||||
if [] then conshow a is smaller else conshow a is larger
|
|
||||||
```
|
|
||||||
|
|
||||||
### 示例4:循环
|
|
||||||
```
|
|
||||||
# 循环示例
|
|
||||||
var(text) code = conshow loop\nsleep 1000
|
|
||||||
loop << code
|
|
||||||
```
|
|
||||||
|
|
||||||
### 示例5:文件操作
|
|
||||||
```
|
|
||||||
# 文件操作示例
|
|
||||||
diskfile reg
|
|
||||||
diskfile create file /test.txt
|
|
||||||
var(text) content = Hello, File System!
|
|
||||||
diskfile write content to /test.txt
|
|
||||||
```
|
|
||||||
|
|
||||||
### 示例6:系统功能
|
|
||||||
```
|
|
||||||
# 系统功能示例
|
|
||||||
conbeep
|
|
||||||
var(text) wait = 1000
|
|
||||||
sleep wait
|
|
||||||
ref mousex
|
|
||||||
conshowl []
|
|
||||||
```
|
|
||||||
|
|
||||||
### 示例7:自定义方法
|
|
||||||
```
|
|
||||||
# 自定义方法示例
|
|
||||||
var(text) greet = greet
|
|
||||||
var(text) name = Leon
|
|
||||||
method greet [] << conshow Hello, []!
|
|
||||||
greet name
|
|
||||||
```
|
|
||||||
|
|
||||||
## 注意事项
|
|
||||||
|
|
||||||
1. **大小写敏感**:命令和变量名区分大小写
|
|
||||||
2. **空格处理**:参数之间用空格分隔
|
|
||||||
3. **变量存储**:所有变量都作为文本存储,运算时会自动转换
|
|
||||||
4. **注释支持**:使用#号添加注释
|
|
||||||
5. **变量作用域**:变量在整个脚本中有效
|
|
||||||
6. **无限循环**:loop命令会无限循环,需要使用end或其他方式退出
|
|
||||||
7. **文件系统**:使用diskfile前需要先执行diskfile reg注册VFS
|
|
||||||
|
|
||||||
## 最佳实践
|
|
||||||
|
|
||||||
1. **添加注释**:在复杂逻辑前添加注释说明
|
|
||||||
2. **使用变量**:避免硬编码,使用变量提高灵活性
|
|
||||||
3. **错误检查**:在使用变量前检查其值
|
|
||||||
4. **代码格式**:保持代码缩进和格式一致
|
|
||||||
5. **测试验证**:逐步测试每个功能确保正确性
|
|
||||||
|
|
||||||
## 参考资料
|
|
||||||
|
|
||||||
- CMLeonOS Shell命令
|
|
||||||
- Branswe编程语言规范
|
|
||||||
- Cosmos系统文档
|
|
||||||
|
|
||||||
## 更新日志
|
|
||||||
|
|
||||||
### 版本2.0
|
|
||||||
- 更新了所有命令的实际语法
|
|
||||||
- 添加了文件系统操作支持
|
|
||||||
- 添加了系统引用命令
|
|
||||||
- 添加了电源管理功能
|
|
||||||
- 添加了自定义方法功能
|
|
||||||
- 修正了条件判断和循环的语法
|
|
||||||
- 完善了变量操作命令
|
|
||||||
|
|
||||||
### 版本1.0
|
|
||||||
- 初始版本
|
|
||||||
- 添加了CMLeonOS兼容性支持
|
|
||||||
- 完善了错误处理
|
|
||||||
@@ -1 +1 @@
|
|||||||
2026-03-27 21:26:04
|
2026-03-28 21:43:07
|
||||||
@@ -135,7 +135,7 @@
|
|||||||
<EmbeddedResource Include="Gui\Resources\Wallpaper_1280_800.bmp" />
|
<EmbeddedResource Include="Gui\Resources\Wallpaper_1280_800.bmp" />
|
||||||
<EmbeddedResource Include="GitCommit.txt" />
|
<EmbeddedResource Include="GitCommit.txt" />
|
||||||
<EmbeddedResource Include="BuildTime.txt" />
|
<EmbeddedResource Include="BuildTime.txt" />
|
||||||
<EmbeddedResource Include="sh.exe" />
|
<EmbeddedResource Include="sh.bin" />
|
||||||
<EmbeddedResource Include="LuaApps\*.lua" />
|
<EmbeddedResource Include="LuaApps\*.lua" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
7a7d44e
|
0988f4c
|
||||||
@@ -33,46 +33,111 @@ namespace CMLeonOS
|
|||||||
|
|
||||||
internal static class BootMenu
|
internal static class BootMenu
|
||||||
{
|
{
|
||||||
|
private const int MinPanelWidth = 58;
|
||||||
|
private const int MaxPanelWidth = 86;
|
||||||
|
|
||||||
private static bool UserDatExists()
|
private static bool UserDatExists()
|
||||||
{
|
{
|
||||||
return File.Exists(@"0:\system\user.dat");
|
return File.Exists(@"0:\system\user.dat");
|
||||||
}
|
}
|
||||||
private static void PrintOption(string text, bool selected)
|
|
||||||
|
private static string FitText(string text, int width)
|
||||||
{
|
{
|
||||||
Console.SetCursorPosition(1, Console.GetCursorPosition().Top);
|
if (string.IsNullOrEmpty(text))
|
||||||
|
{
|
||||||
|
return string.Empty.PadRight(width);
|
||||||
|
}
|
||||||
|
|
||||||
Console.BackgroundColor = selected ? ConsoleColor.White : ConsoleColor.Black;
|
if (text.Length > width)
|
||||||
Console.ForegroundColor = selected ? ConsoleColor.Black : ConsoleColor.White;
|
{
|
||||||
|
if (width <= 3)
|
||||||
|
{
|
||||||
|
return text.Substring(0, width);
|
||||||
|
}
|
||||||
|
return text.Substring(0, width - 3) + "...";
|
||||||
|
}
|
||||||
|
|
||||||
Console.WriteLine(text);
|
return text.PadRight(width);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void WriteAt(int x, int y, string text, ConsoleColor fg, ConsoleColor bg)
|
||||||
|
{
|
||||||
|
if (y < 0 || y >= Console.WindowHeight)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.SetCursorPosition(Math.Max(0, x), y);
|
||||||
|
Console.ForegroundColor = fg;
|
||||||
|
Console.BackgroundColor = bg;
|
||||||
|
Console.Write(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void DrawPanelLine(int left, int top, int width, int row, string content, ConsoleColor contentFg, ConsoleColor contentBg)
|
||||||
|
{
|
||||||
|
int innerWidth = width - 2;
|
||||||
|
int y = top + row;
|
||||||
|
|
||||||
|
// Keep borders in a consistent theme color.
|
||||||
|
WriteAt(left, y, "|", ConsoleColor.Cyan, ConsoleColor.Black);
|
||||||
|
WriteAt(left + 1, y, FitText(content, innerWidth), contentFg, contentBg);
|
||||||
|
WriteAt(left + width - 1, y, "|", ConsoleColor.Cyan, ConsoleColor.Black);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void DrawHorizontalBorder(int left, int y, int width, bool topBorder, ConsoleColor fg, ConsoleColor bg)
|
||||||
|
{
|
||||||
|
string mid = new string('-', width - 2);
|
||||||
|
string line = topBorder ? ("+" + mid + "+") : ("+" + mid + "+");
|
||||||
|
WriteAt(left, y, line, fg, bg);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Render(int selIdx, int remainingTime)
|
private static void Render(int selIdx, int remainingTime)
|
||||||
{
|
{
|
||||||
Console.BackgroundColor = ConsoleColor.Black;
|
Console.BackgroundColor = ConsoleColor.Black;
|
||||||
Console.ForegroundColor = ConsoleColor.Cyan;
|
Console.ForegroundColor = ConsoleColor.White;
|
||||||
|
|
||||||
Console.SetCursorPosition(0, 0);
|
|
||||||
|
|
||||||
uint mem = Cosmos.Core.CPU.GetAmountOfRAM();
|
|
||||||
Console.WriteLine($"{Version.DisplayVersion} [{mem} MB memory]");
|
|
||||||
Console.WriteLine($"Build Time: {GetBuildTime()}");
|
|
||||||
Console.WriteLine();
|
|
||||||
Console.WriteLine($"Auto-select in {remainingTime} seconds...");
|
|
||||||
Console.WriteLine();
|
|
||||||
Console.WriteLine("Select an option:");
|
|
||||||
Console.WriteLine();
|
|
||||||
|
|
||||||
bool userDatExists = UserDatExists();
|
bool userDatExists = UserDatExists();
|
||||||
int optionIndex = 0;
|
string[] options = userDatExists
|
||||||
|
? new[] { "CMLeonOS Shell", "CMLeonOS Desktop", "Reboot", "Shutdown" }
|
||||||
|
: new[] { "CMLeonOS Shell", "Reboot", "Shutdown" };
|
||||||
|
|
||||||
PrintOption("CMLeonOS (Shell)", selIdx == optionIndex++);
|
int width = Console.WindowWidth;
|
||||||
if (userDatExists)
|
int height = Console.WindowHeight;
|
||||||
|
int panelWidth = Math.Min(MaxPanelWidth, Math.Max(MinPanelWidth, width - 8));
|
||||||
|
int panelLeft = Math.Max(0, (width - panelWidth) / 2);
|
||||||
|
int contentLines = 9 + options.Length;
|
||||||
|
int panelTop = Math.Max(0, (height - contentLines) / 2);
|
||||||
|
|
||||||
|
DrawHorizontalBorder(panelLeft, panelTop, panelWidth, true, ConsoleColor.Cyan, ConsoleColor.Black);
|
||||||
|
DrawPanelLine(panelLeft, panelTop, panelWidth, 1, " CMLeonOS Boot Manager ", ConsoleColor.Black, ConsoleColor.Cyan);
|
||||||
|
DrawPanelLine(panelLeft, panelTop, panelWidth, 2, string.Empty, ConsoleColor.White, ConsoleColor.Black);
|
||||||
|
|
||||||
|
uint mem = CPU.GetAmountOfRAM();
|
||||||
|
DrawPanelLine(panelLeft, panelTop, panelWidth, 3, $" Version : {Version.DisplayVersion}", ConsoleColor.Gray, ConsoleColor.Black);
|
||||||
|
DrawPanelLine(panelLeft, panelTop, panelWidth, 4, $" Memory : {mem} MB", ConsoleColor.Gray, ConsoleColor.Black);
|
||||||
|
DrawPanelLine(panelLeft, panelTop, panelWidth, 5, $" Build : {GetBuildTime()}", ConsoleColor.DarkGray, ConsoleColor.Black);
|
||||||
|
DrawPanelLine(panelLeft, panelTop, panelWidth, 6, string.Empty, ConsoleColor.White, ConsoleColor.Black);
|
||||||
|
DrawPanelLine(panelLeft, panelTop, panelWidth, 7, $" Auto boot in {remainingTime}s", ConsoleColor.Yellow, ConsoleColor.Black);
|
||||||
|
DrawPanelLine(panelLeft, panelTop, panelWidth, 8, " Use Up/Down to select, Enter to boot", ConsoleColor.DarkGray, ConsoleColor.Black);
|
||||||
|
|
||||||
|
for (int i = 0; i < options.Length; i++)
|
||||||
{
|
{
|
||||||
PrintOption("CMLeonOS (Desktop)", selIdx == optionIndex++);
|
bool selected = i == selIdx;
|
||||||
|
string prefix = selected ? " > " : " ";
|
||||||
|
string text = prefix + options[i];
|
||||||
|
DrawPanelLine(
|
||||||
|
panelLeft,
|
||||||
|
panelTop,
|
||||||
|
panelWidth,
|
||||||
|
9 + i,
|
||||||
|
text,
|
||||||
|
selected ? ConsoleColor.Black : ConsoleColor.White,
|
||||||
|
selected ? ConsoleColor.White : ConsoleColor.Black
|
||||||
|
);
|
||||||
}
|
}
|
||||||
PrintOption("Reboot", selIdx == optionIndex++);
|
|
||||||
PrintOption("Shutdown", selIdx == optionIndex++);
|
DrawHorizontalBorder(panelLeft, panelTop + contentLines, panelWidth, false, ConsoleColor.Cyan, ConsoleColor.Black);
|
||||||
|
Console.ResetColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static BootMenuAction Confirm(int selIdx)
|
private static BootMenuAction Confirm(int selIdx)
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ namespace CMLeonOS
|
|||||||
return extension switch
|
return extension switch
|
||||||
{
|
{
|
||||||
// 这是一堆后缀名的颜色标注,但是许多后缀名还不支持,先保留
|
// 这是一堆后缀名的颜色标注,但是许多后缀名还不支持,先保留
|
||||||
".exe" => ConsoleColor.Green,
|
".bin" => ConsoleColor.Green,
|
||||||
".cla" => ConsoleColor.Green,
|
".cla" => ConsoleColor.Green,
|
||||||
".lua" => ConsoleColor.Cyan,
|
".lua" => ConsoleColor.Cyan,
|
||||||
".js" => ConsoleColor.Cyan,
|
".js" => ConsoleColor.Cyan,
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ namespace CMLeonOS.Commands
|
|||||||
{
|
{
|
||||||
public static class ExportTestExeCommand
|
public static class ExportTestExeCommand
|
||||||
{
|
{
|
||||||
[ManifestResourceStream(ResourceName = "CMLeonOS.sh.exe")]
|
[ManifestResourceStream(ResourceName = "CMLeonOS.sh.bin")]
|
||||||
private static byte[] testExeBytes;
|
private static byte[] testExeBytes;
|
||||||
|
|
||||||
public static void ExportTestExe(string outputPath)
|
public static void ExportTestExe(string outputPath)
|
||||||
@@ -31,18 +31,18 @@ namespace CMLeonOS.Commands
|
|||||||
{
|
{
|
||||||
if (testExeBytes == null || testExeBytes.Length == 0)
|
if (testExeBytes == null || testExeBytes.Length == 0)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Error: No test.exe found in embedded resources.");
|
Console.WriteLine("Error: No test.bin found in embedded resources.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string destinationPath = string.IsNullOrEmpty(outputPath) ? @"0:\test.exe" : outputPath;
|
string destinationPath = string.IsNullOrEmpty(outputPath) ? @"0:\test.bin" : outputPath;
|
||||||
|
|
||||||
File.WriteAllBytes(destinationPath, testExeBytes);
|
File.WriteAllBytes(destinationPath, testExeBytes);
|
||||||
Console.WriteLine($"Test.exe exported successfully to: {destinationPath}");
|
Console.WriteLine($"Test.bin exported successfully to: {destinationPath}");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Error exporting test.exe: {ex.Message}");
|
Console.WriteLine($"Error exporting test.bin: {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user