Everything but exit works.

This commit is contained in:
moitoius_cp 2008-01-02 14:44:18 +00:00
parent b979134b77
commit b29251b4d4
10 changed files with 272 additions and 6 deletions

View file

@ -30,6 +30,8 @@ namespace Cosmos.Kernel {
public static void Clear() {
HW.Text.Clear();
CurrentChar = 0;
CurrentLine = 0;
}
public static void WriteChar(char aChar) {

View file

@ -10,10 +10,21 @@ namespace Cosmos.Shell.Console.Commands {
/// <summary>
/// Gets the name of the command (must be lowercase).
/// </summary>
public abstract string Name {
get;
}
public abstract string Name
{
get;
}
/// <summary>
/// Gets the summary for the command.
/// </summary>
public abstract string Summary
{
get;
}
public abstract void Execute(string param);
public abstract void Help();
}
}

View file

@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Cosmos.Shell.Console.Commands
{
public class ClsCommand : CommandBase
{
public override string Name
{
get { return "cls"; }
}
public override string Summary
{
get { return "Clears the screen."; }
}
public override void Execute(string param)
{
System.Console.Clear();
}
public override void Help()
{
System.Console.WriteLine("cls");
System.Console.WriteLine(" Clears the screen.");
}
}
}

View file

@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Cosmos.Shell.Console.Commands
{
public class DirCommand : CommandBase
{
public override string Name
{
get { return "dir"; }
}
public override string Summary
{
get { return "Lists the files in the current directory."; }
}
public override void Execute(string param)
{
Hardware.Storage.ATA xDrive = new Cosmos.Hardware.Storage.ATA(0, 0);
Cosmos.Kernel.FileSystem.Ext2 xExt2 = new Cosmos.Kernel.FileSystem.Ext2 (xDrive);
xExt2.Initialize();
string[] files = xExt2.GetDirectoryEntries(new string[0]);
for (int i = 0; i < files.Length; i++)
System.Console.WriteLine(files[i]);
}
public override void Help()
{
System.Console.WriteLine("dir");
System.Console.WriteLine(" Lists the files in the current directory.");
}
}
}

View file

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Cosmos.Shell.Console.Commands
{
public class EchoCommand : CommandBase
{
public override string Name
{
get { return "echo"; }
}
public override string Summary
{
get { return "Duplicates text you enter to the console."; }
}
public override void Execute(string param)
{
System.Console.WriteLine(param);
System.Console.WriteLine();
}
public override void Help()
{
System.Console.WriteLine("echo [text]");
System.Console.WriteLine(" Duplicates text you enter to the console.");
System.Console.WriteLine(" [text]: The text to duplicate.");
}
}
}

View file

@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Cosmos.Shell.Console.Commands
{
public class ExitCommand : CommandBase
{
public override string Name
{
get { return "exit"; }
}
public override string Summary
{
get { return "Closes the console."; }
}
public delegate void SimpleDelegate();
private SimpleDelegate _exit;
public ExitCommand(SimpleDelegate exit)
{
_exit = exit;
}
public override void Execute(string param)
{
_exit();
}
public override void Help()
{
System.Console.WriteLine("exit");
System.Console.WriteLine(" Closes the console.");
}
}
}

View file

@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Cosmos.Shell.Console.Commands
{
public class HelpCommand : CommandBase
{
public override string Name
{
get { return "help"; }
}
public HelpCommand(List<CommandBase> commands)
{
_commands = commands;
}
private List<CommandBase> _commands;
public override void Execute(string param)
{
if (param.CompareTo("") == 0)
DisplayCommands();
else
CommandHelp(param);
}
private void CommandHelp(string command)
{
bool found = false;
for (int i = 0; i < _commands.Count; i++)
{
if (_commands[i].Name.CompareTo(command) == 0)
{
found = true;
_commands[i].Help();
System.Console.WriteLine();
break;
}
}
if (!found)
{
System.Console.ForegroundColor = ConsoleColor.Red;
System.Console.Write("The command ");
System.Console.Write(command);
System.Console.WriteLine(" is not supported. Please type help for more information.");
System.Console.ForegroundColor = ConsoleColor.White;
System.Console.WriteLine();
}
}
private void DisplayCommands()
{
System.Console.WriteLine("Supported Commands:");
for (int i = 0; i < _commands.Count; i++)
{
System.Console.ForegroundColor = ConsoleColor.Red;
System.Console.Write(" ");
System.Console.Write(_commands[i].Name);
System.Console.Write(": ");
System.Console.ForegroundColor = ConsoleColor.White;
System.Console.WriteLine(_commands[i].Summary);
}
System.Console.WriteLine("Please type help [command] for more information.");
System.Console.WriteLine();
}
public override void Help()
{
System.Console.WriteLine("help [command]");
System.Console.WriteLine(" Gets help on a specific command.");
System.Console.WriteLine(" [command]:The command to look up.");
}
public override string Summary
{
get { return "Gets help on a specific command."; }
}
}
}

View file

@ -40,5 +40,17 @@ namespace Cosmos.Shell.Console.Commands {
String s = new String(xChars);
System.Console.WriteLine(s);
}
}
public override void Help()
{
System.Console.WriteLine("type [filename]");
System.Console.WriteLine(" Types the specified file out to the console window.");
System.Console.WriteLine(" [filename]: The name of the file.");
}
public override string Summary
{
get { return "Types the specified file out to the console window."; }
}
}
}

View file

@ -42,6 +42,11 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Commands\ClsCommand.cs" />
<Compile Include="Commands\DirCommand.cs" />
<Compile Include="Commands\EchoCommand.cs" />
<Compile Include="Commands\ExitCommand.cs" />
<Compile Include="Commands\HelpCommand.cs" />
<Compile Include="Commands\TypeCommand.cs" />
<Compile Include="Commands\BaseCommand.cs" />
<Compile Include="Program.cs" />

View file

@ -25,7 +25,13 @@ namespace Cosmos.Shell.Console {
public override void Initialize() {
_commands = new List<Cosmos.Shell.Console.Commands.CommandBase>();
_commands.Add(new Commands.ClsCommand());
_commands.Add(new Commands.DirCommand());
_commands.Add(new Commands.EchoCommand());
_commands.Add(new Commands.ExitCommand(Stop));
_commands.Add(new Commands.HelpCommand(_commands));
_commands.Add(new Commands.TypeCommand());
while (running)
{
@ -45,16 +51,26 @@ namespace Cosmos.Shell.Console {
param = line.Substring(index + 1);
}
bool found = false;
for (int i = 0; i < _commands.Count; i++)
{
if (_commands[i].Name.CompareTo(command) == 0)
{
found = true;
_commands[i].Execute(param);
break;
}
}
if (!found)
{
System.Console.ForegroundColor = ConsoleColor.Red;
System.Console.Write("The command ");
System.Console.Write(command);
System.Console.WriteLine(" is not supported. Please type help for more information.");
System.Console.ForegroundColor = ConsoleColor.White;
System.Console.WriteLine();
}
}
}