diff options
| author | jtsshieh <[email protected]> | 2017-11-18 11:56:23 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2017-11-18 11:56:23 -0500 |
| commit | ce700260e681f483e8e7120619f690da2d8847a6 (patch) | |
| tree | 6897964ac67014fd497ee4f8c29c0ba1742ba5d5 /ShiftOS.Main/Terminal/TerminalCommand.cs | |
| parent | 97722fbe9d474adffbba0b92e9727c48a8205234 (diff) | |
| parent | c0400bc229d5f275955d6c964108deebf0908b4b (diff) | |
| download | shiftos-rewind-ce700260e681f483e8e7120619f690da2d8847a6.tar.gz shiftos-rewind-ce700260e681f483e8e7120619f690da2d8847a6.tar.bz2 shiftos-rewind-ce700260e681f483e8e7120619f690da2d8847a6.zip | |
Merge pull request #15 from Alex-TIMEHACK/master
Fully working command handler (Alex)
Diffstat (limited to 'ShiftOS.Main/Terminal/TerminalCommand.cs')
| -rw-r--r-- | ShiftOS.Main/Terminal/TerminalCommand.cs | 92 |
1 files changed, 92 insertions, 0 deletions
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) { } + + /// <summary> + /// Writes a blank line in the terminal. + /// </summary> + public virtual void WriteLine() + { + WriteLine(""); + } + + /// <summary> + /// Writes specified text in the terminal and starts a new line. + /// </summary> + /// <param name="value"><summary>The text to write before the new line is made.</summary></param> + public virtual void WriteLine(string value) + { + Array.Find(TerminalBackend.trm.ToArray(), w => w.TerminalID == TermID).termmain.AppendText($"{value} \n"); + } + + /// <summary> + /// Writes specified text in the terminal in the specified color and starts a new line. + /// </summary> + /// <param name="value"><summary>The text to write before the new line is made.</summary></param> + /// <param name="textClr"><summary>The color the text is written in.</summary></param> + 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; + } + + /// <summary> + /// Writes specified text in the terminal. + /// </summary> + /// <param name="value"><summary>The text to write.</summary></param> + /// <param name="textClr"><summary>The color the text is written in.</summary></param> + 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; + } + + /// <summary> + /// Writes specified text in the terminal. + /// </summary> + /// <param name="value"><summary>The text to say before requesting text. </summary></param> + //public virtual Task<string> Input(string value = "") + //{ + // ShiftOS.Apps.Terminal trm = Array.Find(TerminalBackend.trm.ToArray(), w => w.TerminalID == TermID); + // trm.Input(value); + + // Task<string> Input = new Task<string>(() => + // { + // while (true) + // if (trm.InputReturnText != "") break; + + // // The terminal has finally decided! + + // return trm.InputReturnText; + // }); + // Input.Start(); + // return Input; + //} + } +} |
