Programs now built using IProgram interface

- The old App abstract class has been scrapped in favor of the IProgram interface in the Tomas.Interface library.
- A new terminal emulator was created when not on Windows.
- In both OS and terminal, a single dictionary has the commands and classes that implement IProgram.
- Start() now returns a boolean that behaves similar to C's main in returning an integer.
- A new while loop in both terminal and kernel handles the execution of programs.
This commit is contained in:
Tony Bark 2021-03-30 08:26:18 -04:00
parent 952554b476
commit c11f987521
31 changed files with 387 additions and 219 deletions

View file

@ -0,0 +1,19 @@
namespace Tomas.Terminal
{
class Program
{
static void Main()
{
while (true)
{
var shell = new Shell();
var command = shell.ReadLine;
TermConsts.Programs.TryGetValue(command, out var program);
var isRun = program.Start();
if (isRun) continue;
break;
}
}
}
}

View file

@ -0,0 +1,21 @@
using System;
using Tomas.Common;
using Tomas.Interface.Shell;
namespace Tomas.Terminal.Programs
{
public class About : IProgram
{
public bool Start()
{
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);
return true;
}
}
}

View file

@ -0,0 +1,20 @@
using System;
using Tomas.Interface.Shell;
namespace Tomas.Terminal
{
public class Shell : IShell
{
const char SYMBOL = '$';
public string ReadLine
{
get
{
Console.Write(SYMBOL);
var readl = Console.ReadLine();
return readl;
}
}
}
}

View file

@ -0,0 +1,17 @@
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()}
};
}
}

View file

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<LangVersion>8</LangVersion>
<Nullable>warnings</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Tomas.Common\Tomas.Common.csproj" />
<ProjectReference Include="..\Tomas.Interface\Tomas.Interface.csproj" />
</ItemGroup>
</Project>