Return of kernal programs

- Boot log is now cleared
- File scoped namespaces work
This commit is contained in:
Tony Bark 2023-01-06 19:34:09 -05:00
parent 7530f8500b
commit a06f9ccc9f
9 changed files with 136 additions and 94 deletions

View file

@ -19,7 +19,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tomas.Interface", "Tomas.In
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tomas.Terminal", "Tomas.Terminal\Tomas.Terminal.csproj", "{49E67E55-F9D2-419A-8097-38F39E98A95E}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tomas.Terminal", "Tomas.Terminal\Tomas.Terminal.csproj", "{49E67E55-F9D2-419A-8097-38F39E98A95E}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tomas.Kernal", "Tomas.Kernal\Tomas.Kernal.csproj", "{20750C95-A3C7-4958-BA9F-56E4C3BD0293}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tomas.Kernel", "Tomas.Kernal\Tomas.Kernel.csproj", "{20750C95-A3C7-4958-BA9F-56E4C3BD0293}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution

View file

@ -1,4 +1,5 @@
global using Tomas.Common.Programs; global using Tomas.Common.Programs;
global using Tomas.Interface; global using Tomas.Interface;
global using Tomas.Kernel;
global using Tomas.Kernel.Programs; global using Tomas.Kernel.Programs;
global using Os = Cosmos.System; global using Os = Cosmos.System;

View file

@ -2,22 +2,54 @@
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using System; using System;
namespace Tomas.Kernal namespace Tomas.Kernel;
{
public class Kernel : Os.Kernel public class Kernel : Os.Kernel
{ {
protected override void BeforeRun() protected override void BeforeRun()
{ {
Console.WriteLine("Cosmos booted successfully. Type a line of text to get it echoed back."); Console.Clear();
Console.WriteLine("TOMAS booted successfully.");
} }
protected override void Run() protected override void Run()
{ {
/*
Console.Write("$"); Console.Write("$");
var input = Console.ReadLine(); var input = Console.ReadLine();
Console.Write("Text typed: "); Console.Write("Text typed: ");
Console.WriteLine(input); Console.WriteLine(input);
*/
while (true)
{
var shell = new Shell();
var command = shell.ReadLine;
var programs = shell.Programs;
if (!programs.TryGetValue(command, out var program))
{
Console.WriteLine("Command Not Found.");
continue;
}
try
{
var start = program.Run(shell);
switch (start)
{
case true:
continue;
case false:
Console.WriteLine("Program closed unexpectedly.");
continue;
}
}
catch (Exception err)
{
Console.WriteLine(err.Message);
}
} }
} }
} }

View file

@ -3,8 +3,8 @@
using System; using System;
using Tomas.Common; using Tomas.Common;
namespace Tomas.Kernel.Programs namespace Tomas.Kernel.Programs;
{
public class About : IProgram public class About : IProgram
{ {
public bool Run(IShell shell) public bool Run(IShell shell)
@ -18,4 +18,3 @@ namespace Tomas.Kernel.Programs
return true; return true;
} }
} }
}

View file

@ -0,0 +1,13 @@
using System;
namespace Tomas.Kernel.Programs;
internal class Shutdown : IProgram
{
public bool Run(IShell shell)
{
Environment.Exit(Environment.ExitCode);
return true;
}
}

View file

@ -3,8 +3,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace Tomas.Kernel namespace Tomas.Kernel;
{
public class Shell : IShell public class Shell : IShell
{ {
const char SYMBOL = '$'; const char SYMBOL = '$';
@ -14,7 +14,8 @@ namespace Tomas.Kernel
{"about", new About() }, {"about", new About() },
{"fensay", new FenSay() }, {"fensay", new FenSay() },
{"clear", new Clear() }, {"clear", new Clear() },
{"commands", new Commands()} {"commands", new Commands() },
{"shutdown", new Shutdown() }
}; };
public string ReadLine public string ReadLine
@ -27,4 +28,3 @@ namespace Tomas.Kernel
} }
} }
} }
}

View file

@ -6,8 +6,8 @@ using Cosmos.System.FileSystem;
using Cosmos.System.FileSystem.VFS; using Cosmos.System.FileSystem.VFS;
using Tomas.Common; using Tomas.Common;
namespace Tomas.Kernel namespace Tomas.Kernel;
{
class TomFS class TomFS
{ {
public const string ROOT_DIR = "0:\\"; public const string ROOT_DIR = "0:\\";
@ -49,4 +49,3 @@ namespace Tomas.Kernel
} }
} }
} }
}

View file

@ -1,10 +1,9 @@
// I license this project under the BSD 3-Clause license. // I license this project under the BSD 3-Clause license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using Tomas.Common; using Tomas.Common;
using Tomas.Interface;
namespace Tomas.Terminal.Programs namespace Tomas.Terminal.Programs;
{
public class About : IProgram public class About : IProgram
{ {
public bool Run(IShell shell) public bool Run(IShell shell)
@ -14,4 +13,3 @@ namespace Tomas.Terminal.Programs
return true; return true;
} }
} }
}