mirror of
https://github.com/tonytins/tomas.git
synced 2025-06-25 18:14:42 -04:00
Start() in IProgram has been renamed to Run()
- Run() loop in the shell is now wrapped in a try-catch statement. - Added Github CI - Removed OSConsts and TermConsts - Programs can now access the programs dictionary directly from the shell
This commit is contained in:
parent
d1ccfad2ae
commit
4f0863f429
16 changed files with 149 additions and 93 deletions
|
@ -12,17 +12,30 @@ namespace Tomas.Terminal
|
|||
{
|
||||
var shell = new Shell();
|
||||
var command = shell.ReadLine;
|
||||
var programs = shell.Programs;
|
||||
|
||||
if (!TermConsts.Programs.TryGetValue(command, out var program))
|
||||
if (!programs.TryGetValue(command, out var program))
|
||||
{
|
||||
Console.WriteLine("Command Unknown.");
|
||||
Console.WriteLine("Command Not Found.");
|
||||
continue;
|
||||
}
|
||||
|
||||
var start = program.Start();
|
||||
if (start) continue;
|
||||
|
||||
break;
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,21 +2,16 @@
|
|||
// See the LICENSE file in the project root for more information.
|
||||
using System;
|
||||
using Tomas.Common;
|
||||
using Tomas.Interface.Shell;
|
||||
using Tomas.Interface;
|
||||
|
||||
namespace Tomas.Terminal.Programs
|
||||
{
|
||||
public class About : IProgram
|
||||
{
|
||||
public bool Start()
|
||||
public bool Run(IShell shell)
|
||||
{
|
||||
Console.WriteLine($"{ComConsts.NAME} v{ComConsts.VersionGit}{Environment.NewLine}");
|
||||
|
||||
Console.WriteLine("Commands:");
|
||||
var progs = TermConsts.Programs;
|
||||
foreach (var commands in progs.Keys)
|
||||
Console.WriteLine(commands);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
// I license this project under the GPL 3.0 license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
using System;
|
||||
using Tomas.Interface.Shell;
|
||||
using System.Collections.Generic;
|
||||
using Tomas.Common.Programs;
|
||||
using Tomas.Interface;
|
||||
using Tomas.Terminal.Programs;
|
||||
|
||||
namespace Tomas.Terminal
|
||||
{
|
||||
|
@ -9,6 +12,14 @@ namespace Tomas.Terminal
|
|||
{
|
||||
const char SYMBOL = '$';
|
||||
|
||||
public Dictionary<string, IProgram> Programs => new Dictionary<string, IProgram>()
|
||||
{
|
||||
{"about", new About()},
|
||||
{"fensay", new FenSay()},
|
||||
{"clear", new Clear()},
|
||||
{"commands", new Commands()}
|
||||
};
|
||||
|
||||
public string ReadLine
|
||||
{
|
||||
get
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
// I license this project under the GPL 3.0 license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
using System.Collections.Generic;
|
||||
using Tomas.Interface.Shell;
|
||||
using Tomas.Kernel.Programs;
|
||||
using Tomas.Terminal.Programs;
|
||||
|
||||
namespace Tomas.Terminal
|
||||
{
|
||||
public struct TermConsts
|
||||
{
|
||||
public static Dictionary<string, IProgram> Programs => new Dictionary<string, IProgram>()
|
||||
{
|
||||
{"about", new About()},
|
||||
{"fensay", new FenSay()},
|
||||
{"clear", new Clear()}
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue