diff options
Diffstat (limited to 'ShiftOS.Main/ShiftOS/Apps')
| -rw-r--r-- | ShiftOS.Main/ShiftOS/Apps/Terminal.Designer.cs | 2 | ||||
| -rw-r--r-- | ShiftOS.Main/ShiftOS/Apps/Terminal.cs | 89 |
2 files changed, 89 insertions, 2 deletions
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..a5c5a11 100644 --- a/ShiftOS.Main/ShiftOS/Apps/Terminal.cs +++ b/ShiftOS.Main/ShiftOS/Apps/Terminal.cs @@ -1,5 +1,19 @@ using System; using System.Windows.Forms; +using ShiftOS.Engine; +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 RunningCommand = false; + public bool WaitingResponse = false; + public string InputReturnText = ""; using ShiftOS.Engine.Terminal; namespace ShiftOS.Main.ShiftOS.Apps @@ -15,6 +29,10 @@ namespace ShiftOS.Main.ShiftOS.Apps int TrackingPosition; + termmain.ContextMenuStrip = new ContextMenuStrip(); // Disables the right click of a richtextbox! + + TerminalBackend.trm.Add(this); // Makes the commands run! + } public Terminal() { InitializeComponent(); @@ -27,7 +45,76 @@ namespace ShiftOS.Main.ShiftOS.Apps 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; + } + + 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) { // The below code disables the ability to paste anything other then text... @@ -77,4 +164,4 @@ namespace ShiftOS.Main.ShiftOS.Apps Print("\n"); } } -}
\ No newline at end of file +} |
