aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.Main/Terminal/TerminalBackend.cs
diff options
context:
space:
mode:
authorAShifter <[email protected]>2017-11-18 10:04:42 -0700
committerAShifter <[email protected]>2017-11-18 10:04:42 -0700
commitb4a8a646b1d0c67414a0e1eeedcf9442739fd990 (patch)
tree92c92907a420f2bb97719f4fd6c19ac72e283b8d /ShiftOS.Main/Terminal/TerminalBackend.cs
parentebdc09fe679b4b06fd149c8fc6539244100ce896 (diff)
parentcc734557de877186c5f5eb1e59efdcb785ac37a8 (diff)
downloadshiftos-rewind-b4a8a646b1d0c67414a0e1eeedcf9442739fd990.tar.gz
shiftos-rewind-b4a8a646b1d0c67414a0e1eeedcf9442739fd990.tar.bz2
shiftos-rewind-b4a8a646b1d0c67414a0e1eeedcf9442739fd990.zip
Merge remote-tracking branch 'refs/remotes/ShiftOS-Rewind/master'
Diffstat (limited to 'ShiftOS.Main/Terminal/TerminalBackend.cs')
-rw-r--r--ShiftOS.Main/Terminal/TerminalBackend.cs48
1 files changed, 48 insertions, 0 deletions
diff --git a/ShiftOS.Main/Terminal/TerminalBackend.cs b/ShiftOS.Main/Terminal/TerminalBackend.cs
new file mode 100644
index 0000000..02c9cd0
--- /dev/null
+++ b/ShiftOS.Main/Terminal/TerminalBackend.cs
@@ -0,0 +1,48 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace ShiftOS.Main.Terminal
+{
+ public static class TerminalBackend
+ {
+ // The line below gets all the terminal commands in... well... the entire ShiftOS.Engine
+ public static IEnumerable<TerminalCommand> instances = Assembly.GetExecutingAssembly().GetTypes()
+ .Where(t => t.IsSubclassOf(typeof(TerminalCommand)) && t.GetConstructor(Type.EmptyTypes) != null)
+ .Select(t => Activator.CreateInstance(t) as TerminalCommand);
+
+ public static List<ShiftOS.Apps.Terminal> trm = new List<ShiftOS.Apps.Terminal>();
+ public static int trmTopID = 0;
+ /// <summary>
+ /// Runs a terminal command.
+ /// </summary>
+ /// <param name="command"></param>
+ /// <param name="rtb"><summary>The rich text box that the text will be written to.</summary></param>
+ public static void RunCommand(string command, int TermID)
+ {
+ 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.Name.ToLower() == name.ToLower())
+ {
+ instance.TermID = TermID;
+ // Add a new line!
+ Array.Find(trm.ToArray(), w => w.TerminalID == TermID).termmain.AppendText("\n");
+ instance.Run(theParams);
+ return;
+ }
+ }
+
+ Array.Find(trm.ToArray(), w => w.TerminalID == TermID).termmain.Text += " \n The command cannot be found. \n";
+ }
+ }
+}