mirror of
https://github.com/tonytins/tomas.git
synced 2025-03-15 04:11:24 +00:00
Return of kernal programs
- Boot log is now cleared - File scoped namespaces work
This commit is contained in:
parent
7530f8500b
commit
a06f9ccc9f
9 changed files with 136 additions and 94 deletions
|
@ -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
|
||||
|
|
|
@ -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;
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
13
src/Tomas.Kernal/Programs/Shutdown.cs
Normal file
13
src/Tomas.Kernal/Programs/Shutdown.cs
Normal 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;
|
||||
}
|
||||
}
|
|
@ -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<string, IProgram> Programs => new Dictionary<string, IProgram>()
|
||||
{
|
||||
const char SYMBOL = '$';
|
||||
{"about", new About() },
|
||||
{"fensay", new FenSay() },
|
||||
{"clear", new Clear() },
|
||||
{"commands", new Commands() },
|
||||
{"shutdown", new Shutdown() }
|
||||
};
|
||||
|
||||
public Dictionary<string, IProgram> Programs => new Dictionary<string, IProgram>()
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue