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:
Tony Bark 2021-03-31 00:10:38 -04:00
parent d1ccfad2ae
commit 4f0863f429
16 changed files with 149 additions and 93 deletions

28
.github/workflows/dotnet.yml vendored Normal file
View file

@ -0,0 +1,28 @@
name: .NET
on:
schedule:
- cron: "0 0 * * 0"
push:
branches: [master, main, develop, "feature/**"]
pull_request:
branches: [master, main, develop, "feature/**"]
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
dotnet: ["3.1.x", "5.0.x"]
os: [windows-latest, ubuntu-latest, macOS-latest]
steps:
- uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ matrix.dotnet }}
- name: Install dependencies
run: dotnet restore src/Tomas.Terminal
- name: Build
run: dotnet build src/Tomas.Terminal -c Release --no-restore

View file

@ -10,7 +10,7 @@ TOMAS (**To**ny's **Ma**naged Operating **S**ystem) is a operating system based
- Visual Studio 2019 - Visual Studio 2019
- COSMOS User Kit v20190508 or later - COSMOS User Kit v20190508 or later
- VMWare Workstation Player - VMWare Workstation Player
- .NET Core 2.1 or later - .NET Core 3.1 or later

View file

@ -1,11 +1,11 @@
using System; using System;
using Tomas.Interface.Shell; using Tomas.Interface;
namespace Tomas.Kernel.Programs namespace Tomas.Common.Programs
{ {
public class Clear : IProgram public class Clear : IProgram
{ {
public bool Start() public bool Run(IShell shell)
{ {
Console.Clear(); Console.Clear();
return true; return true;

View file

@ -0,0 +1,17 @@
using System;
using Tomas.Interface;
namespace Tomas.Common.Programs
{
public class Commands : IProgram
{
public bool Run(IShell shell)
{
Console.WriteLine($"Commands:");
var progs = shell.Programs;
foreach (var commands in progs.Keys)
Console.WriteLine(commands);
return true;
}
}
}

View file

@ -1,9 +1,10 @@
// I license this project under the GPL 3.0 license. // I license this project under the GPL 3.0 license.
// 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 Tomas.Interface.Shell;
namespace Tomas.Kernel.Programs using System;
using Tomas.Interface;
namespace Tomas.Common.Programs
{ {
public class FenSay : IProgram public class FenSay : IProgram
{ {
@ -11,7 +12,7 @@ namespace Tomas.Kernel.Programs
/// <summary> /// <summary>
/// Fennec art by Todd Vargo /// Fennec art by Todd Vargo
/// </summary> /// </summary>
const string FENNEC = @" \/ const string _fennec = @" \/
/\ /\ /\ /\
//\\_//\\ ____ //\\_//\\ ____
\_ _/ / / \_ _/ / /
@ -22,19 +23,19 @@ namespace Tomas.Kernel.Programs
[ [ / \/ _/ [ [ / \/ _/
_[ [ \ /_/"; _[ [ \ /_/";
readonly string[] _fenPhrases = readonly string[] _phrases =
{ {
"[Screams in Fennec]", "[SCREAMS IN FENNEC]",
"Some people call me a coffee fox.", "Some people call me a coffee fox.",
"Drink Soda. It makes you see faster.", "Drink Soda. It makes you see faster.",
"10/10, Wouldn't Recommend." "10/10, Wouldn't Recommend."
}; };
public bool Start() public bool Run(IShell shell)
{ {
var rng = new Random(); var rng = new Random();
var phrases = _fenPhrases[rng.Next(_fenPhrases.Length)]; var phrases = _phrases[rng.Next(_phrases.Length)];
Console.WriteLine($"{phrases}{Environment.NewLine}{FENNEC}"); Console.WriteLine($"{phrases}{Environment.NewLine}{_fennec}");
return true; return true;
} }
} }

View file

@ -0,0 +1,15 @@
// I license this project under the GPL 3.0 license.
// See the LICENSE file in the project root for more information.
namespace Tomas.Interface
{
public interface IProgram
{
/// <summary>
/// The program's main entry point. Boolean behaves as an exit point.
/// True and False are the equivalent to C's 0 and 1, i.e. "Success" and "Failure," respectfully.
/// </summary>
/// <param name="shell">Allows the program to interact with the shell.</param>
/// <returns>Exit back to shell.</returns>
bool Run(IShell shell);
}
}

View file

@ -1,9 +1,14 @@
// I license this project under the GPL 3.0 license. // I license this project under the GPL 3.0 license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
namespace Tomas.Interface.Shell
using System.Collections.Generic;
namespace Tomas.Interface
{ {
public interface IShell public interface IShell
{ {
string ReadLine { get; } string ReadLine { get; }
Dictionary<string, IProgram> Programs { get; }
} }
} }

View file

@ -1,9 +0,0 @@
// I license this project under the GPL 3.0 license.
// See the LICENSE file in the project root for more information.
namespace Tomas.Interface.Shell
{
public interface IProgram
{
bool Start();
}
}

View file

@ -3,9 +3,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Tomas.Common; using Tomas.Common;
using Tomas.Interface.Shell;
using Tomas.Kernel.Programs;
using Tomas.Terminal.Programs;
using Sys = Cosmos.System; using Sys = Cosmos.System;
namespace Tomas.Kernel namespace Tomas.Kernel
@ -42,10 +39,22 @@ namespace Tomas.Kernel
continue; continue;
} }
var start = program.Start(); try
if (start) continue; {
var start = program.Run(shell);
break; switch (start)
{
case true:
continue;
case false:
Console.WriteLine("Program closed unexpectedly.");
continue;
}
}
catch (Exception err)
{
Console.WriteLine(err.Message);
}
} }
} }

View file

@ -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.Kernel
{
public struct OSConsts
{
public static Dictionary<string, IProgram> Programs => new Dictionary<string, IProgram>()
{
{"about", new About()},
{"fensay", new FenSay()},
{"clear", new Clear()}
};
}
}

View file

@ -1,19 +1,19 @@
// I license this project under the GPL 3.0 license. // I license this project under the GPL 3.0 license.
// 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;
using Tomas.Common; using Tomas.Common;
using Tomas.Interface.Shell; using Tomas.Interface;
using Tomas.Kernel;
namespace Tomas.Terminal.Programs namespace Tomas.Kernel.Programs
{ {
public class About : IProgram public class About : IProgram
{ {
public bool Start() public bool Run(IShell shell)
{ {
Console.WriteLine($"{ComConsts.NAME} v{ComConsts.VersionGit}"); 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 = OSConsts.Programs; var progs = shell.Programs;
foreach (var commands in progs.Keys) foreach (var commands in progs.Keys)
Console.WriteLine(commands); Console.WriteLine(commands);

View file

@ -1,8 +1,9 @@
// I license this project under the GPL 3.0 license. // I license this project under the GPL 3.0 license.
// 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;
using Tomas.Common; using System.Collections.Generic;
using Tomas.Interface.Shell; using Tomas.Common.Programs;
using Tomas.Interface;
using Tomas.Kernel.Programs; using Tomas.Kernel.Programs;
using Sys = Cosmos.System; using Sys = Cosmos.System;
@ -12,6 +13,14 @@ namespace Tomas.Kernel
{ {
const char SYMBOL = '$'; 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 public string ReadLine
{ {
get get

View file

@ -12,17 +12,30 @@ namespace Tomas.Terminal
{ {
var shell = new Shell(); var shell = new Shell();
var command = shell.ReadLine; 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; continue;
} }
var start = program.Start(); try
if (start) continue; {
var start = program.Run(shell);
break; switch (start)
{
case true:
continue;
case false:
Console.WriteLine("Program closed unexpectedly.");
continue;
}
}
catch (Exception err)
{
Console.WriteLine(err.Message);
}
} }
} }
} }

View file

@ -2,21 +2,16 @@
// 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;
using Tomas.Common; using Tomas.Common;
using Tomas.Interface.Shell; using Tomas.Interface;
namespace Tomas.Terminal.Programs namespace Tomas.Terminal.Programs
{ {
public class About : IProgram public class About : IProgram
{ {
public bool Start() public bool Run(IShell shell)
{ {
Console.WriteLine($"{ComConsts.NAME} v{ComConsts.VersionGit}{Environment.NewLine}"); 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("Commands:");
var progs = TermConsts.Programs;
foreach (var commands in progs.Keys)
Console.WriteLine(commands);
return true; return true;
} }
} }

View file

@ -1,7 +1,10 @@
// I license this project under the GPL 3.0 license. // I license this project under the GPL 3.0 license.
// 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;
using Tomas.Interface.Shell; using System.Collections.Generic;
using Tomas.Common.Programs;
using Tomas.Interface;
using Tomas.Terminal.Programs;
namespace Tomas.Terminal namespace Tomas.Terminal
{ {
@ -9,6 +12,14 @@ namespace Tomas.Terminal
{ {
const char SYMBOL = '$'; 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 public string ReadLine
{ {
get get

View file

@ -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()}
};
}
}