mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-23 06:18:54 +00:00
Everything but exit works.
This commit is contained in:
parent
b979134b77
commit
b29251b4d4
10 changed files with 272 additions and 6 deletions
|
|
@ -30,6 +30,8 @@ namespace Cosmos.Kernel {
|
|||
|
||||
public static void Clear() {
|
||||
HW.Text.Clear();
|
||||
CurrentChar = 0;
|
||||
CurrentLine = 0;
|
||||
}
|
||||
|
||||
public static void WriteChar(char aChar) {
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
30
source/Cosmos/Cosmos.Shell.Console/Commands/ClsCommand.cs
Normal file
30
source/Cosmos/Cosmos.Shell.Console/Commands/ClsCommand.cs
Normal 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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
36
source/Cosmos/Cosmos.Shell.Console/Commands/DirCommand.cs
Normal file
36
source/Cosmos/Cosmos.Shell.Console/Commands/DirCommand.cs
Normal 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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
32
source/Cosmos/Cosmos.Shell.Console/Commands/EchoCommand.cs
Normal file
32
source/Cosmos/Cosmos.Shell.Console/Commands/EchoCommand.cs
Normal 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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
39
source/Cosmos/Cosmos.Shell.Console/Commands/ExitCommand.cs
Normal file
39
source/Cosmos/Cosmos.Shell.Console/Commands/ExitCommand.cs
Normal 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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
83
source/Cosmos/Cosmos.Shell.Console/Commands/HelpCommand.cs
Normal file
83
source/Cosmos/Cosmos.Shell.Console/Commands/HelpCommand.cs
Normal 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."; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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."; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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" />
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue