diff options
| author | IBMPCDOS5 <[email protected]> | 2017-10-14 13:44:48 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2017-10-14 13:44:48 -0500 |
| commit | b0fb6ed50e8108b4c5f4ef8614368664e79d4426 (patch) | |
| tree | a99eba02a00fe5c0d9dd445cc5f82100a40ead9f /ShiftOS.Main/ShiftOS/Apps/Terminal.cs | |
| parent | db714a32b91ae577f256347c71137a7a41dfca37 (diff) | |
| parent | 9952cfd7eb666e04de3b51d1e7dbade8d9168b11 (diff) | |
| download | shiftos-rewind-b0fb6ed50e8108b4c5f4ef8614368664e79d4426.tar.gz shiftos-rewind-b0fb6ed50e8108b4c5f4ef8614368664e79d4426.tar.bz2 shiftos-rewind-b0fb6ed50e8108b4c5f4ef8614368664e79d4426.zip | |
Merge pull request #10 from Alex-TIMEHACK/master
Terminal. With a little example command.
Diffstat (limited to 'ShiftOS.Main/ShiftOS/Apps/Terminal.cs')
| -rw-r--r-- | ShiftOS.Main/ShiftOS/Apps/Terminal.cs | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/ShiftOS.Main/ShiftOS/Apps/Terminal.cs b/ShiftOS.Main/ShiftOS/Apps/Terminal.cs new file mode 100644 index 0000000..a9bd093 --- /dev/null +++ b/ShiftOS.Main/ShiftOS/Apps/Terminal.cs @@ -0,0 +1,95 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using ShiftOS.Engine; +using ShiftOS.Engine.Terminal; + +namespace ShiftOS.Main.ShiftOS.Apps +{ + public partial class Terminal : UserControl + { + public string defaulttextBefore = "user> "; + public string defaulttextResult = "user@shiftos> "; // NOT YET IMPLEMENTED!!! + public bool doClear = false; + + // The below variables makes the terminal... a terminal! + public string OldText = ""; + public int TrackingPosition = 0; + + public Terminal() + { + 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; + } + + private void termmain_KeyDown(object sender, KeyEventArgs e) + { + // The below code disables the ability to paste anything other then text... + + 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) { + Print(TerminalBackend.RunCommand(termmain.Text.Substring(TrackingPosition, termmain.Text.Length - TrackingPosition))); // The most horrific line in the entire application! + e.Handled = true; + } + } + + private void termmain_TextChanged(object sender, EventArgs e) + { + if (termmain.SelectionStart < TrackingPosition) + { + if (doClear == false) // 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 (termmain.SelectionStart < TrackingPosition) + { + termmain.Text = OldText; + termmain.Select(termmain.Text.Length, 0); + } + } + + private void Terminal_Load(object sender, EventArgs e) + { + Print("\n"); + } + + public string RunCommand(string command) + { + string ToReturn = ""; + + if (command == "hi") + { + ToReturn = $"{ToReturn} \n Hi!"; + MessageBox.Show("HI!"); + } + return ToReturn; + } + } +} |
