From 2020e5677bf5a13ccaf9cd8556589fd60970826f Mon Sep 17 00:00:00 2001 From: rsenk330_cp <9f6236c47fe81cda1934f95c43bb1e96542ca22eBdFxLga6> Date: Fri, 20 Jun 2008 03:40:34 +0000 Subject: [PATCH] Added some more key mappings ([, ], etc.) and changed a few that were giving invalid key errors. --- source/Cosmos/Cosmos.Hardware/KeyboardOld.cs | 31 +++- source/RsenkTest/Commander.cs | 58 ++++++++ source/RsenkTest/CommanderShell.cs | 97 ------------- .../Commands/ClearScreen/ClearScreen.cs | 38 ----- source/RsenkTest/Commands/CommandBase.cs | 23 --- source/RsenkTest/Commands/HelpCommand.cs | 51 ------- source/RsenkTest/Commands/ParameterBase.cs | 15 -- source/RsenkTest/Commands/Version/VerAll.cs | 35 ----- .../Commands/Version/VerCommander.cs | 35 ----- source/RsenkTest/Commands/Version/Version.cs | 49 ------- source/RsenkTest/Interpreter.cs | 132 ++++++------------ source/RsenkTest/Program.cs | 17 +-- source/RsenkTest/Prompter.cs | 8 +- source/RsenkTest/RsenkTest.csproj | 9 +- 14 files changed, 137 insertions(+), 461 deletions(-) create mode 100644 source/RsenkTest/Commander.cs delete mode 100644 source/RsenkTest/CommanderShell.cs delete mode 100644 source/RsenkTest/Commands/ClearScreen/ClearScreen.cs delete mode 100644 source/RsenkTest/Commands/CommandBase.cs delete mode 100644 source/RsenkTest/Commands/HelpCommand.cs delete mode 100644 source/RsenkTest/Commands/ParameterBase.cs delete mode 100644 source/RsenkTest/Commands/Version/VerAll.cs delete mode 100644 source/RsenkTest/Commands/Version/VerCommander.cs delete mode 100644 source/RsenkTest/Commands/Version/Version.cs diff --git a/source/Cosmos/Cosmos.Hardware/KeyboardOld.cs b/source/Cosmos/Cosmos.Hardware/KeyboardOld.cs index 35a691a1f..052e253f3 100644 --- a/source/Cosmos/Cosmos.Hardware/KeyboardOld.cs +++ b/source/Cosmos/Cosmos.Hardware/KeyboardOld.cs @@ -27,6 +27,7 @@ namespace Cosmos.Hardware { mEscaped = false; } switch (xTheScancode) { + case 0x36: case 0x2A: { mShiftState = !aReleased; break; @@ -75,6 +76,9 @@ namespace Cosmos.Hardware { mKeys = new List(128); + //TODO: Direction Arrows, alt, ctrl, num pad, function keys, insert, home, pg up, delete, end, page down, esc, fn (for laptops) + + //reference: http://www.win.tue.nl/~aeb/linux/kbd/scancodes-1.html#ss1.1 #region Letters AddKey(0x10, 'q'); AddKey(0x100000, 'Q'); @@ -133,8 +137,10 @@ namespace Cosmos.Hardware { #endregion #region digits - AddKey(0x1, '`'); - AddKey(0x10000, '~'); + //AddKey(0x1, '`'); + //AddKey(0x10000, '~'); + AddKey(0x29, '`'); + AddKey(0x290000, '~'); AddKey(0x2, '1'); AddKey(0x20000, '!'); AddKey(0x3, '2'); @@ -170,18 +176,31 @@ namespace Cosmos.Hardware { #region Punctuation and Signs AddKey(0x27, ';'); + AddKey(0x270000, ':'); AddKey(0x28, '\''); + AddKey(0x280000, '"'); AddKey(0x2B, '\\'); + AddKey(0x2B0000, '|'); AddKey(0x33, ','); + AddKey(0x330000, '<'); AddKey(0x34, '.'); + AddKey(0x340000, '>'); AddKey(0x35, '/'); - AddKey(0x340000, '>'); - AddKey(0x4A, '-'); - AddKey(0x4E, '+'); + AddKey(0x350000, '?'); + //AddKey(0x4A, '-'); + AddKey(0x0C, '-'); + AddKey(0x0C0000, '_'); + AddKey(0x0D, '='); + AddKey(0x0D0000, '+'); + //AddKey(0x4E, '+'); + AddKey(0x1A, '['); + AddKey(0x1A0000, '{'); + AddKey(0x1B, ']'); + AddKey(0x1B0000, '}'); #endregion } } - + public static void Initialize() { CheckInit(); } diff --git a/source/RsenkTest/Commander.cs b/source/RsenkTest/Commander.cs new file mode 100644 index 000000000..72ce23a4e --- /dev/null +++ b/source/RsenkTest/Commander.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace RsenkTest +{ + public class Commander + { + private static Commander commanderShell; + /// + /// Will be false when the user exits the shell + /// + private bool runShell; + + private Commander() + { + runShell = true; //Tells the shell to start running + } + + /// + /// Gets the current instance of the shell. If it does not exist, create it. + /// + /// The commander shell. + public static Commander GetInstance() + { + if(commanderShell == null) + commanderShell = new Commander(); + + return commanderShell; + } + + /// + /// Starts the shell and prompts the user. + /// + public void Start() + { + while (runShell) //Keep prompting until the user exits + { + Prompter.Prompt("root", "~"); + String command = Console.ReadLine(); + + this.Execute(command); + } + } + + private void Execute(string command) + { + //Use the interpreter to break apart the program to execute and the arguments to pass in + List comm = Interpreter.GetParsed(command); + + Prompter.PrintMessage("Interpreted command:"); + + for(int x = 0; x < comm.Count; x++) + Prompter.PrintMessage(comm[x]); + } + } +} diff --git a/source/RsenkTest/CommanderShell.cs b/source/RsenkTest/CommanderShell.cs deleted file mode 100644 index 3de4fa11f..000000000 --- a/source/RsenkTest/CommanderShell.cs +++ /dev/null @@ -1,97 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using RsenkTest.Commands; -using RsenkTest.Commands.ClearScreen; - -namespace RsenkTest -{ - class CommanderShell //: StageBase - { - private Interpreter interpreter; - private List commands = new List(); - private static CommanderShell commander; - - private CommanderShell() - { - commands.Add(new ClearScreen()); - commands.Add(new RsenkTest.Commands.Version.Version()); - commands.Add(new HelpCommand()); - - interpreter = new Interpreter(commands); - } - - public static CommanderShell GetInstance() - { - if (commander == null) - commander = new CommanderShell(); - - return commander; - } - - public void Initialize() - { - //Clear the screen - interpreter.ParseCommand("cls").Execute(); - - while (true) //Stay in the shell until exit - { - Prompter.Prompt("rsenk330", "~"); - string line = Console.ReadLine(); - - if (line.Equals("exit")) - break; - - if (!String.IsNullOrEmpty(line)) - { - CommandBase command = interpreter.ParseCommand(line); - - if (command != null) - { - ParameterBase[] parameters = interpreter.ParseParameters(command, line); - command.Execute(parameters); - } - else - { - Prompter.PrintCommandError(line, false); - } - } - } - } - - public string Name - { - get { return "Cosmos Commander Shell"; } - } - - public void PrintCommands() - { - string toPrint = ""; - for (int x = 0; x < commands.Count; x++) - { - toPrint = commands[x].Name; - - for (int i = commands[x].Name.Length; i < 11; i++) - { - toPrint += " "; - } - - toPrint += commands[x].Summary; - - Prompter.PrintMessage(toPrint); - } - - Prompter.PrintMessage("exit Exits Commander\n"); - Prompter.PrintMessage("Type 'help [command]' for more help.\n"); - } - - public List Commands - { - get - { - return commands; - } - } - } -} diff --git a/source/RsenkTest/Commands/ClearScreen/ClearScreen.cs b/source/RsenkTest/Commands/ClearScreen/ClearScreen.cs deleted file mode 100644 index 67b96a654..000000000 --- a/source/RsenkTest/Commands/ClearScreen/ClearScreen.cs +++ /dev/null @@ -1,38 +0,0 @@ -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() - { - Console.WriteLine(""); //TODO: Write this method - } - - 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 deleted file mode 100644 index 12d2d137d..000000000 --- a/source/RsenkTest/Commands/CommandBase.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace RsenkTest.Commands -{ - abstract class CommandBase - { - protected List parameters; - public List Parameters - { - get - { - return parameters; - } - } - 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/HelpCommand.cs b/source/RsenkTest/Commands/HelpCommand.cs deleted file mode 100644 index d23d6349d..000000000 --- a/source/RsenkTest/Commands/HelpCommand.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace RsenkTest.Commands -{ - class HelpCommand : CommandBase - { - public HelpCommand() - { - parameters = new List(); - - parameters.Add(new Commands.ClearScreen.ClearScreen()); - parameters.Add(new RsenkTest.Commands.Version.Version()); - } - - public override string Name - { - get { return "help"; } - } - - public override string Summary - { - get { return "Provides help for commands"; } - } - - public override void Execute(params ParameterBase[] args) - { - switch (args.Length) - { - case 0: //'help' parsed - Help(); - break; - case 1: //'help [command]' parsed - args[0].Help(); - break; - default: - Prompter.PrintCommandError(Name, true); - break; - } - } - - public override void Help() - { - Prompter.PrintMessage(""); - Prompter.PrintMessage("Command Summary"); - CommanderShell.GetInstance().PrintCommands(); - } - } -} diff --git a/source/RsenkTest/Commands/ParameterBase.cs b/source/RsenkTest/Commands/ParameterBase.cs deleted file mode 100644 index e4626452f..000000000 --- a/source/RsenkTest/Commands/ParameterBase.cs +++ /dev/null @@ -1,15 +0,0 @@ -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 deleted file mode 100644 index ed8cbdb9b..000000000 --- a/source/RsenkTest/Commands/Version/VerAll.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace RsenkTest.Commands.Version -{ - class VerAll : ParameterBase - { - public override string Name - { - get { return "all"; } - } - - public override string Summary - { - get { return "Gets the version number of Cosmos and Commander"; } - } - - public override void Help() - { - Prompter.PrintMessage(""); //TODO: Finish this method - } - - public override void Execute() - { - Prompter.PrintMessage("About Commander:"); - } - - 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 deleted file mode 100644 index e0597e55a..000000000 --- a/source/RsenkTest/Commands/Version/VerCommander.cs +++ /dev/null @@ -1,35 +0,0 @@ -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() - { - Prompter.PrintMessage(""); //TODO: Finish this method - } - - public override void Execute() - { - Prompter.PrintMessage("Commander 0.0.0.1 alpha\n"); - } - - 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 deleted file mode 100644 index 3b0c6a11f..000000000 --- a/source/RsenkTest/Commands/Version/Version.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace RsenkTest.Commands.Version -{ - class Version : CommandBase - { - public Version() - { - parameters = new List(); - - parameters.Add(new VerAll()); - parameters.Add(new VerCommander()); - } - - public override string Name - { - get { return "ver"; } - } - - public override string Summary - { - get { return "Gets the version number."; } - } - - public override void Help() - { - Prompter.PrintMessage("Usage: ver [arg]."); - Prompter.PrintMessage("Valid args: "); - - for (int x = 0; x < parameters.Count; x++) - { - Prompter.PrintMessage(" " + parameters[x].Name); - } - - Prompter.PrintMessage(""); - } - - 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 index db2594765..44276d2db 100644 --- a/source/RsenkTest/Interpreter.cs +++ b/source/RsenkTest/Interpreter.cs @@ -2,108 +2,64 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using RsenkTest.Commands; namespace RsenkTest { - class Interpreter + public class Interpreter { - private List _commands; - - public Interpreter(List commands) + public static List GetParsed(string line) { - _commands = commands; - } + List retList = new List(); + string lineOld = ""; - /// - /// Parses the command off. Reads everything up to the first space. - /// - /// - /// Returns the command if it exists, otherwise null. - public CommandBase ParseCommand(string line) - { - string command = line.Substring(0, line.IndexOf(' ')); - - CommandBase commandToRet = CheckCommand(command); - - return commandToRet; - } - - /// - /// Checks to see if the command is valid. - /// - /// - /// Returns the command in the form of CommandBase if found, otherwise returns null. - private CommandBase CheckCommand(string comm) - { - CommandBase commandToRet = _commands.Find(delegate(CommandBase command) + //Read command + String command = ReadCommand(line); + if (!String.IsNullOrEmpty(command)) { - return command.Name.Equals(comm); - }); - - return commandToRet; - } - - public ParameterBase[] ParseParameters(CommandBase command, string line) - { - ParameterBase[] parameters = new ParameterBase[0]; - line = line.Substring(command.Name.Length + 1).Trim(); - bool invalidArg = false; - - if ((command != null) && (String.IsNullOrEmpty(line))) - { - List paramsTemp = new List(); - - while (line.Length > 0) - { - string param = line.Substring(0, line.IndexOf(' ')); - Console.WriteLine(param); - line = line.Substring(line.IndexOf(' ')); - Console.WriteLine(line); - - if (param.Equals(line)) - { - break; - } - - ParameterBase temp = ValidParam(command, param); - - if (temp != null) - paramsTemp.Add(temp); - else - { - invalidArg = true; - break; - } - } - - if (line.Trim().Length > 0) - { - ParameterBase temp = ValidParam(command, line); - - if (temp != null) - paramsTemp.Add(temp); - else - invalidArg = true; - } - - if (!invalidArg) - { - parameters = paramsTemp.ToArray(); - } + retList.Add(command); + line = line.Substring(command.Length); //remove the command + line = line.Trim(); //remove any whitespace } - return parameters; + //Read all arguments + while (line.Trim().Length > 0) + { + String arg = ReadArgument(line); + if (!String.IsNullOrEmpty(arg)) + { + retList.Add(arg); + line = line.Substring(arg.Length); + line = line.Trim(); + } + else + break; + } + + return retList; } - private ParameterBase ValidParam(CommandBase command, string paramToCheck) + private static string ReadCommand(string line) { - ParameterBase param = command.Parameters.Find(delegate(CommandBase parameter) + //String.Contains() doesn't work yet, so check manually... + for (int x = 0; x < line.Length; x++) { - return parameter.Name.Equals(paramToCheck); - }) as ParameterBase; + if (line[x].Equals(' ')) + return line.Substring(0, x); + } - return param; + return line; + } + + private static string ReadArgument(string line) + { + //String.Contains() doesn't work yet, so check manually... + for (int x = 0; x < line.Length; x++) + { + if (line[x].Equals(' ')) + return line.Substring(0, x); + } + + return line; } } } diff --git a/source/RsenkTest/Program.cs b/source/RsenkTest/Program.cs index 76f36b36e..f40056760 100644 --- a/source/RsenkTest/Program.cs +++ b/source/RsenkTest/Program.cs @@ -1,7 +1,8 @@ using System; using Cosmos.Build.Windows; +using RsenkTest; -namespace RsenkTest +namespace CosmosBoot { class Program { @@ -17,18 +18,10 @@ namespace RsenkTest // Main entry point of the kernel public static void Init() { - try - { - Cosmos.Sys.Boot.Default(); - System.Console.WriteLine(" [ done ]"); + Cosmos.Sys.Boot.Default(); - System.Console.WriteLine("Queueing Shell"); - System.Console.WriteLine(" [ done ]"); - } - catch (PrompterException e) - { - Prompter.PrintError(e.Message); - } + Commander shell = Commander.GetInstance(); + shell.Start(); while (true) ; diff --git a/source/RsenkTest/Prompter.cs b/source/RsenkTest/Prompter.cs index 6b2cd2e88..ccadadce6 100644 --- a/source/RsenkTest/Prompter.cs +++ b/source/RsenkTest/Prompter.cs @@ -10,8 +10,8 @@ namespace RsenkTest 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 = '$'; + private const string SYM_ROOT = "#"; + private const string SYM_NORM = "$"; /// /// The different message types possible @@ -31,7 +31,7 @@ namespace RsenkTest public static void Prompt(string user, string path) { Console.ForegroundColor = NORMAL_COLOR; - Console.Write("[" + user + ":" + path + "]" + SYM_NORM + " "); + Console.Write(user + ":" + path + SYM_NORM + " "); } /// @@ -103,4 +103,4 @@ namespace RsenkTest } } } -} +} \ No newline at end of file diff --git a/source/RsenkTest/RsenkTest.csproj b/source/RsenkTest/RsenkTest.csproj index 771c03be0..08fadd226 100644 --- a/source/RsenkTest/RsenkTest.csproj +++ b/source/RsenkTest/RsenkTest.csproj @@ -55,14 +55,7 @@ - - - - - - - - +