mirror of
https://github.com/tonytins/tomas.git
synced 2025-03-21 15:21:21 +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
|
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
|
||||||
|
|
|
@ -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;
|
|
@ -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()
|
||||||
{
|
{
|
||||||
|
Console.Clear();
|
||||||
|
Console.WriteLine("TOMAS booted successfully.");
|
||||||
|
}
|
||||||
|
|
||||||
protected override void BeforeRun()
|
protected override void Run()
|
||||||
{
|
{
|
||||||
Console.WriteLine("Cosmos booted successfully. Type a line of text to get it echoed back.");
|
/*
|
||||||
}
|
Console.Write("$");
|
||||||
|
var input = Console.ReadLine();
|
||||||
|
Console.Write("Text typed: ");
|
||||||
|
Console.WriteLine(input);
|
||||||
|
*/
|
||||||
|
|
||||||
protected override void Run()
|
while (true)
|
||||||
{
|
{
|
||||||
Console.Write("$");
|
var shell = new Shell();
|
||||||
var input = Console.ReadLine();
|
var command = shell.ReadLine;
|
||||||
Console.Write("Text typed: ");
|
var programs = shell.Programs;
|
||||||
Console.WriteLine(input);
|
|
||||||
|
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 System;
|
||||||
using Tomas.Common;
|
using Tomas.Common;
|
||||||
|
|
||||||
namespace Tomas.Kernel.Programs
|
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);
|
|
||||||
|
|
||||||
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;
|
||||||
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 = '$';
|
||||||
|
|
||||||
|
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()},
|
Console.Write(SYMBOL);
|
||||||
{"fensay", new FenSay()},
|
var readl = Console.ReadLine();
|
||||||
{"clear", new Clear()},
|
return readl;
|
||||||
{"commands", new Commands()}
|
|
||||||
};
|
|
||||||
|
|
||||||
public string ReadLine
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
Console.Write(SYMBOL);
|
|
||||||
var readl = Console.ReadLine();
|
|
||||||
return readl;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,47 +6,46 @@ 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 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()
|
public static void Initialize()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var fs = new CosmosVFS();
|
var fs = new CosmosVFS();
|
||||||
VFSManager.RegisterVFS(fs);
|
VFSManager.RegisterVFS(fs);
|
||||||
fs.CreateDirectory(SYSTEM_DIR);
|
fs.CreateDirectory(SYSTEM_DIR);
|
||||||
Console.WriteLine("Creating system files.");
|
Console.WriteLine("Creating system files.");
|
||||||
fs.CreateFile($"{SYSTEM_DIR}sysinfo.txt");
|
fs.CreateFile($"{SYSTEM_DIR}sysinfo.txt");
|
||||||
Console.WriteLine("Setting system preferences.");
|
Console.WriteLine("Setting system preferences.");
|
||||||
File.WriteAllText($"{SYSTEM_DIR}sysinfo.txt", $"{ComConsts.NAME}, {ComConsts.VersionGit}");
|
File.WriteAllText($"{SYSTEM_DIR}sysinfo.txt", $"{ComConsts.NAME}, {ComConsts.VersionGit}");
|
||||||
Console.WriteLine("File system loaded sucesfully.");
|
Console.WriteLine("File system loaded sucesfully.");
|
||||||
var intro = File.ReadAllText($"{SYSTEM_DIR}sysinfo.txt");
|
var intro = File.ReadAllText($"{SYSTEM_DIR}sysinfo.txt");
|
||||||
Console.WriteLine(intro);
|
Console.WriteLine(intro);
|
||||||
|
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
Console.WriteLine("File system failed to load! Not all functions will work.");
|
Console.WriteLine("File system failed to load! Not all functions will work.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string[] ListDirectories(string path)
|
public static string[] ListDirectories(string path)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var dirs = Directory.GetDirectories(path);
|
var dirs = Directory.GetDirectories(path);
|
||||||
return dirs;
|
return dirs;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
Console.WriteLine("Failed to find any directories.");
|
Console.WriteLine("Failed to find any directories.");
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,15 @@
|
||||||
// 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)
|
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.");
|
||||||
Console.WriteLine($"{ComConsts.NAME} Terminal Emulator v{ComConsts.VersionGit}{Environment.NewLine}"
|
return true;
|
||||||
+ "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