using System; 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", " 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", " 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 const int CommandsPerPage = 15; public static void ProcessHelp(string args) { string[] helpArgs = args.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); int pageNumber = 1; bool showAll = false; if (helpArgs.Length > 0) { if (helpArgs[0].ToLower() == "all") { showAll = true; } else if (int.TryParse(helpArgs[0], out int page)) { pageNumber = page; } } int totalPages = (int)Math.Ceiling((double)allCommands.Length / CommandsPerPage); if (showAll) { ShowAllPages(); } else { ShowPage(pageNumber, totalPages); } } private static void ShowAllPages() { Console.WriteLine("===================================="); Console.WriteLine(" Help - All Pages"); Console.WriteLine("===================================="); Console.WriteLine(); foreach (var cmd in allCommands) { Console.WriteLine(cmd); } Console.WriteLine(); Console.WriteLine("-- End of help --"); } private static void ShowPage(int pageNumber, int totalPages) { if (pageNumber > totalPages) { pageNumber = totalPages; } if (pageNumber < 1) { pageNumber = 1; } int startIndex = (pageNumber - 1) * CommandsPerPage; int endIndex = Math.Min(startIndex + CommandsPerPage, allCommands.Length); Console.WriteLine("===================================="); Console.WriteLine($" Help - Page {pageNumber}/{totalPages}"); Console.WriteLine("===================================="); Console.WriteLine(); for (int i = startIndex; i < endIndex; i++) { Console.WriteLine(allCommands[i]); } if (pageNumber < totalPages) { Console.WriteLine(); Console.WriteLine($"-- More -- Type 'help {pageNumber + 1}' for next page or 'help all' for all pages --"); } else { Console.WriteLine(); Console.WriteLine("-- End of help --"); } } } }