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.Main/Terminal/TerminalCommand.cs | 92 ++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 ShiftOS.Main/Terminal/TerminalCommand.cs (limited to 'ShiftOS.Main/Terminal/TerminalCommand.cs') 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(-) (limited to 'ShiftOS.Main/Terminal/TerminalCommand.cs') 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