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
|
@ -1,11 +1,11 @@
|
|||
using System;
|
||||
using Tomas.Interface.Shell;
|
||||
using Tomas.Interface;
|
||||
|
||||
namespace Tomas.Kernel.Programs
|
||||
namespace Tomas.Common.Programs
|
||||
{
|
||||
public class Clear : IProgram
|
||||
{
|
||||
public bool Start()
|
||||
public bool Run(IShell shell)
|
||||
{
|
||||
Console.Clear();
|
||||
return true;
|
||||
|
|
17
src/Tomas.Common/Programs/Commands.cs
Normal file
17
src/Tomas.Common/Programs/Commands.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,9 +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;
|
||||
|
||||
namespace Tomas.Kernel.Programs
|
||||
using System;
|
||||
using Tomas.Interface;
|
||||
|
||||
namespace Tomas.Common.Programs
|
||||
{
|
||||
public class FenSay : IProgram
|
||||
{
|
||||
|
@ -11,7 +12,7 @@ namespace Tomas.Kernel.Programs
|
|||
/// <summary>
|
||||
/// Fennec art by Todd Vargo
|
||||
/// </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.",
|
||||
"Drink Soda. It makes you see faster.",
|
||||
"10/10, Wouldn't Recommend."
|
||||
};
|
||||
|
||||
public bool Start()
|
||||
public bool Run(IShell shell)
|
||||
{
|
||||
var rng = new Random();
|
||||
var phrases = _fenPhrases[rng.Next(_fenPhrases.Length)];
|
||||
Console.WriteLine($"{phrases}{Environment.NewLine}{FENNEC}");
|
||||
var phrases = _phrases[rng.Next(_phrases.Length)];
|
||||
Console.WriteLine($"{phrases}{Environment.NewLine}{_fennec}");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
15
src/Tomas.Interface/IProgram.cs
Normal file
15
src/Tomas.Interface/IProgram.cs
Normal 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);
|
||||
}
|
||||
}
|
|
@ -1,9 +1,14 @@
|
|||
// 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
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Tomas.Interface
|
||||
{
|
||||
public interface IShell
|
||||
{
|
||||
string ReadLine { get; }
|
||||
|
||||
Dictionary<string, IProgram> Programs { get; }
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -3,9 +3,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Tomas.Common;
|
||||
using Tomas.Interface.Shell;
|
||||
using Tomas.Kernel.Programs;
|
||||
using Tomas.Terminal.Programs;
|
||||
using Sys = Cosmos.System;
|
||||
|
||||
namespace Tomas.Kernel
|
||||
|
@ -42,10 +39,22 @@ namespace Tomas.Kernel
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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()}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -1,19 +1,19 @@
|
|||
// 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.Common;
|
||||
using Tomas.Interface.Shell;
|
||||
using Tomas.Kernel;
|
||||
using Tomas.Interface;
|
||||
|
||||
namespace Tomas.Terminal.Programs
|
||||
namespace Tomas.Kernel.Programs
|
||||
{
|
||||
public class About : IProgram
|
||||
{
|
||||
public bool Start()
|
||||
public bool Run(IShell shell)
|
||||
{
|
||||
Console.WriteLine($"{ComConsts.NAME} v{ComConsts.VersionGit}");
|
||||
|
||||
var progs = OSConsts.Programs;
|
||||
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);
|
||||
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
// 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.Common;
|
||||
using Tomas.Interface.Shell;
|
||||
using System.Collections.Generic;
|
||||
using Tomas.Common.Programs;
|
||||
using Tomas.Interface;
|
||||
using Tomas.Kernel.Programs;
|
||||
using Sys = Cosmos.System;
|
||||
|
||||
|
@ -12,6 +13,14 @@ namespace Tomas.Kernel
|
|||
{
|
||||
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
|
||||
|
|
|
@ -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