mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-21 13:28:41 +00:00
Started work on a custom shell for me to test things with.
This commit is contained in:
parent
4513e4144d
commit
4104c87c99
14 changed files with 544 additions and 0 deletions
50
source/RsenkTest/CommanderShell.cs
Normal file
50
source/RsenkTest/CommanderShell.cs
Normal file
|
|
@ -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<CommandBase> commands = new List<CommandBase>();
|
||||
|
||||
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() { }
|
||||
}
|
||||
}
|
||||
38
source/RsenkTest/Commands/ClearScreen/ClearScreen.cs
Normal file
38
source/RsenkTest/Commands/ClearScreen/ClearScreen.cs
Normal file
|
|
@ -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("");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
15
source/RsenkTest/Commands/CommandBase.cs
Normal file
15
source/RsenkTest/Commands/CommandBase.cs
Normal file
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
15
source/RsenkTest/Commands/ParameterBase.cs
Normal file
15
source/RsenkTest/Commands/ParameterBase.cs
Normal file
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
35
source/RsenkTest/Commands/Version/VerAll.cs
Normal file
35
source/RsenkTest/Commands/Version/VerAll.cs
Normal file
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
40
source/RsenkTest/Commands/Version/VerCommander.cs
Normal file
40
source/RsenkTest/Commands/Version/VerCommander.cs
Normal file
|
|
@ -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");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="args"></param>
|
||||
[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();
|
||||
}
|
||||
}
|
||||
}
|
||||
33
source/RsenkTest/Commands/Version/Version.cs
Normal file
33
source/RsenkTest/Commands/Version/Version.cs
Normal file
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
43
source/RsenkTest/Interpreter.cs
Normal file
43
source/RsenkTest/Interpreter.cs
Normal file
|
|
@ -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<CommandBase> _commands;
|
||||
|
||||
public Interpreter(List<CommandBase> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
43
source/RsenkTest/Program.cs
Normal file
43
source/RsenkTest/Program.cs
Normal file
|
|
@ -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)
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
93
source/RsenkTest/Prompter.cs
Normal file
93
source/RsenkTest/Prompter.cs
Normal file
|
|
@ -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 = '$';
|
||||
|
||||
/// <summary>
|
||||
/// The different message types possible
|
||||
/// </summary>
|
||||
private enum MessageType
|
||||
{
|
||||
Normal,
|
||||
Warning,
|
||||
Error
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Displays the prompt string
|
||||
/// </summary>
|
||||
/// <param name="user">The current user.</param>
|
||||
/// <param name="path">The current path.</param>
|
||||
public static void Prompt(string user, string path)
|
||||
{
|
||||
Console.Write("[" + user + ":" + path + "]" + SYM_NORM + " ");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prints the welcome message to the console.
|
||||
/// </summary>
|
||||
/// <param name="additional">Additional messages to be displayed.</param>
|
||||
public static void PrintWelcome(string additional)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.DarkMagenta;
|
||||
Console.WriteLine("Welcome to Cosmos Commander!\n\n");
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prints an error message to the console.
|
||||
/// </summary>
|
||||
public static void PrintError(string error)
|
||||
{
|
||||
PrintMessage(error, MessageType.Error);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prints a warning message to the console.
|
||||
/// </summary>
|
||||
public static void PrintWarning(string warning)
|
||||
{
|
||||
PrintMessage(warning, MessageType.Warning);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prints a message to the console.
|
||||
/// </summary>
|
||||
public static void PrintMessage(string message)
|
||||
{
|
||||
PrintMessage(message, MessageType.Normal);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prints a message to the console and sets the foreground color depending on the message type.
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
14
source/RsenkTest/PrompterException.cs
Normal file
14
source/RsenkTest/PrompterException.cs
Normal file
|
|
@ -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) { }
|
||||
}
|
||||
}
|
||||
36
source/RsenkTest/Properties/AssemblyInfo.cs
Normal file
36
source/RsenkTest/Properties/AssemblyInfo.cs
Normal file
|
|
@ -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")]
|
||||
79
source/RsenkTest/RsenkTest.csproj
Normal file
79
source/RsenkTest/RsenkTest.csproj
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.21022</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{F598F906-8F3B-4EC1-AB8F-A9CBD8EBBE21}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>RsenkTest</RootNamespace>
|
||||
<AssemblyName>RsenkTest</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<SccProjectName>SAK</SccProjectName>
|
||||
<SccLocalPath>SAK</SccLocalPath>
|
||||
<SccAuxPath>SAK</SccAuxPath>
|
||||
<SccProvider>SAK</SccProvider>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Cosmos.Build.Windows, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5ae71220097cb983, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\Cosmos.Build.Windows\bin\Debug\Cosmos.Build.Windows.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Cosmos.Kernel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5ae71220097cb983, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\Cosmos\Cosmos.Kernel\bin\Debug\Cosmos.Kernel.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Xml.Linq">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Commands\ClearScreen\ClearScreen.cs" />
|
||||
<Compile Include="Commands\CommandBase.cs" />
|
||||
<Compile Include="CommanderShell.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="Interpreter.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Prompter.cs" />
|
||||
<Compile Include="PrompterException.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
10
source/RsenkTest/RsenkTest.csproj.vspscc
Normal file
10
source/RsenkTest/RsenkTest.csproj.vspscc
Normal file
|
|
@ -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"
|
||||
}
|
||||
Loading…
Reference in a new issue