From 4104c87c99e7900bcbdbbeac9be79bc28d0438ec Mon Sep 17 00:00:00 2001 From: rsenk330_cp <9f6236c47fe81cda1934f95c43bb1e96542ca22eBdFxLga6> Date: Sat, 12 Apr 2008 21:24:17 +0000 Subject: [PATCH] Started work on a custom shell for me to test things with. --- source/RsenkTest/CommanderShell.cs | 50 ++++++++++ .../Commands/ClearScreen/ClearScreen.cs | 38 ++++++++ source/RsenkTest/Commands/CommandBase.cs | 15 +++ source/RsenkTest/Commands/ParameterBase.cs | 15 +++ source/RsenkTest/Commands/Version/VerAll.cs | 35 +++++++ .../Commands/Version/VerCommander.cs | 40 ++++++++ source/RsenkTest/Commands/Version/Version.cs | 33 +++++++ source/RsenkTest/Interpreter.cs | 43 +++++++++ source/RsenkTest/Program.cs | 43 +++++++++ source/RsenkTest/Prompter.cs | 93 +++++++++++++++++++ source/RsenkTest/PrompterException.cs | 14 +++ source/RsenkTest/Properties/AssemblyInfo.cs | 36 +++++++ source/RsenkTest/RsenkTest.csproj | 79 ++++++++++++++++ source/RsenkTest/RsenkTest.csproj.vspscc | 10 ++ 14 files changed, 544 insertions(+) create mode 100644 source/RsenkTest/CommanderShell.cs create mode 100644 source/RsenkTest/Commands/ClearScreen/ClearScreen.cs create mode 100644 source/RsenkTest/Commands/CommandBase.cs create mode 100644 source/RsenkTest/Commands/ParameterBase.cs create mode 100644 source/RsenkTest/Commands/Version/VerAll.cs create mode 100644 source/RsenkTest/Commands/Version/VerCommander.cs create mode 100644 source/RsenkTest/Commands/Version/Version.cs create mode 100644 source/RsenkTest/Interpreter.cs create mode 100644 source/RsenkTest/Program.cs create mode 100644 source/RsenkTest/Prompter.cs create mode 100644 source/RsenkTest/PrompterException.cs create mode 100644 source/RsenkTest/Properties/AssemblyInfo.cs create mode 100644 source/RsenkTest/RsenkTest.csproj create mode 100644 source/RsenkTest/RsenkTest.csproj.vspscc diff --git a/source/RsenkTest/CommanderShell.cs b/source/RsenkTest/CommanderShell.cs new file mode 100644 index 000000000..a8903d1a8 --- /dev/null +++ b/source/RsenkTest/CommanderShell.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Cosmos.Kernel.Staging; +using RsenkTest.Commands; +using RsenkTest.Commands.ClearScreen; + +namespace RsenkTest +{ + class CommanderShell : StageBase + { + Interpreter interpreter; + List commands = new List(); + + public CommanderShell() + { + commands.Add(new ClearScreen()); + + interpreter = new Interpreter(commands); + } + + public override void Initialize() + { + while (true) //Stay in the shell until exit + { + Prompter.Prompt("rsenk330", "~"); + string line = Console.ReadLine(); + + CommandBase command = interpreter.ParseCommand(line); + + if (command != null) + { + command.Execute(); + } + else + { + Prompter.PrintError("'" + line + "' is not a valid command. Type 'help' for a list of valid commands"); + } + } + } + + public override string Name + { + get { return "Cosmos Commander Shell"; } + } + + public override void Teardown() { } + } +} diff --git a/source/RsenkTest/Commands/ClearScreen/ClearScreen.cs b/source/RsenkTest/Commands/ClearScreen/ClearScreen.cs new file mode 100644 index 000000000..dcafa0340 --- /dev/null +++ b/source/RsenkTest/Commands/ClearScreen/ClearScreen.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace RsenkTest.Commands.ClearScreen +{ + class ClearScreen : CommandBase + { + public override string Name + { + get { return "cls"; } + } + + public override string Summary + { + get { return "Clears the screen and displays the welcome message."; } + } + + public override void Help() + { + throw new NotImplementedException(); + } + + public override void Execute(params ParameterBase[] args) + { + if (args.Length > 0) + { + Prompter.PrintError("The command '" + Name + "' does not take any parameters."); + } + else + { + Console.Clear(); + Prompter.PrintWelcome(""); + } + } + } +} diff --git a/source/RsenkTest/Commands/CommandBase.cs b/source/RsenkTest/Commands/CommandBase.cs new file mode 100644 index 000000000..eecfef4d5 --- /dev/null +++ b/source/RsenkTest/Commands/CommandBase.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace RsenkTest.Commands +{ + abstract class CommandBase + { + public abstract string Name { get; } + public abstract string Summary { get; } + public abstract void Help(); + public abstract void Execute(params ParameterBase[] args); + } +} diff --git a/source/RsenkTest/Commands/ParameterBase.cs b/source/RsenkTest/Commands/ParameterBase.cs new file mode 100644 index 000000000..e4626452f --- /dev/null +++ b/source/RsenkTest/Commands/ParameterBase.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace RsenkTest.Commands +{ + abstract class ParameterBase : CommandBase + { + public abstract override string Name { get; } + public abstract override string Summary { get; } + public abstract override void Help(); + public abstract void Execute(); + } +} diff --git a/source/RsenkTest/Commands/Version/VerAll.cs b/source/RsenkTest/Commands/Version/VerAll.cs new file mode 100644 index 000000000..26dd11df8 --- /dev/null +++ b/source/RsenkTest/Commands/Version/VerAll.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace RsenkTest.Commands.Version +{ + class VerAll : ParameterBase + { + public override string Name + { + get { throw new NotImplementedException(); } + } + + public override string Summary + { + get { throw new NotImplementedException(); } + } + + public override void Help() + { + throw new NotImplementedException(); + } + + public override void Execute() + { + throw new NotImplementedException(); + } + + public override void Execute(params ParameterBase[] args) + { + throw new NotImplementedException(); + } + } +} diff --git a/source/RsenkTest/Commands/Version/VerCommander.cs b/source/RsenkTest/Commands/Version/VerCommander.cs new file mode 100644 index 000000000..f716a6f8f --- /dev/null +++ b/source/RsenkTest/Commands/Version/VerCommander.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace RsenkTest.Commands.Version +{ + class VerCommander : ParameterBase + { + public override string Name + { + get { return "commander"; } + } + + public override string Summary + { + get { return "Gets the current version number of the Cosmos Commander Shell."; } + } + + public override void Help() + { + throw new NotImplementedException(); + } + + public override void Execute() + { + Prompter.PrintMessage("Commander 0.0.0.1 alpha\n"); + } + + /// + /// + /// + /// + [Obsolete("This method was inherited from CommandBase and should not be used. User Execute() instead.")] + public override void Execute(params ParameterBase[] args) + { + throw new NotImplementedException(); + } + } +} diff --git a/source/RsenkTest/Commands/Version/Version.cs b/source/RsenkTest/Commands/Version/Version.cs new file mode 100644 index 000000000..21de5d232 --- /dev/null +++ b/source/RsenkTest/Commands/Version/Version.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace RsenkTest.Commands.Version +{ + class Version : CommandBase + { + public override string Name + { + get { return "ver"; } + } + + public override string Summary + { + get { return "Gets the version number."; } + } + + public override void Help() + { + throw new NotImplementedException(); + } + + public override void Execute(params ParameterBase[] args) + { + foreach (ParameterBase param in args) + { + param.Execute(); + } + } + } +} diff --git a/source/RsenkTest/Interpreter.cs b/source/RsenkTest/Interpreter.cs new file mode 100644 index 000000000..0761145ee --- /dev/null +++ b/source/RsenkTest/Interpreter.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using RsenkTest.Commands; + +namespace RsenkTest +{ + class Interpreter + { + private List _commands; + + public Interpreter(List commands) + { + _commands = commands; + } + + public CommandBase ParseCommand(string line) + { + string command = line.Substring(0, line.IndexOf(' ')); + + CommandBase commandToRet = CheckCommand(command); + + return commandToRet; + } + + private CommandBase CheckCommand(string comm) + { + CommandBase commandToRet = new RsenkTest.Commands.ClearScreen.ClearScreen(); + + //foreach (CommandBase command in _commands) + //{ + // if (command.Name == comm) + // { + // commandToRet = command; + // break; + // } + //} + + return commandToRet; + } + } +} diff --git a/source/RsenkTest/Program.cs b/source/RsenkTest/Program.cs new file mode 100644 index 000000000..077c76040 --- /dev/null +++ b/source/RsenkTest/Program.cs @@ -0,0 +1,43 @@ +using System; +using Cosmos.Build.Windows; + +namespace RsenkTest +{ + class Program + { + #region Cosmos Builder logic + // Most users wont touch this. This will call the Cosmos Build tool + [STAThread] + static void Main(string[] args) + { + BuildUI.Run(); + } + #endregion + + // Main entry point of the kernel + public static void Init() + { + try + { + Cosmos.Kernel.Boot.Default(); + System.Console.Write("Creating StageQueue"); + Cosmos.Kernel.Staging.DefaultStageQueue stages = new Cosmos.Kernel.Staging.DefaultStageQueue(); + System.Console.WriteLine(" [ done ]"); + + System.Console.WriteLine("Queueing Shell"); + stages.Enqueue(new CommanderShell()); + System.Console.WriteLine(" [ done ]"); + + stages.Run(); + stages.Teardown(); + } + catch (PrompterException e) + { + Prompter.PrintError(e.Message); + } + + while (true) + ; + } + } +} \ No newline at end of file diff --git a/source/RsenkTest/Prompter.cs b/source/RsenkTest/Prompter.cs new file mode 100644 index 000000000..99f8e7615 --- /dev/null +++ b/source/RsenkTest/Prompter.cs @@ -0,0 +1,93 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace RsenkTest +{ + class Prompter + { + private const ConsoleColor NORMAL_COLOR = ConsoleColor.White; + private const ConsoleColor WARNING_COLOR = ConsoleColor.Yellow; + private const ConsoleColor ERROR_COLOR = ConsoleColor.Red; + private const char SYM_ROOT = '#'; + private const char SYM_NORM = '$'; + + /// + /// The different message types possible + /// + private enum MessageType + { + Normal, + Warning, + Error + } + + /// + /// Displays the prompt string + /// + /// The current user. + /// The current path. + public static void Prompt(string user, string path) + { + Console.Write("[" + user + ":" + path + "]" + SYM_NORM + " "); + } + + /// + /// Prints the welcome message to the console. + /// + /// Additional messages to be displayed. + public static void PrintWelcome(string additional) + { + Console.ForegroundColor = ConsoleColor.DarkMagenta; + Console.WriteLine("Welcome to Cosmos Commander!\n\n"); + Console.ForegroundColor = ConsoleColor.White; + } + + /// + /// Prints an error message to the console. + /// + public static void PrintError(string error) + { + PrintMessage(error, MessageType.Error); + } + + /// + /// Prints a warning message to the console. + /// + public static void PrintWarning(string warning) + { + PrintMessage(warning, MessageType.Warning); + } + + /// + /// Prints a message to the console. + /// + public static void PrintMessage(string message) + { + PrintMessage(message, MessageType.Normal); + } + + /// + /// Prints a message to the console and sets the foreground color depending on the message type. + /// + private static void PrintMessage(string message, MessageType type) + { + switch (type) + { + case MessageType.Error: + Console.ForegroundColor = ERROR_COLOR; + break; + case MessageType.Warning: + Console.ForegroundColor = WARNING_COLOR; + break; + case MessageType.Normal: + default: + Console.ForegroundColor = NORMAL_COLOR; + break; + } + + Console.WriteLine(message); + } + } +} diff --git a/source/RsenkTest/PrompterException.cs b/source/RsenkTest/PrompterException.cs new file mode 100644 index 000000000..a50640798 --- /dev/null +++ b/source/RsenkTest/PrompterException.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace RsenkTest +{ + class PrompterException : Exception + { + public PrompterException() : base() { } + public PrompterException(string message) : base(message) { } + public PrompterException(string message, Exception innerExc) : base(message, innerExc) { } + } +} diff --git a/source/RsenkTest/Properties/AssemblyInfo.cs b/source/RsenkTest/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..b550e5ffb --- /dev/null +++ b/source/RsenkTest/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("RsenkTest")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("RsenkTest")] +[assembly: AssemblyCopyright("Copyright © 2008")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("c18ed28a-23cc-4374-832d-87aeaa37c267")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/source/RsenkTest/RsenkTest.csproj b/source/RsenkTest/RsenkTest.csproj new file mode 100644 index 000000000..210ebb8bd --- /dev/null +++ b/source/RsenkTest/RsenkTest.csproj @@ -0,0 +1,79 @@ + + + + Debug + AnyCPU + 9.0.21022 + 2.0 + {F598F906-8F3B-4EC1-AB8F-A9CBD8EBBE21} + Exe + Properties + RsenkTest + RsenkTest + v3.5 + 512 + SAK + SAK + SAK + SAK + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + x86 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + False + ..\Cosmos.Build.Windows\bin\Debug\Cosmos.Build.Windows.dll + + + False + ..\Cosmos\Cosmos.Kernel\bin\Debug\Cosmos.Kernel.dll + + + + 3.5 + + + + + 3.5 + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/source/RsenkTest/RsenkTest.csproj.vspscc b/source/RsenkTest/RsenkTest.csproj.vspscc new file mode 100644 index 000000000..feffdecaa --- /dev/null +++ b/source/RsenkTest/RsenkTest.csproj.vspscc @@ -0,0 +1,10 @@ +"" +{ +"FILE_VERSION" = "9237" +"ENLISTMENT_CHOICE" = "NEVER" +"PROJECT_FILE_RELATIVE_PATH" = "" +"NUMBER_OF_EXCLUDED_FILES" = "0" +"ORIGINAL_PROJECT_FILE_PATH" = "" +"NUMBER_OF_NESTED_PROJECTS" = "0" +"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER" +}