diff --git a/BuildTime.txt b/BuildTime.txt index f56512b..28ed575 100644 --- a/BuildTime.txt +++ b/BuildTime.txt @@ -1 +1 @@ -2026-03-22 18:25:04 \ No newline at end of file +2026-03-22 19:16:27 \ No newline at end of file diff --git a/GitCommit.txt b/GitCommit.txt index 5877de7..769bece 100644 --- a/GitCommit.txt +++ b/GitCommit.txt @@ -1 +1 @@ -1907cdb \ No newline at end of file +e43417c \ No newline at end of file diff --git a/docs/cmleonos/docs/commands.md b/docs/cmleonos/docs/commands.md index 665a690..6a856b6 100644 --- a/docs/cmleonos/docs/commands.md +++ b/docs/cmleonos/docs/commands.md @@ -300,6 +300,26 @@ tree tree /system ``` +### tuitree +以树形结构显示目录内容(TUI界面)。 + +**用法:** +```bash +tuitree [path] +``` + +**示例:** +```bash +tuitree +tuitree /system +``` + +**说明:** +- 使用TUI TreeView组件显示文件和文件夹 +- 支持键盘导航(上下箭头、PageUp/PageDown) +- 按ESC键退出 +- 默认显示当前目录 + ### head 显示文件的前几行。 diff --git a/shell/CommandList.cs b/shell/CommandList.cs index fc4f57b..9c343e1 100644 --- a/shell/CommandList.cs +++ b/shell/CommandList.cs @@ -143,6 +143,9 @@ namespace CMLeonOS.shell case "tree": shell.ShowTree(args); break; + case "tuitree": + shell.ShowTUITree(args); + break; case "getdisk": shell.GetDiskInfo(); break; diff --git a/shell/Commands/FileSystem/TUITreeCommand.cs b/shell/Commands/FileSystem/TUITreeCommand.cs new file mode 100644 index 0000000..422fd2c --- /dev/null +++ b/shell/Commands/FileSystem/TUITreeCommand.cs @@ -0,0 +1,120 @@ +// The CMLeonOS Project (https://github.com/Leonmmcoset/CMLeonOS) +// Copyright (C) 2025-present LeonOS 2 Developer Team +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System; +using System.Collections.Generic; + +namespace CMLeonOS.Commands.FileSystem +{ + public static class TUITreeCommand + { + public static void ShowTUITree(CMLeonOS.FileSystem fileSystem, string args, Action showError) + { + string startPath = string.IsNullOrEmpty(args) ? "." : args; + string fullPath = fileSystem.GetFullPath(startPath); + + if (!global::System.IO.Directory.Exists(fullPath)) + { + showError($"Directory not found: {startPath}"); + return; + } + + try + { + var rootNode = BuildTree(fileSystem, fullPath, ""); + if (rootNode == null) + { + showError("No files or directories found."); + return; + } + + Console.Clear(); + Console.WriteLine($"Tree View: {fullPath}"); + Console.WriteLine("Press ESC to exit"); + Console.WriteLine(); + + var treeView = new CMLeonOS.UI.TreeView(new CMLeonOS.UI.Rect(5, 4, Console.WindowWidth - 10, Console.WindowHeight - 8)); + treeView.Root = rootNode; + treeView.BackgroundColor = ConsoleColor.Black; + treeView.NormalColor = ConsoleColor.White; + treeView.SelectedColor = ConsoleColor.Yellow; + treeView.BorderColor = ConsoleColor.Gray; + + if (rootNode.Children.Count > 0) + { + treeView.SelectedNodes.Add(rootNode.Children[0]); + } + + treeView.Render(); + + bool running = true; + while (running) + { + var key = Console.ReadKey(true); + if (key.Key == ConsoleKey.Escape) + { + running = false; + } + else if (treeView.HandleKey(key)) + { + treeView.Render(); + } + } + + Console.Clear(); + } + catch (Exception ex) + { + showError($"Error displaying tree: {ex.Message}"); + } + } + + private static CMLeonOS.UI.TreeViewNode BuildTree(CMLeonOS.FileSystem fileSystem, string path, string prefix) + { + var node = new CMLeonOS.UI.TreeViewNode(prefix + global::System.IO.Path.GetFileName(path)); + + try + { + var dirs = fileSystem.GetFullPathDirectoryList(path); + foreach (var dir in dirs) + { + var childNode = BuildTree(fileSystem, dir, prefix + " "); + if (childNode != null) + { + node.Children.Add(childNode); + } + } + + var files = fileSystem.GetFullPathFileList(path); + foreach (var file in files) + { + var fileNode = new CMLeonOS.UI.TreeViewNode(prefix + " " + global::System.IO.Path.GetFileName(file)); + node.Children.Add(fileNode); + } + } + catch + { + } + + if (node.Children.Count == 0) + { + return null; + } + + return node; + } + } +} diff --git a/shell/Shell.cs b/shell/Shell.cs index 2c20b64..9d5ec7c 100644 --- a/shell/Shell.cs +++ b/shell/Shell.cs @@ -920,6 +920,11 @@ namespace CMLeonOS Commands.FileSystem.TreeCommand.ShowTree(fileSystem, args, ShowError); } + public void ShowTUITree(string args) + { + Commands.FileSystem.TUITreeCommand.ShowTUITree(fileSystem, args, ShowError); + } + public void GetDiskInfo() { Commands.FileSystem.DiskInfoCommand.GetDiskInfo(ShowError);