mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-21 13:28:41 +00:00
Added some more key mappings ([, ], etc.) and changed a few that were giving invalid key errors.
This commit is contained in:
parent
6969203d55
commit
2020e5677b
14 changed files with 137 additions and 461 deletions
|
|
@ -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<KeyMapping>(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();
|
||||
}
|
||||
|
|
|
|||
58
source/RsenkTest/Commander.cs
Normal file
58
source/RsenkTest/Commander.cs
Normal file
|
|
@ -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;
|
||||
/// <summary>
|
||||
/// Will be false when the user exits the shell
|
||||
/// </summary>
|
||||
private bool runShell;
|
||||
|
||||
private Commander()
|
||||
{
|
||||
runShell = true; //Tells the shell to start running
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current instance of the shell. If it does not exist, create it.
|
||||
/// </summary>
|
||||
/// <returns>The commander shell.</returns>
|
||||
public static Commander GetInstance()
|
||||
{
|
||||
if(commanderShell == null)
|
||||
commanderShell = new Commander();
|
||||
|
||||
return commanderShell;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Starts the shell and prompts the user.
|
||||
/// </summary>
|
||||
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<String> comm = Interpreter.GetParsed(command);
|
||||
|
||||
Prompter.PrintMessage("Interpreted command:");
|
||||
|
||||
for(int x = 0; x < comm.Count; x++)
|
||||
Prompter.PrintMessage(comm[x]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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<CommandBase> commands = new List<CommandBase>();
|
||||
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<CommandBase> Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return commands;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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("");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace RsenkTest.Commands
|
||||
{
|
||||
abstract class CommandBase
|
||||
{
|
||||
protected List<CommandBase> parameters;
|
||||
public List<CommandBase> 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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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<CommandBase>();
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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<CommandBase>();
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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<CommandBase> _commands;
|
||||
|
||||
public Interpreter(List<CommandBase> commands)
|
||||
public static List<String> GetParsed(string line)
|
||||
{
|
||||
_commands = commands;
|
||||
}
|
||||
List<String> retList = new List<String>();
|
||||
string lineOld = "";
|
||||
|
||||
/// <summary>
|
||||
/// Parses the command off. Reads everything up to the first space.
|
||||
/// </summary>
|
||||
/// <param name="line"></param>
|
||||
/// <returns>Returns the command if it exists, otherwise null.</returns>
|
||||
public CommandBase ParseCommand(string line)
|
||||
{
|
||||
string command = line.Substring(0, line.IndexOf(' '));
|
||||
|
||||
CommandBase commandToRet = CheckCommand(command);
|
||||
|
||||
return commandToRet;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks to see if the command is valid.
|
||||
/// </summary>
|
||||
/// <param name="comm"></param>
|
||||
/// <returns>Returns the command in the form of CommandBase if found, otherwise returns null.</returns>
|
||||
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<ParameterBase> paramsTemp = new List<ParameterBase>();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
;
|
||||
|
|
|
|||
|
|
@ -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 = "$";
|
||||
|
||||
/// <summary>
|
||||
/// 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 + " ");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -103,4 +103,4 @@ namespace RsenkTest
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -55,14 +55,7 @@
|
|||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Commands\ClearScreen\ClearScreen.cs" />
|
||||
<Compile Include="Commands\CommandBase.cs" />
|
||||
<Compile Include="CommanderShell.cs" />
|
||||
<Compile Include="Commands\HelpCommand.cs" />
|
||||
<Compile Include="Commands\ParameterBase.cs" />
|
||||
<Compile Include="Commands\Version\VerAll.cs" />
|
||||
<Compile Include="Commands\Version\VerCommander.cs" />
|
||||
<Compile Include="Commands\Version\Version.cs" />
|
||||
<Compile Include="Commander.cs" />
|
||||
<Compile Include="Interpreter.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Prompter.cs" />
|
||||
|
|
|
|||
Loading…
Reference in a new issue