diff --git a/src/TOMAS.sln b/src/TOMAS.sln index 75fb522..5fff92d 100644 --- a/src/TOMAS.sln +++ b/src/TOMAS.sln @@ -19,7 +19,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tomas.Interface", "Tomas.In EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tomas.Terminal", "Tomas.Terminal\Tomas.Terminal.csproj", "{49E67E55-F9D2-419A-8097-38F39E98A95E}" 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 Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/src/Tomas.Kernal/GlobalUsing.cs b/src/Tomas.Kernal/GlobalUsing.cs index 9d9efd3..a1606b9 100644 --- a/src/Tomas.Kernal/GlobalUsing.cs +++ b/src/Tomas.Kernal/GlobalUsing.cs @@ -1,4 +1,5 @@ global using Tomas.Common.Programs; global using Tomas.Interface; +global using Tomas.Kernel; global using Tomas.Kernel.Programs; global using Os = Cosmos.System; \ No newline at end of file diff --git a/src/Tomas.Kernal/Kernel.cs b/src/Tomas.Kernal/Kernel.cs index 8c29342..bd5113c 100644 --- a/src/Tomas.Kernal/Kernel.cs +++ b/src/Tomas.Kernal/Kernel.cs @@ -2,22 +2,54 @@ // See the LICENSE file in the project root for more information. using System; -namespace Tomas.Kernal +namespace Tomas.Kernel; + +public class Kernel : Os.Kernel { - public class Kernel : Os.Kernel + + protected override void BeforeRun() { + Console.Clear(); + Console.WriteLine("TOMAS booted successfully."); + } - protected override void BeforeRun() - { - Console.WriteLine("Cosmos booted successfully. Type a line of text to get it echoed back."); - } + protected override void Run() + { + /* + Console.Write("$"); + var input = Console.ReadLine(); + Console.Write("Text typed: "); + Console.WriteLine(input); + */ - protected override void Run() + while (true) { - Console.Write("$"); - var input = Console.ReadLine(); - Console.Write("Text typed: "); - Console.WriteLine(input); + 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); + } } } } diff --git a/src/Tomas.Kernal/Programs/About.cs b/src/Tomas.Kernal/Programs/About.cs index 71a4658..5ec9dad 100644 --- a/src/Tomas.Kernal/Programs/About.cs +++ b/src/Tomas.Kernal/Programs/About.cs @@ -3,19 +3,18 @@ using System; using Tomas.Common; -namespace Tomas.Kernel.Programs -{ - public class About : IProgram - { - public bool Run(IShell shell) - { - Console.WriteLine($"{ComConsts.NAME} v{ComConsts.VersionGit}{Environment.NewLine}" - + "TOMAS (Tony's Managed Operating System) is a operating system written in C# using the COSMOS framework."); - var progs = shell.Programs; - foreach (var commands in progs.Keys) - Console.WriteLine(commands); +namespace Tomas.Kernel.Programs; - return true; - } - } +public class About : IProgram +{ + public bool Run(IShell shell) + { + Console.WriteLine($"{ComConsts.NAME} v{ComConsts.VersionGit}{Environment.NewLine}" + + "TOMAS (Tony's Managed Operating System) is a operating system written in C# using the COSMOS framework."); + var progs = shell.Programs; + foreach (var commands in progs.Keys) + Console.WriteLine(commands); + + return true; + } } \ No newline at end of file diff --git a/src/Tomas.Kernal/Programs/Shutdown.cs b/src/Tomas.Kernal/Programs/Shutdown.cs new file mode 100644 index 0000000..e083530 --- /dev/null +++ b/src/Tomas.Kernal/Programs/Shutdown.cs @@ -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; + } +} diff --git a/src/Tomas.Kernal/Shell.cs b/src/Tomas.Kernal/Shell.cs index c5e3c4c..17837aa 100644 --- a/src/Tomas.Kernal/Shell.cs +++ b/src/Tomas.Kernal/Shell.cs @@ -3,28 +3,28 @@ using System; using System.Collections.Generic; -namespace Tomas.Kernel +namespace Tomas.Kernel; + +public class Shell : IShell { - public class Shell : IShell + const char SYMBOL = '$'; + + public Dictionary Programs => new Dictionary() { - const char SYMBOL = '$'; + {"about", new About() }, + {"fensay", new FenSay() }, + {"clear", new Clear() }, + {"commands", new Commands() }, + {"shutdown", new Shutdown() } + }; - public Dictionary Programs => new Dictionary() + public string ReadLine + { + get { - {"about", new About()}, - {"fensay", new FenSay()}, - {"clear", new Clear()}, - {"commands", new Commands()} - }; - - public string ReadLine - { - get - { - Console.Write(SYMBOL); - var readl = Console.ReadLine(); - return readl; - } + Console.Write(SYMBOL); + var readl = Console.ReadLine(); + return readl; } } } diff --git a/src/Tomas.Kernal/TomFS.cs b/src/Tomas.Kernal/TomFS.cs index c1ebc46..48223e0 100644 --- a/src/Tomas.Kernal/TomFS.cs +++ b/src/Tomas.Kernal/TomFS.cs @@ -6,47 +6,46 @@ using Cosmos.System.FileSystem; using Cosmos.System.FileSystem.VFS; using Tomas.Common; -namespace Tomas.Kernel +namespace Tomas.Kernel; + +class TomFS { - class TomFS - { - public const string ROOT_DIR = "0:\\"; - public static string SYSTEM_DIR = $"{ROOT_DIR}\\SYSTEM\\"; + public const string ROOT_DIR = "0:\\"; + public static string SYSTEM_DIR = $"{ROOT_DIR}\\SYSTEM\\"; - public static void Initialize() - { - try - { - var fs = new CosmosVFS(); - VFSManager.RegisterVFS(fs); - fs.CreateDirectory(SYSTEM_DIR); - Console.WriteLine("Creating system files."); - fs.CreateFile($"{SYSTEM_DIR}sysinfo.txt"); - Console.WriteLine("Setting system preferences."); - File.WriteAllText($"{SYSTEM_DIR}sysinfo.txt", $"{ComConsts.NAME}, {ComConsts.VersionGit}"); - Console.WriteLine("File system loaded sucesfully."); - var intro = File.ReadAllText($"{SYSTEM_DIR}sysinfo.txt"); - Console.WriteLine(intro); + public static void Initialize() + { + try + { + var fs = new CosmosVFS(); + VFSManager.RegisterVFS(fs); + fs.CreateDirectory(SYSTEM_DIR); + Console.WriteLine("Creating system files."); + fs.CreateFile($"{SYSTEM_DIR}sysinfo.txt"); + Console.WriteLine("Setting system preferences."); + File.WriteAllText($"{SYSTEM_DIR}sysinfo.txt", $"{ComConsts.NAME}, {ComConsts.VersionGit}"); + Console.WriteLine("File system loaded sucesfully."); + var intro = File.ReadAllText($"{SYSTEM_DIR}sysinfo.txt"); + Console.WriteLine(intro); - } - catch - { - Console.WriteLine("File system failed to load! Not all functions will work."); - } - } + } + catch + { + Console.WriteLine("File system failed to load! Not all functions will work."); + } + } - public static string[] ListDirectories(string path) - { - try - { - var dirs = Directory.GetDirectories(path); - return dirs; - } - catch - { - Console.WriteLine("Failed to find any directories."); - throw; - } - } - } + public static string[] ListDirectories(string path) + { + try + { + var dirs = Directory.GetDirectories(path); + return dirs; + } + catch + { + Console.WriteLine("Failed to find any directories."); + throw; + } + } } diff --git a/src/Tomas.Kernal/Tomas.Kernal.csproj b/src/Tomas.Kernal/Tomas.Kernel.csproj similarity index 100% rename from src/Tomas.Kernal/Tomas.Kernal.csproj rename to src/Tomas.Kernal/Tomas.Kernel.csproj diff --git a/src/Tomas.Terminal/Programs/About.cs b/src/Tomas.Terminal/Programs/About.cs index bec288e..f8e6fa9 100644 --- a/src/Tomas.Terminal/Programs/About.cs +++ b/src/Tomas.Terminal/Programs/About.cs @@ -1,17 +1,15 @@ // I license this project under the BSD 3-Clause license. // See the LICENSE file in the project root for more information. 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) - { - Console.WriteLine($"{ComConsts.NAME} Terminal Emulator v{ComConsts.VersionGit}{Environment.NewLine}" - + "TOMAS (Tony's Managed Operating System) is a operating system written in C# using the COSMOS framework."); - return true; - } - } +public bool Run(IShell shell) +{ +Console.WriteLine($"{ComConsts.NAME} Terminal Emulator v{ComConsts.VersionGit}{Environment.NewLine}" + + "TOMAS (Tony's Managed Operating System) is a operating system written in C# using the COSMOS framework."); +return true; +} } \ No newline at end of file