From 7efdde5832b517153363621aaec982211ff25f61 Mon Sep 17 00:00:00 2001 From: Alex-TIMEHACK Date: Sun, 15 Oct 2017 17:01:17 +0100 Subject: Tiny change - github bugging out --- ShiftOS.Engine/Terminal/TerminalCommand.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ShiftOS.Engine/Terminal/TerminalCommand.cs b/ShiftOS.Engine/Terminal/TerminalCommand.cs index a344122..b5dd8bf 100644 --- a/ShiftOS.Engine/Terminal/TerminalCommand.cs +++ b/ShiftOS.Engine/Terminal/TerminalCommand.cs @@ -6,10 +6,14 @@ using System.Threading.Tasks; namespace ShiftOS.Engine.Terminal { - public abstract class TerminalCommand + public class TerminalCommand { - public abstract string GetName(); + public string GetName() { return ""; } - public abstract string Run(params string[] parameters); + public void Run(params string[] parameters) { return ""; } + + public void Run(params string[] parameters) { + + } } } -- cgit v1.2.3 From b2f7322f3072ff90c8e6039ec4b3219d3c3fb919 Mon Sep 17 00:00:00 2001 From: Alex-TIMEHACK Date: Sun, 15 Oct 2017 20:25:37 +0100 Subject: It's broken. --- ShiftOS.Engine/ShiftOS.Engine.csproj | 3 - ShiftOS.Engine/Terminal/Commands/Hello.cs | 21 ------ ShiftOS.Engine/Terminal/TerminalBackend.cs | 46 ------------- ShiftOS.Engine/Terminal/TerminalCommand.cs | 19 ------ ShiftOS.Main/ShiftOS.Main.csproj | 3 + ShiftOS.Main/ShiftOS/Apps/Terminal.Designer.cs | 2 +- ShiftOS.Main/ShiftOS/Apps/Terminal.cs | 72 ++++++++++++-------- ShiftOS.Main/ShiftOS/Desktop.cs | 2 +- ShiftOS.Main/Terminal/Commands/Hello.cs | 25 +++++++ ShiftOS.Main/Terminal/TerminalBackend.cs | 49 ++++++++++++++ ShiftOS.Main/Terminal/TerminalCommand.cs | 92 ++++++++++++++++++++++++++ 11 files changed, 215 insertions(+), 119 deletions(-) delete mode 100644 ShiftOS.Engine/Terminal/Commands/Hello.cs delete mode 100644 ShiftOS.Engine/Terminal/TerminalBackend.cs delete mode 100644 ShiftOS.Engine/Terminal/TerminalCommand.cs create mode 100644 ShiftOS.Main/Terminal/Commands/Hello.cs create mode 100644 ShiftOS.Main/Terminal/TerminalBackend.cs create mode 100644 ShiftOS.Main/Terminal/TerminalCommand.cs diff --git a/ShiftOS.Engine/ShiftOS.Engine.csproj b/ShiftOS.Engine/ShiftOS.Engine.csproj index 6740db1..8d3d003 100644 --- a/ShiftOS.Engine/ShiftOS.Engine.csproj +++ b/ShiftOS.Engine/ShiftOS.Engine.csproj @@ -52,9 +52,6 @@ True Resources.resx - - - UserControl diff --git a/ShiftOS.Engine/Terminal/Commands/Hello.cs b/ShiftOS.Engine/Terminal/Commands/Hello.cs deleted file mode 100644 index 531bd1f..0000000 --- a/ShiftOS.Engine/Terminal/Commands/Hello.cs +++ /dev/null @@ -1,21 +0,0 @@ -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 deleted file mode 100644 index 7103238..0000000 --- a/ShiftOS.Engine/Terminal/TerminalBackend.cs +++ /dev/null @@ -1,46 +0,0 @@ -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 instances = from t in Assembly.GetExecutingAssembly().GetTypes() - where t.IsSubclassOf(typeof(TerminalCommand)) - && t.GetConstructor(Type.EmptyTypes) != null - select Activator.CreateInstance(t) as TerminalCommand; - - /// - /// 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 (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 deleted file mode 100644 index b5dd8bf..0000000 --- a/ShiftOS.Engine/Terminal/TerminalCommand.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ShiftOS.Engine.Terminal -{ - public class TerminalCommand - { - public string GetName() { return ""; } - - public void Run(params string[] parameters) { return ""; } - - public void Run(params string[] parameters) { - - } - } -} diff --git a/ShiftOS.Main/ShiftOS.Main.csproj b/ShiftOS.Main/ShiftOS.Main.csproj index 7c19b38..b2e9739 100644 --- a/ShiftOS.Main/ShiftOS.Main.csproj +++ b/ShiftOS.Main/ShiftOS.Main.csproj @@ -88,6 +88,9 @@ Desktop.cs + + + HijackScreen.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 a9bd093..1bd5c03 100644 --- a/ShiftOS.Main/ShiftOS/Apps/Terminal.cs +++ b/ShiftOS.Main/ShiftOS/Apps/Terminal.cs @@ -8,15 +8,19 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using ShiftOS.Engine; -using ShiftOS.Engine.Terminal; +using ShiftOS.Main.Terminal; namespace ShiftOS.Main.ShiftOS.Apps { 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 DoClear = false; + public bool RunningCommand = false; + public bool WaitingResponse = false; + public string InputReturnText = ""; // The below variables makes the terminal... a terminal! public string OldText = ""; @@ -27,12 +31,8 @@ namespace ShiftOS.Main.ShiftOS.Apps InitializeComponent(); termmain.ContextMenuStrip = new ContextMenuStrip(); // Disables the right click of a richtextbox! - } - public void Print(string text) - { - termmain.AppendText($"\n {text} \n {defaulttextResult}"); - TrackingPosition = termmain.Text.Length; + TerminalBackend.trm.Add(this); // Makes the commands run! } private void termmain_KeyDown(object sender, KeyEventArgs e) @@ -45,51 +45,67 @@ namespace ShiftOS.Main.ShiftOS.Apps // termmain.Paste(DataFormats.GetFormat(DataFormats.Text)); e.Handled = true; } 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! + 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 (termmain.SelectionStart < TrackingPosition) + if (!RunningCommand) { - if (doClear == false) // If it's not clearing the terminal + if (termmain.SelectionStart < TrackingPosition) { - termmain.Text = OldText; - termmain.Select(termmain.Text.Length, 0); + if (!DoClear) // If it's not clearing the terminal + { + termmain.Text = OldText; + termmain.Select(termmain.Text.Length, 0); + } + } + else + { + OldText = termmain.Text; } - } - else - { - OldText = termmain.Text; } } private void termmain_SelectionChanged(object sender, EventArgs e) { - if (termmain.SelectionStart < TrackingPosition) + if (!RunningCommand) { - termmain.Text = OldText; - termmain.Select(termmain.Text.Length, 0); + if (termmain.SelectionStart < TrackingPosition) + { + termmain.Text = OldText; + termmain.Select(termmain.Text.Length, 0); + } } } private void Terminal_Load(object sender, EventArgs e) { - Print("\n"); + termmain.Text = $"\n {defaulttextResult}"; + TrackingPosition = termmain.Text.Length; } - public string RunCommand(string command) + public void Input(string request) { - string ToReturn = ""; + InputReturnText = ""; + RunningCommand = false; - if (command == "hi") - { - ToReturn = $"{ToReturn} \n Hi!"; - MessageBox.Show("HI!"); - } - return ToReturn; + termmain.AppendText($"\n {request} "); + TrackingPosition = termmain.Text.Length; + } + + public void Clear() + { + DoClear = true; + termmain.Text = $"\n {defaulttextResult}"; + TrackingPosition = termmain.Text.Length; + DoClear = false; } } } diff --git a/ShiftOS.Main/ShiftOS/Desktop.cs b/ShiftOS.Main/ShiftOS/Desktop.cs index 06f1fc8..3477788 100644 --- a/ShiftOS.Main/ShiftOS/Desktop.cs +++ b/ShiftOS.Main/ShiftOS/Desktop.cs @@ -61,7 +61,7 @@ namespace ShiftOS.Main.ShiftOS private void terminalToolStripMenuItem_Click(object sender, EventArgs e) { Apps.Terminal trm = new Apps.Terminal(); - + ShiftWM.Init(trm, "Terminal", null, false, true); } } diff --git a/ShiftOS.Main/Terminal/Commands/Hello.cs b/ShiftOS.Main/Terminal/Commands/Hello.cs new file mode 100644 index 0000000..efc9a9a --- /dev/null +++ b/ShiftOS.Main/Terminal/Commands/Hello.cs @@ -0,0 +1,25 @@ +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 async void Run(params string[] parameters) + { + string name = string.Join(" ", parameters); + WriteLine($"Oh, hello, {name}.", Color.Red); + string age = await Input("Hey, What's your age?"); + WriteLine($"Ok, so your name is {name} and your age {age}."); + } + } +} diff --git a/ShiftOS.Main/Terminal/TerminalBackend.cs b/ShiftOS.Main/Terminal/TerminalBackend.cs new file mode 100644 index 0000000..9a5785f --- /dev/null +++ b/ShiftOS.Main/Terminal/TerminalBackend.cs @@ -0,0 +1,49 @@ +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 = from t in Assembly.GetExecutingAssembly().GetTypes() + where t.IsSubclassOf(typeof(TerminalCommand)) + && t.GetConstructor(Type.EmptyTypes) != null + select 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..4746e6c --- /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; + } + } +} -- cgit v1.2.3 From 65b7ac2b8cbc4478f6d31a21f106048aeb075078 Mon Sep 17 00:00:00 2001 From: Alex-TIMEHACK Date: Sat, 18 Nov 2017 16:09:54 +0000 Subject: Removed Input() stuff! --- ShiftOS.Main/Terminal/Commands/Hello.cs | 6 ++---- ShiftOS.Main/Terminal/TerminalBackend.cs | 7 +++---- ShiftOS.Main/Terminal/TerminalCommand.cs | 28 ++++++++++++++-------------- 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/ShiftOS.Main/Terminal/Commands/Hello.cs b/ShiftOS.Main/Terminal/Commands/Hello.cs index efc9a9a..a826532 100644 --- a/ShiftOS.Main/Terminal/Commands/Hello.cs +++ b/ShiftOS.Main/Terminal/Commands/Hello.cs @@ -14,12 +14,10 @@ namespace ShiftOS.Main.Terminal.Commands public override string Usage { get; } = "Hello ."; public override bool Unlocked { get; set; } = false; - public override async void Run(params string[] parameters) + public override void Run(params string[] parameters) { string name = string.Join(" ", parameters); - WriteLine($"Oh, hello, {name}.", Color.Red); - string age = await Input("Hey, What's your age?"); - WriteLine($"Ok, so your name is {name} and your age {age}."); + WriteLine($"Oh, hello, {name}."); } } } diff --git a/ShiftOS.Main/Terminal/TerminalBackend.cs b/ShiftOS.Main/Terminal/TerminalBackend.cs index 9a5785f..02c9cd0 100644 --- a/ShiftOS.Main/Terminal/TerminalBackend.cs +++ b/ShiftOS.Main/Terminal/TerminalBackend.cs @@ -11,10 +11,9 @@ 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 = from t in Assembly.GetExecutingAssembly().GetTypes() - where t.IsSubclassOf(typeof(TerminalCommand)) - && t.GetConstructor(Type.EmptyTypes) != null - select Activator.CreateInstance(t) as TerminalCommand; + 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; diff --git a/ShiftOS.Main/Terminal/TerminalCommand.cs b/ShiftOS.Main/Terminal/TerminalCommand.cs index 4746e6c..5f313be 100644 --- a/ShiftOS.Main/Terminal/TerminalCommand.cs +++ b/ShiftOS.Main/Terminal/TerminalCommand.cs @@ -71,22 +71,22 @@ namespace ShiftOS.Main.Terminal /// 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); + //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; + // Task Input = new Task(() => + // { + // while (true) + // if (trm.InputReturnText != "") break; - // The terminal has finally decided! + // // The terminal has finally decided! - return trm.InputReturnText; - }); - Input.Start(); - return Input; - } + // return trm.InputReturnText; + // }); + // Input.Start(); + // return Input; + //} } } -- cgit v1.2.3 From 6faabfbbd86d70c99e197a3d8cfcf7db0680d17f Mon Sep 17 00:00:00 2001 From: Alex-TIMEHACK Date: Sat, 18 Nov 2017 16:33:30 +0000 Subject: Fixed fork? --- ShiftOS.Engine/ShiftOS.Engine.csproj | 3 - ShiftOS.Engine/Terminal/Commands/Hello.cs | 9 -- ShiftOS.Engine/Terminal/TerminalBackend.cs | 46 -------- ShiftOS.Engine/Terminal/TerminalCommand.cs | 182 ----------------------------- 4 files changed, 240 deletions(-) delete mode 100644 ShiftOS.Engine/Terminal/Commands/Hello.cs delete mode 100644 ShiftOS.Engine/Terminal/TerminalBackend.cs delete mode 100644 ShiftOS.Engine/Terminal/TerminalCommand.cs diff --git a/ShiftOS.Engine/ShiftOS.Engine.csproj b/ShiftOS.Engine/ShiftOS.Engine.csproj index 218daf4..6b810fa 100644 --- a/ShiftOS.Engine/ShiftOS.Engine.csproj +++ b/ShiftOS.Engine/ShiftOS.Engine.csproj @@ -70,9 +70,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 e079d22..0000000 --- a/ShiftOS.Engine/Terminal/TerminalBackend.cs +++ /dev/null @@ -1,46 +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 - 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); - - /// - /// 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 110d1d2..0000000 --- a/ShiftOS.Engine/Terminal/TerminalCommand.cs +++ /dev/null @@ -1,182 +0,0 @@ -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; - - } - - } - -} \ No newline at end of file -- cgit v1.2.3 From 179ec19e6b49dd6c0f5de5dc6f69128338a28e12 Mon Sep 17 00:00:00 2001 From: Alex-TIMEHACK Date: Sat, 18 Nov 2017 16:46:45 +0000 Subject: I don't know WHAT git did but I fixed it. --- .vs/ShiftOS/v15/sqlite3/storage.ide | Bin 1413120 -> 1622016 bytes ShiftOS.Engine/ShiftOS.Engine.csproj | 1 - ShiftOS.Main/ShiftOS.Main.csproj | 3 -- ShiftOS.Main/ShiftOS/Apps/Terminal.cs | 94 +++++++++++----------------------- ShiftOS.Main/ShiftOS/Desktop.cs | 7 --- 5 files changed, 29 insertions(+), 76 deletions(-) diff --git a/.vs/ShiftOS/v15/sqlite3/storage.ide b/.vs/ShiftOS/v15/sqlite3/storage.ide index 4ff5119..1ddce4d 100644 Binary files a/.vs/ShiftOS/v15/sqlite3/storage.ide and b/.vs/ShiftOS/v15/sqlite3/storage.ide differ diff --git a/ShiftOS.Engine/ShiftOS.Engine.csproj b/ShiftOS.Engine/ShiftOS.Engine.csproj index 6b810fa..88ad0cf 100644 --- a/ShiftOS.Engine/ShiftOS.Engine.csproj +++ b/ShiftOS.Engine/ShiftOS.Engine.csproj @@ -63,7 +63,6 @@ True Resources.resx - diff --git a/ShiftOS.Main/ShiftOS.Main.csproj b/ShiftOS.Main/ShiftOS.Main.csproj index f7d8dc0..35d7761 100644 --- a/ShiftOS.Main/ShiftOS.Main.csproj +++ b/ShiftOS.Main/ShiftOS.Main.csproj @@ -102,9 +102,6 @@ - - HijackScreen.cs - ResXFileCodeGenerator Resources.Designer.cs diff --git a/ShiftOS.Main/ShiftOS/Apps/Terminal.cs b/ShiftOS.Main/ShiftOS/Apps/Terminal.cs index a5c5a11..5976cab 100644 --- a/ShiftOS.Main/ShiftOS/Apps/Terminal.cs +++ b/ShiftOS.Main/ShiftOS/Apps/Terminal.cs @@ -14,52 +14,48 @@ namespace ShiftOS.Main.ShiftOS.Apps public bool RunningCommand = false; public bool WaitingResponse = false; public string InputReturnText = ""; -using ShiftOS.Engine.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; // The below variables makes the terminal... a terminal! string OldText = ""; int TrackingPosition; - termmain.ContextMenuStrip = new ContextMenuStrip(); // Disables the right click of a richtextbox! - - TerminalBackend.trm.Add(this); // Makes the commands run! - } public Terminal() { 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; - } } + //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) @@ -113,8 +109,7 @@ namespace ShiftOS.Main.ShiftOS.Apps TrackingPosition = termmain.Text.Length; DoClear = false; } - } -} + void termmain_KeyDown(object sender, KeyEventArgs e) { // The below code disables the ability to paste anything other then text... @@ -127,41 +122,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"); - } } } diff --git a/ShiftOS.Main/ShiftOS/Desktop.cs b/ShiftOS.Main/ShiftOS/Desktop.cs index 10eea41..4bf4805 100644 --- a/ShiftOS.Main/ShiftOS/Desktop.cs +++ b/ShiftOS.Main/ShiftOS/Desktop.cs @@ -60,13 +60,6 @@ namespace ShiftOS.Main.ShiftOS ShiftWM.Init(trm, "Terminal", null, false, true); } - } -} - void terminalToolStripMenuItem_Click(object sender, EventArgs e) - { - var trm = new Terminal(); - ShiftWM.Init(trm, "Terminal", null); - } void textPadToolStripMenuItem_Click(object sender, EventArgs e) { -- cgit v1.2.3 From c0400bc229d5f275955d6c964108deebf0908b4b Mon Sep 17 00:00:00 2001 From: Alex-TIMEHACK Date: Sat, 18 Nov 2017 16:48:19 +0000 Subject: Fixed tiny caret issue. --- ShiftOS.Main/ShiftOS/Apps/Terminal.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/ShiftOS.Main/ShiftOS/Apps/Terminal.cs b/ShiftOS.Main/ShiftOS/Apps/Terminal.cs index 5976cab..c65f705 100644 --- a/ShiftOS.Main/ShiftOS/Apps/Terminal.cs +++ b/ShiftOS.Main/ShiftOS/Apps/Terminal.cs @@ -91,6 +91,7 @@ namespace ShiftOS.Main.ShiftOS.Apps { termmain.Text = $"\n {defaulttextResult}"; TrackingPosition = termmain.Text.Length; + termmain.Select(termmain.TextLength, 1); } public void Input(string request) -- cgit v1.2.3 From cc734557de877186c5f5eb1e59efdcb785ac37a8 Mon Sep 17 00:00:00 2001 From: jtsshieh Date: Sat, 18 Nov 2017 12:00:19 -0500 Subject: Delete storage.ide --- .vs/ShiftOS/v15/sqlite3/storage.ide | Bin 1622016 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .vs/ShiftOS/v15/sqlite3/storage.ide diff --git a/.vs/ShiftOS/v15/sqlite3/storage.ide b/.vs/ShiftOS/v15/sqlite3/storage.ide deleted file mode 100644 index 1ddce4d..0000000 Binary files a/.vs/ShiftOS/v15/sqlite3/storage.ide and /dev/null differ -- cgit v1.2.3