diff --git a/shell/Commands/Help/Help.cs b/shell/Commands/Help/Help.cs new file mode 100644 index 0000000..00313fa --- /dev/null +++ b/shell/Commands/Help/Help.cs @@ -0,0 +1,165 @@ +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", + " 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 --"); + } + } + } +} diff --git a/shell/Commands/Info/About.cs b/shell/Commands/Info/About.cs new file mode 100644 index 0000000..415404a --- /dev/null +++ b/shell/Commands/Info/About.cs @@ -0,0 +1,13 @@ +using System; + +namespace CMLeonOS.Commands +{ + public static class AboutCommand + { + public static void ProcessAbout() + { + Console.WriteLine("CMLeonOS Project"); + Console.WriteLine("By LeonOS 2 Developement Team"); + } + } +} diff --git a/shell/Commands/Info/Version.cs b/shell/Commands/Info/Version.cs new file mode 100644 index 0000000..bc82149 --- /dev/null +++ b/shell/Commands/Info/Version.cs @@ -0,0 +1,16 @@ +using System; + +namespace CMLeonOS.Commands +{ + public static class VersionCommand + { + public static void ProcessVersion() + { + Console.WriteLine(Version.DisplayVersion); + Console.WriteLine($"Major: {Version.Major}"); + Console.WriteLine($"Minor: {Version.Minor}"); + Console.WriteLine($"Patch: {Version.Patch}"); + Console.WriteLine($"Full Version: {Version.FullVersion}"); + } + } +} diff --git a/shell/Shell.cs b/shell/Shell.cs index 8c034ec..c8ef8c7 100644 --- a/shell/Shell.cs +++ b/shell/Shell.cs @@ -138,149 +138,7 @@ namespace CMLeonOS public 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; - } - } - - 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", - " 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" - }; - - int commandsPerPage = 15; - int totalPages = (int)Math.Ceiling((double)allCommands.Length / commandsPerPage); - - if (showAll) - { - 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 --"); - } - else - { - 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 --"); - } - } + Commands.HelpCommand.ProcessHelp(args); } public void ProcessTime() @@ -395,17 +253,12 @@ namespace CMLeonOS public void ProcessVersion() { - Console.WriteLine(Version.DisplayVersion); - Console.WriteLine($"Major: {Version.Major}"); - Console.WriteLine($"Minor: {Version.Minor}"); - Console.WriteLine($"Patch: {Version.Patch}"); - Console.WriteLine($"Full Version: {Version.FullVersion}"); + Commands.VersionCommand.ProcessVersion(); } public void ProcessAbout() { - Console.WriteLine("CMLeonOS Project"); - Console.WriteLine("By LeonOS 2 Developement Team"); + Commands.AboutCommand.ProcessAbout(); } public void ProcessCpass()