diff --git a/shell/Commands/Help/Help.cs b/shell/Commands/Help/Help.cs index e28eb3a..1fe43f6 100644 --- a/shell/Commands/Help/Help.cs +++ b/shell/Commands/Help/Help.cs @@ -1,87 +1,381 @@ using System; +using System.Collections.Generic; namespace CMLeonOS.Commands { public static class HelpCommand { - private static readonly string[] allCommands = { - " echo - Display text (supports \\n for newline)", - " clear/cls - Clear the screen", - " restart - Restart the system", - " shutdown - Shutdown the system", - " time - Display current time", - " date - Display current date", - " prompt - Change command prompt", - " calc - Simple calculator", - " history - Show command history", - " background - Change background color", - " cuitest - Test CUI framework", - " labyrinth - Play maze escape game", - " edit - Simple code editor", - " Tab key inserts 4 spaces", - " ls - List files and directories", - " cd - Change directory", - " cd .. - Go to parent directory", - " cd dir1/dir2/dir3 - Go to numbered directory", - " pwd - Show current directory", - " mkdir - Create directory", - " rm - Remove file", - " Use -norisk to delete files in sys folder", - " rmdir - Remove directory", - " cat - Display file content", - " echo > - Write text to file", - " head - Display first lines of file", - " Usage: head ", - " tail - Display last lines of file", - " Usage: tail ", - " wc - Count lines, words, characters", - " cp - Copy file", - " mv - Move/rename file", - " touch - Create empty file", - " find - Find file", - " getdisk - Show disk information", - " user - User management", - " user add admin - Add admin user", - " user add user - Add regular user", - " user delete - Delete user", - " user list - List all users", - " cpass - Change password", - " env - Environment variables", - " env see - Show variable value", - " env change - Set variable value", - " env delete - Delete variable", - " beep - Play beep sound", - " uptime - Show system uptime", - " branswe - Execute Branswe code file", - " backup - Backup system files", - " restore - Restore system files", - " grep - Search text in file", - " ping - Ping IP address (5 times)", - " tcpserver - Start TCP server on specified port", - " tcpclient - Connect to TCP server", - " wget - Download file from URL", - " setdns - Set DNS server", - " setgateway - Set gateway", - " ipconfig - Show network configuration", - " nslookup - DNS lookup", - " whoami - Show current username", - " base64 encrypt - Encode text to Base64", - " base64 decrypt - Decode Base64 to text", - " alias - Create command alias", - " alias - List all aliases", - " unalias - Remove command alias", - " lua - Execute Lua script", - " version - Show OS version", - " about - Show about information", - " settings [value] - View or modify system settings", - " settings - List all settings", - " help - Show help page (1-3)", - " help all - Show all help pages", - "", - "Startup Script: sys\\startup.cm", - " Commands in this file will be executed on startup", - " Each line should contain one command", - " Lines starting with # are treated as comments" + private class CommandInfo + { + public string Command { get; set; } + public string Parameters { get; set; } + public string Description { get; set; } + public string[] SubCommands { get; set; } + } + + private static readonly List allCommands = new List + { + new CommandInfo + { + Command = "echo", + Parameters = "", + Description = "Display text (supports \\n for newline)" + }, + new CommandInfo + { + Command = "clear/cls", + Parameters = "", + Description = "Clear screen" + }, + new CommandInfo + { + Command = "restart", + Parameters = "", + Description = "Restart system" + }, + new CommandInfo + { + Command = "shutdown", + Parameters = "", + Description = "Shutdown system" + }, + new CommandInfo + { + Command = "time", + Parameters = "", + Description = "Display current time" + }, + new CommandInfo + { + Command = "date", + Parameters = "", + Description = "Display current date" + }, + new CommandInfo + { + Command = "prompt", + Parameters = "", + Description = "Change command prompt" + }, + new CommandInfo + { + Command = "calc", + Parameters = "", + Description = "Simple calculator" + }, + new CommandInfo + { + Command = "history", + Parameters = "", + Description = "Show command history" + }, + new CommandInfo + { + Command = "background", + Parameters = "", + Description = "Change background color" + }, + new CommandInfo + { + Command = "cuitest", + Parameters = "", + Description = "Test CUI framework" + }, + new CommandInfo + { + Command = "labyrinth", + Parameters = "", + Description = "Play maze escape game" + }, + new CommandInfo + { + Command = "edit", + Parameters = "", + Description = "Simple code editor", + SubCommands = new[] { "Tab key inserts 4 spaces" } + }, + new CommandInfo + { + Command = "ls", + Parameters = "", + Description = "List files and directories" + }, + new CommandInfo + { + Command = "cd", + Parameters = "", + Description = "Change directory", + SubCommands = new[] + { + "cd .. - Go to parent directory", + "cd dir1/dir2/dir3 - Go to numbered directory" + } + }, + new CommandInfo + { + Command = "pwd", + Parameters = "", + Description = "Show current directory" + }, + new CommandInfo + { + Command = "mkdir", + Parameters = "", + Description = "Create directory" + }, + new CommandInfo + { + Command = "rm", + Parameters = "", + Description = "Remove file", + SubCommands = new[] { "Use -norisk to delete files in sys folder" } + }, + new CommandInfo + { + Command = "rmdir", + Parameters = "", + Description = "Remove directory" + }, + new CommandInfo + { + Command = "cat", + Parameters = "", + Description = "Display file content" + }, + new CommandInfo + { + Command = "echo", + Parameters = " > ", + Description = "Write text to file" + }, + new CommandInfo + { + Command = "head", + Parameters = "", + Description = "Display first lines of file", + SubCommands = new[] { "Usage: head " } + }, + new CommandInfo + { + Command = "tail", + Parameters = "", + Description = "Display last lines of file", + SubCommands = new[] { "Usage: tail " } + }, + new CommandInfo + { + Command = "wc", + Parameters = "", + Description = "Count lines, words, characters" + }, + new CommandInfo + { + Command = "cp", + Parameters = " ", + Description = "Copy file" + }, + new CommandInfo + { + Command = "mv", + Parameters = " ", + Description = "Move/rename file" + }, + new CommandInfo + { + Command = "touch", + Parameters = "", + Description = "Create empty file" + }, + new CommandInfo + { + Command = "find", + Parameters = "", + Description = "Find file" + }, + new CommandInfo + { + Command = "getdisk", + Parameters = "", + Description = "Show disk information" + }, + new CommandInfo + { + Command = "user", + Parameters = "", + Description = "User management", + SubCommands = new[] + { + "user add admin - Add admin user", + "user add user - Add regular user", + "user delete - Delete user", + "user list - List all users" + } + }, + new CommandInfo + { + Command = "cpass", + Parameters = "", + Description = "Change password" + }, + new CommandInfo + { + Command = "env", + Parameters = "", + Description = "Environment variables", + SubCommands = new[] + { + "env see - Show variable value", + "env change - Set variable value", + "env delete - Delete variable" + } + }, + new CommandInfo + { + Command = "beep", + Parameters = "", + Description = "Play beep sound" + }, + new CommandInfo + { + Command = "uptime", + Parameters = "", + Description = "Show system uptime" + }, + new CommandInfo + { + Command = "branswe", + Parameters = "", + Description = "Execute Branswe code file" + }, + new CommandInfo + { + Command = "backup", + Parameters = "", + Description = "Backup system files" + }, + new CommandInfo + { + Command = "restore", + Parameters = "", + Description = "Restore system files" + }, + new CommandInfo + { + Command = "grep", + Parameters = " ", + Description = "Search text in file" + }, + new CommandInfo + { + Command = "ping", + Parameters = "", + Description = "Ping IP address (5 times)" + }, + new CommandInfo + { + Command = "tcpserver", + Parameters = "", + Description = "Start TCP server on specified port" + }, + new CommandInfo + { + Command = "tcpclient", + Parameters = " ", + Description = "Connect to TCP server" + }, + new CommandInfo + { + Command = "wget", + Parameters = "", + Description = "Download file from URL" + }, + new CommandInfo + { + Command = "setdns", + Parameters = "", + Description = "Set DNS server" + }, + new CommandInfo + { + Command = "setgateway", + Parameters = "", + Description = "Set gateway" + }, + new CommandInfo + { + Command = "ipconfig", + Parameters = "", + Description = "Show network configuration" + }, + new CommandInfo + { + Command = "nslookup", + Parameters = "", + Description = "DNS lookup" + }, + new CommandInfo + { + Command = "whoami", + Parameters = "", + Description = "Show current username" + }, + new CommandInfo + { + Command = "base64", + Parameters = "encrypt ", + Description = "Encode text to Base64" + }, + new CommandInfo + { + Command = "base64", + Parameters = "decrypt ", + Description = "Decode Base64 to text" + }, + new CommandInfo + { + Command = "alias", + Parameters = " ", + Description = "Create command alias", + SubCommands = new[] { "alias - List all aliases" } + }, + new CommandInfo + { + Command = "unalias", + Parameters = "", + Description = "Remove command alias" + }, + new CommandInfo + { + Command = "lua", + Parameters = "", + Description = "Execute Lua script" + }, + new CommandInfo + { + Command = "version", + Parameters = "", + Description = "Show OS version" + }, + new CommandInfo + { + Command = "about", + Parameters = "", + Description = "Show about information" + }, + new CommandInfo + { + Command = "settings", + Parameters = " [value]", + Description = "View or modify system settings", + SubCommands = new[] { "settings - List all settings" } + }, + new CommandInfo + { + Command = "help", + Parameters = "", + Description = "Show help page (1-3)", + SubCommands = new[] { "help all - Show all help pages" } + } }; private const int CommandsPerPage = 15; @@ -104,7 +398,7 @@ namespace CMLeonOS.Commands } } - int totalPages = (int)Math.Ceiling((double)allCommands.Length / CommandsPerPage); + int totalPages = (int)Math.Ceiling((double)allCommands.Count / CommandsPerPage); if (showAll) { @@ -125,7 +419,7 @@ namespace CMLeonOS.Commands foreach (var cmd in allCommands) { - Console.WriteLine(cmd); + DisplayCommand(cmd); } Console.WriteLine(); @@ -144,7 +438,7 @@ namespace CMLeonOS.Commands } int startIndex = (pageNumber - 1) * CommandsPerPage; - int endIndex = Math.Min(startIndex + CommandsPerPage, allCommands.Length); + int endIndex = Math.Min(startIndex + CommandsPerPage, allCommands.Count); Console.WriteLine("===================================="); Console.WriteLine($" Help - Page {pageNumber}/{totalPages}"); @@ -153,7 +447,7 @@ namespace CMLeonOS.Commands for (int i = startIndex; i < endIndex; i++) { - Console.WriteLine(allCommands[i]); + DisplayCommand(allCommands[i]); } if (pageNumber < totalPages) @@ -167,5 +461,39 @@ namespace CMLeonOS.Commands Console.WriteLine("-- End of help --"); } } + + private static void DisplayCommand(CommandInfo cmd) + { + int maxCommandWidth = 18; + int maxParamWidth = 18; + + string commandPart = PadRight(cmd.Command, maxCommandWidth); + string paramPart = PadRight(cmd.Parameters, maxParamWidth); + + Console.WriteLine($" {commandPart} {paramPart} - {cmd.Description}"); + + if (cmd.SubCommands != null) + { + foreach (var subCmd in cmd.SubCommands) + { + Console.WriteLine($" {subCmd}"); + } + } + } + + private static string PadRight(string str, int totalWidth) + { + if (string.IsNullOrEmpty(str)) + { + return new string(' ', totalWidth); + } + + if (str.Length >= totalWidth) + { + return str; + } + + return str + new string(' ', totalWidth - str.Length); + } } }