mirror of
https://github.com/tonytins/tomas.git
synced 2025-06-25 18:14:42 -04:00
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:
parent
952554b476
commit
c11f987521
31 changed files with 387 additions and 219 deletions
19
src/Tomas.Terminal/Program.cs
Normal file
19
src/Tomas.Terminal/Program.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
21
src/Tomas.Terminal/Programs/About.cs
Normal file
21
src/Tomas.Terminal/Programs/About.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
20
src/Tomas.Terminal/Shell.cs
Normal file
20
src/Tomas.Terminal/Shell.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
17
src/Tomas.Terminal/TermConsts.cs
Normal file
17
src/Tomas.Terminal/TermConsts.cs
Normal 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()}
|
||||
};
|
||||
}
|
||||
}
|
15
src/Tomas.Terminal/Tomas.Terminal.csproj
Normal file
15
src/Tomas.Terminal/Tomas.Terminal.csproj
Normal 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>
|
Loading…
Add table
Add a link
Reference in a new issue