aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.Engine/Terminal
diff options
context:
space:
mode:
authorIBMPCDOS5 <[email protected]>2017-10-14 13:44:48 -0500
committerGitHub <[email protected]>2017-10-14 13:44:48 -0500
commitb0fb6ed50e8108b4c5f4ef8614368664e79d4426 (patch)
treea99eba02a00fe5c0d9dd445cc5f82100a40ead9f /ShiftOS.Engine/Terminal
parentdb714a32b91ae577f256347c71137a7a41dfca37 (diff)
parent9952cfd7eb666e04de3b51d1e7dbade8d9168b11 (diff)
downloadshiftos-rewind-b0fb6ed50e8108b4c5f4ef8614368664e79d4426.tar.gz
shiftos-rewind-b0fb6ed50e8108b4c5f4ef8614368664e79d4426.tar.bz2
shiftos-rewind-b0fb6ed50e8108b4c5f4ef8614368664e79d4426.zip
Merge pull request #10 from Alex-TIMEHACK/master
Terminal. With a little example command.
Diffstat (limited to 'ShiftOS.Engine/Terminal')
-rw-r--r--ShiftOS.Engine/Terminal/Commands/Hello.cs21
-rw-r--r--ShiftOS.Engine/Terminal/TerminalBackend.cs46
-rw-r--r--ShiftOS.Engine/Terminal/TerminalCommand.cs15
3 files changed, 82 insertions, 0 deletions
diff --git a/ShiftOS.Engine/Terminal/Commands/Hello.cs b/ShiftOS.Engine/Terminal/Commands/Hello.cs
new file mode 100644
index 0000000..531bd1f
--- /dev/null
+++ b/ShiftOS.Engine/Terminal/Commands/Hello.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ShiftOS.Engine.Terminal.Commands
+{
+ public class Hello : TerminalCommand
+ {
+ public override string GetName()
+ {
+ return "Hello";
+ }
+
+ public override string Run(params string[] parameters)
+ {
+ return "Oh, HELLO, " + String.Join(" ", parameters);
+ }
+ }
+}
diff --git a/ShiftOS.Engine/Terminal/TerminalBackend.cs b/ShiftOS.Engine/Terminal/TerminalBackend.cs
new file mode 100644
index 0000000..7103238
--- /dev/null
+++ b/ShiftOS.Engine/Terminal/TerminalBackend.cs
@@ -0,0 +1,46 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ShiftOS.Engine.Terminal
+{
+ public static class TerminalBackend
+ {
+ // The line below gets all the terminal commands in... well... the entire ShiftOS.Engine
+ public static IEnumerable<TerminalCommand> instances = from t in Assembly.GetExecutingAssembly().GetTypes()
+ where t.IsSubclassOf(typeof(TerminalCommand))
+ && t.GetConstructor(Type.EmptyTypes) != null
+ select Activator.CreateInstance(t) as TerminalCommand;
+
+ /// <summary>
+ /// Runs a terminal command.
+ /// </summary>
+ /// <param name="command"></param>
+ /// <returns>Returns all the output from that command.</returns>
+ public static string RunCommand(string command)
+ {
+ string name;
+ try { name = command.Split(' ')[0]; } catch { name = command; }
+
+ var theParams = new string[command.Split(' ').Length - 1];
+ Array.Copy(command.Split(' '), 1, theParams, 0, command.Split(' ').Length - 1);
+
+ foreach (TerminalCommand instance in instances)
+ {
+ if (instance.GetName() == name)
+ return instance.Run(theParams);
+ }
+
+ return "The command cannot be found.";
+ }
+
+ // An extra function ;)
+ private static Type[] GetTypesInNamespace(Assembly assembly, string nameSpace)
+ {
+ return assembly.GetTypes().Where(t => String.Equals(t.Namespace, nameSpace, StringComparison.Ordinal)).ToArray();
+ }
+ }
+}
diff --git a/ShiftOS.Engine/Terminal/TerminalCommand.cs b/ShiftOS.Engine/Terminal/TerminalCommand.cs
new file mode 100644
index 0000000..a344122
--- /dev/null
+++ b/ShiftOS.Engine/Terminal/TerminalCommand.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ShiftOS.Engine.Terminal
+{
+ public abstract class TerminalCommand
+ {
+ public abstract string GetName();
+
+ public abstract string Run(params string[] parameters);
+ }
+}