diff --git a/.vs/ShiftOS/v15/sqlite3/storage.ide b/.vs/ShiftOS/v15/sqlite3/storage.ide
deleted file mode 100644
index 4ff5119..0000000
Binary files a/.vs/ShiftOS/v15/sqlite3/storage.ide and /dev/null differ
diff --git a/ShiftOS.Engine/ShiftOS.Engine.csproj b/ShiftOS.Engine/ShiftOS.Engine.csproj
index 0bb54c5..88ad0cf 100644
--- a/ShiftOS.Engine/ShiftOS.Engine.csproj
+++ b/ShiftOS.Engine/ShiftOS.Engine.csproj
@@ -69,9 +69,6 @@
-
-
-
UserControl
diff --git a/ShiftOS.Engine/Terminal/Commands/Hello.cs b/ShiftOS.Engine/Terminal/Commands/Hello.cs
deleted file mode 100644
index 7d4b82f..0000000
--- a/ShiftOS.Engine/Terminal/Commands/Hello.cs
+++ /dev/null
@@ -1,9 +0,0 @@
-namespace ShiftOS.Engine.Terminal.Commands
-{
- public class Hello : TerminalCommand
- {
- public override string GetName() => "Hello";
-
- public override string Run(params string[] parameters) => "Oh, HELLO, " + string.Join(" ", parameters);
- }
-}
\ No newline at end of file
diff --git a/ShiftOS.Engine/Terminal/TerminalBackend.cs b/ShiftOS.Engine/Terminal/TerminalBackend.cs
deleted file mode 100644
index 793b748..0000000
--- a/ShiftOS.Engine/Terminal/TerminalBackend.cs
+++ /dev/null
@@ -1,47 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
-
-namespace ShiftOS.Engine.Terminal
-{
- public static class TerminalBackend
- {
- // The line below gets all the terminal commands in... well... the entire ShiftOS.Engine
- static readonly IEnumerable Instances = from t in Assembly.GetExecutingAssembly().GetTypes()
- where t.IsSubclassOf(typeof(TerminalCommand)) &&
- t.GetConstructor(Type.EmptyTypes) != null
- select (TerminalCommand) Activator.CreateInstance(t);
-
- ///
- /// Runs a terminal command.
- ///
- ///
- /// Returns all the output from that command.
- 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 (var instance in Instances)
- {
- if (instance.GetName() == name)
- {
- return instance.Run(theParams);
- }
- }
-
- return "The command cannot be found.";
- }
- }
-}
\ No newline at end of file
diff --git a/ShiftOS.Engine/Terminal/TerminalCommand.cs b/ShiftOS.Engine/Terminal/TerminalCommand.cs
deleted file mode 100644
index 81a34b9..0000000
--- a/ShiftOS.Engine/Terminal/TerminalCommand.cs
+++ /dev/null
@@ -1,9 +0,0 @@
-namespace ShiftOS.Engine.Terminal
-{
- public abstract class TerminalCommand
- {
- public abstract string GetName();
-
- public abstract string Run(params string[] parameters);
- }
-}
\ No newline at end of file
diff --git a/ShiftOS.Main/ShiftOS.Main.csproj b/ShiftOS.Main/ShiftOS.Main.csproj
index 6f712cc..35d7761 100644
--- a/ShiftOS.Main/ShiftOS.Main.csproj
+++ b/ShiftOS.Main/ShiftOS.Main.csproj
@@ -99,6 +99,9 @@
Desktop.cs
+
+
+
ResXFileCodeGenerator
Resources.Designer.cs
diff --git a/ShiftOS.Main/ShiftOS/Apps/Terminal.Designer.cs b/ShiftOS.Main/ShiftOS/Apps/Terminal.Designer.cs
index e92cdb4..b514bbf 100644
--- a/ShiftOS.Main/ShiftOS/Apps/Terminal.Designer.cs
+++ b/ShiftOS.Main/ShiftOS/Apps/Terminal.Designer.cs
@@ -60,6 +60,6 @@
#endregion
- private System.Windows.Forms.RichTextBox termmain;
+ public System.Windows.Forms.RichTextBox termmain;
}
}
diff --git a/ShiftOS.Main/ShiftOS/Apps/Terminal.cs b/ShiftOS.Main/ShiftOS/Apps/Terminal.cs
index 4c11136..c65f705 100644
--- a/ShiftOS.Main/ShiftOS/Apps/Terminal.cs
+++ b/ShiftOS.Main/ShiftOS/Apps/Terminal.cs
@@ -1,14 +1,19 @@
using System;
using System.Windows.Forms;
-using ShiftOS.Engine.Terminal;
+using ShiftOS.Engine;
+using ShiftOS.Main.Terminal;
namespace ShiftOS.Main.ShiftOS.Apps
{
- public partial class Terminal : UserControl
- {
- public string DefaulttextBefore = "user> ";
- string DefaulttextResult = "user@shiftos> "; // NOT YET IMPLEMENTED!!!
- bool DoClear = false;
+ public partial class Terminal : UserControl
+ {
+ public int TerminalID = TerminalBackend.trmTopID++; // Used so that we can have multiple instances of the terminal whilst the command begin run knowing what terminal to send the text to - very complicated ;)
+ public string defaulttextBefore = "user> ";
+ public string defaulttextResult = "user@shiftos> "; // NOT YET IMPLEMENTED!!!
+ public bool DoClear = false;
+ public bool RunningCommand = false;
+ public bool WaitingResponse = false;
+ public string InputReturnText = "";
// The below variables makes the terminal... a terminal!
string OldText = "";
@@ -20,13 +25,91 @@ namespace ShiftOS.Main.ShiftOS.Apps
InitializeComponent();
termmain.ContextMenuStrip = new ContextMenuStrip(); // Disables the right click of a richtextbox!
- }
- void Print(string text)
+ TerminalBackend.trm.Add(this);
+ }
+
+ void Print()
+ {
+ termmain.AppendText($"\n {defaulttextResult}");
+ TrackingPosition = termmain.Text.Length;
+ }
+
+ void Print(string text)
{
- termmain.AppendText($"\n {text} \n {DefaulttextResult}");
+ termmain.AppendText($"\n {text} \n {defaulttextResult}");
TrackingPosition = termmain.Text.Length;
- }
+ }
+
+ //if (e.Control && e.KeyCode == Keys.V)
+ // {
+ // //if (Clipboard.ContainsText())
+ // // termmain.Paste(DataFormats.GetFormat(DataFormats.Text));
+ // e.Handled = true;
+ // } else if (e.KeyCode == Keys.Enter) {
+ // RunningCommand = true;
+ // TerminalBackend.RunCommand(termmain.Text.Substring(TrackingPosition, termmain.Text.Length - TrackingPosition), TerminalID); // The most horrific line in the entire application!
+ // RunningCommand = false;
+ // termmain.AppendText($"\n {defaulttextResult}");
+ // TrackingPosition = termmain.Text.Length;
+ // e.Handled = true;
+ // }
+ //}
+
+ private void termmain_TextChanged(object sender, EventArgs e)
+ {
+ if (!RunningCommand)
+ {
+ if (termmain.SelectionStart < TrackingPosition)
+ {
+ if (!DoClear) // If it's not clearing the terminal
+ {
+ termmain.Text = OldText;
+ termmain.Select(termmain.Text.Length, 0);
+ }
+ }
+ else
+ {
+ OldText = termmain.Text;
+ }
+ }
+ }
+
+ private void termmain_SelectionChanged(object sender, EventArgs e)
+ {
+ if (!RunningCommand)
+ {
+ if (termmain.SelectionStart < TrackingPosition)
+ {
+ termmain.Text = OldText;
+ termmain.Select(termmain.Text.Length, 0);
+ }
+ }
+ }
+
+ private void Terminal_Load(object sender, EventArgs e)
+ {
+ termmain.Text = $"\n {defaulttextResult}";
+ TrackingPosition = termmain.Text.Length;
+ termmain.Select(termmain.TextLength, 1);
+ }
+
+ public void Input(string request)
+ {
+ InputReturnText = "";
+ RunningCommand = false;
+
+ termmain.AppendText($"\n {request} ");
+ TrackingPosition = termmain.Text.Length;
+ }
+
+ public void Clear()
+ {
+ DoClear = true;
+ termmain.Text = $"\n {defaulttextResult}";
+ TrackingPosition = termmain.Text.Length;
+ DoClear = false;
+ }
void termmain_KeyDown(object sender, KeyEventArgs e)
{
@@ -40,41 +123,10 @@ namespace ShiftOS.Main.ShiftOS.Apps
}
else if (e.KeyCode == Keys.Enter)
{
- Print(
- TerminalBackend.RunCommand(
- termmain.Text.Substring(
- TrackingPosition,
- termmain.Text.Length - TrackingPosition))); // The most horrific line in the entire application!
+ TerminalBackend.RunCommand(termmain.Text.Substring(TrackingPosition, termmain.Text.Length - TrackingPosition), TerminalID); // The most horrific line in the entire application!
+ Print();
e.Handled = true;
}
}
-
- void termmain_TextChanged(object sender, EventArgs e)
- {
- if (termmain.SelectionStart < TrackingPosition)
- {
- if (DoClear) return;
-
- termmain.Text = OldText;
- termmain.Select(termmain.Text.Length, 0);
- }
- else
- {
- OldText = termmain.Text;
- }
- }
-
- void termmain_SelectionChanged(object sender, EventArgs e)
- {
- if (termmain.SelectionStart >= TrackingPosition) return;
-
- termmain.Text = OldText;
- termmain.Select(termmain.Text.Length, 0);
- }
-
- void Terminal_Load(object sender, EventArgs e)
- {
- Print("\n");
- }
}
-}
\ No newline at end of file
+}
diff --git a/ShiftOS.Main/ShiftOS/Desktop.cs b/ShiftOS.Main/ShiftOS/Desktop.cs
index 95e4d26..4bf4805 100644
--- a/ShiftOS.Main/ShiftOS/Desktop.cs
+++ b/ShiftOS.Main/ShiftOS/Desktop.cs
@@ -54,11 +54,12 @@ namespace ShiftOS.Main.ShiftOS
void timer1_Tick(object sender, EventArgs e) =>
taskbarClock.Text = $"{DateTime.Now:t}";
- void terminalToolStripMenuItem_Click(object sender, EventArgs e)
- {
- var trm = new Terminal();
- ShiftWM.Init(trm, "Terminal", null);
- }
+ private void terminalToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ Apps.Terminal trm = new Apps.Terminal();
+
+ ShiftWM.Init(trm, "Terminal", null, false, true);
+ }
void textPadToolStripMenuItem_Click(object sender, EventArgs e)
{
@@ -72,4 +73,4 @@ namespace ShiftOS.Main.ShiftOS
ShiftWM.Init(fs, "File Skimmer", Resources.iconFileSkimmer);
}
}
-}
\ No newline at end of file
+}
diff --git a/ShiftOS.Main/Terminal/Commands/Hello.cs b/ShiftOS.Main/Terminal/Commands/Hello.cs
new file mode 100644
index 0000000..a826532
--- /dev/null
+++ b/ShiftOS.Main/Terminal/Commands/Hello.cs
@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ShiftOS.Main.Terminal.Commands
+{
+ public class Hello : TerminalCommand
+ {
+ public override string Name { get; } = "Hello";
+ public override string Summary { get; } = "Just an example command.";
+ public override string Usage { get; } = "Hello .";
+ public override bool Unlocked { get; set; } = false;
+
+ public override void Run(params string[] parameters)
+ {
+ string name = string.Join(" ", parameters);
+ WriteLine($"Oh, hello, {name}.");
+ }
+ }
+}
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 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 trm = new List();
+ public static int trmTopID = 0;
+ ///
+ /// Runs a terminal command.
+ ///
+ ///
+ /// The rich text box that the text will be written to.
+ 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";
+ }
+ }
+}
diff --git a/ShiftOS.Main/Terminal/TerminalCommand.cs b/ShiftOS.Main/Terminal/TerminalCommand.cs
new file mode 100644
index 0000000..5f313be
--- /dev/null
+++ b/ShiftOS.Main/Terminal/TerminalCommand.cs
@@ -0,0 +1,92 @@
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace ShiftOS.Main.Terminal
+{
+ public class TerminalCommand
+ {
+ public int TermID { get; set; }
+
+ public virtual string Name { get; }
+ public virtual string Summary { get; }
+ public virtual string Usage { get; }
+ public virtual bool Unlocked { get; set; }
+
+ public virtual void Run(params string[] parameters) { }
+
+ ///
+ /// Writes a blank line in the terminal.
+ ///
+ public virtual void WriteLine()
+ {
+ WriteLine("");
+ }
+
+ ///
+ /// Writes specified text in the terminal and starts a new line.
+ ///
+ /// The text to write before the new line is made.
+ public virtual void WriteLine(string value)
+ {
+ Array.Find(TerminalBackend.trm.ToArray(), w => w.TerminalID == TermID).termmain.AppendText($"{value} \n");
+ }
+
+ ///
+ /// Writes specified text in the terminal in the specified color and starts a new line.
+ ///
+ /// The text to write before the new line is made.
+ /// The color the text is written in.
+ public virtual void WriteLine(string value, Color textClr)
+ {
+ ShiftOS.Apps.Terminal trm = Array.Find(TerminalBackend.trm.ToArray(), w => w.TerminalID == TermID);
+
+ int startPoint = trm.termmain.Text.Length;
+ trm.termmain.AppendText($"{value} \n");
+ trm.termmain.Select(startPoint, $"{value} \n".Length);
+ trm.termmain.SelectionColor = textClr;
+ }
+
+ ///
+ /// Writes specified text in the terminal.
+ ///
+ /// The text to write.
+ /// The color the text is written in.
+ public virtual void Write(string value, Color textClr)
+ {
+
+ ShiftOS.Apps.Terminal trm = Array.Find(TerminalBackend.trm.ToArray(), w => w.TerminalID == TermID);
+
+ int startPoint = trm.termmain.Text.Length;
+ trm.termmain.AppendText($"{value}");
+ trm.termmain.Select(startPoint, $"{value}".Length);
+ trm.termmain.SelectionColor = textClr;
+ }
+
+ ///
+ /// Writes specified text in the terminal.
+ ///
+ /// The text to say before requesting text.
+ //public virtual Task Input(string value = "")
+ //{
+ // ShiftOS.Apps.Terminal trm = Array.Find(TerminalBackend.trm.ToArray(), w => w.TerminalID == TermID);
+ // trm.Input(value);
+
+ // Task Input = new Task(() =>
+ // {
+ // while (true)
+ // if (trm.InputReturnText != "") break;
+
+ // // The terminal has finally decided!
+
+ // return trm.InputReturnText;
+ // });
+ // Input.Start();
+ // return Input;
+ //}
+ }
+}