From 59a7eabcbe37d44a1cd4a9b742ce99f423a42ff7 Mon Sep 17 00:00:00 2001 From: Alex-TIMEHACK Date: Sat, 14 Oct 2017 16:23:41 +0100 Subject: Done like a few things but I need to update so.... --- ShiftOS.Main/ShiftOS/Apps/Terminal.Designer.cs | 65 ++++++++++++++ ShiftOS.Main/ShiftOS/Apps/Terminal.cs | 92 +++++++++++++++++++ ShiftOS.Main/ShiftOS/Apps/Terminal.resx | 120 +++++++++++++++++++++++++ 3 files changed, 277 insertions(+) create mode 100644 ShiftOS.Main/ShiftOS/Apps/Terminal.Designer.cs create mode 100644 ShiftOS.Main/ShiftOS/Apps/Terminal.cs create mode 100644 ShiftOS.Main/ShiftOS/Apps/Terminal.resx (limited to 'ShiftOS.Main/ShiftOS/Apps') diff --git a/ShiftOS.Main/ShiftOS/Apps/Terminal.Designer.cs b/ShiftOS.Main/ShiftOS/Apps/Terminal.Designer.cs new file mode 100644 index 0000000..e92cdb4 --- /dev/null +++ b/ShiftOS.Main/ShiftOS/Apps/Terminal.Designer.cs @@ -0,0 +1,65 @@ +namespace ShiftOS.Main.ShiftOS.Apps +{ + partial class Terminal + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.termmain = new System.Windows.Forms.RichTextBox(); + this.SuspendLayout(); + // + // termmain + // + this.termmain.BackColor = System.Drawing.Color.Black; + this.termmain.BorderStyle = System.Windows.Forms.BorderStyle.None; + this.termmain.Dock = System.Windows.Forms.DockStyle.Fill; + this.termmain.ForeColor = System.Drawing.Color.White; + this.termmain.Location = new System.Drawing.Point(0, 0); + this.termmain.Name = "termmain"; + this.termmain.Size = new System.Drawing.Size(476, 394); + this.termmain.TabIndex = 0; + this.termmain.Text = ""; + this.termmain.SelectionChanged += new System.EventHandler(this.termmain_SelectionChanged); + this.termmain.TextChanged += new System.EventHandler(this.termmain_TextChanged); + this.termmain.KeyDown += new System.Windows.Forms.KeyEventHandler(this.termmain_KeyDown); + // + // Terminal + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.termmain); + this.Name = "Terminal"; + this.Size = new System.Drawing.Size(476, 394); + this.Load += new System.EventHandler(this.Terminal_Load); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.RichTextBox termmain; + } +} diff --git a/ShiftOS.Main/ShiftOS/Apps/Terminal.cs b/ShiftOS.Main/ShiftOS/Apps/Terminal.cs new file mode 100644 index 0000000..cb5bed3 --- /dev/null +++ b/ShiftOS.Main/ShiftOS/Apps/Terminal.cs @@ -0,0 +1,92 @@ +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; + +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(RunCommand(termmain.Text.Substring(TrackingPosition, termmain.Text.Length - TrackingPosition))); // The most horrific line in the entire application! + } + } + + 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; + } + } +} diff --git a/ShiftOS.Main/ShiftOS/Apps/Terminal.resx b/ShiftOS.Main/ShiftOS/Apps/Terminal.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/ShiftOS.Main/ShiftOS/Apps/Terminal.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file -- cgit v1.2.3 From 09215a05ddc717b2eaf667737ac6baa724c5f2bc Mon Sep 17 00:00:00 2001 From: Alex-TIMEHACK Date: Sat, 14 Oct 2017 18:42:11 +0100 Subject: YOY terminal --- ShiftOS.Engine/ShiftOS.Engine.csproj | 4 +++ ShiftOS.Engine/Terminal/Commands/Hello.cs | 21 ++++++++++++++ ShiftOS.Engine/Terminal/TerminalBackend.cs | 46 ++++++++++++++++++++++++++++++ ShiftOS.Engine/Terminal/TerminalCommand.cs | 15 ++++++++++ ShiftOS.Main/ShiftOS/Apps/Terminal.cs | 5 +++- 5 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 ShiftOS.Engine/Terminal/Commands/Hello.cs create mode 100644 ShiftOS.Engine/Terminal/TerminalBackend.cs create mode 100644 ShiftOS.Engine/Terminal/TerminalCommand.cs (limited to 'ShiftOS.Main/ShiftOS/Apps') diff --git a/ShiftOS.Engine/ShiftOS.Engine.csproj b/ShiftOS.Engine/ShiftOS.Engine.csproj index 71721bc..6740db1 100644 --- a/ShiftOS.Engine/ShiftOS.Engine.csproj +++ b/ShiftOS.Engine/ShiftOS.Engine.csproj @@ -52,6 +52,9 @@ True Resources.resx + + + UserControl @@ -93,5 +96,6 @@ + \ No newline at end of file diff --git a/ShiftOS.Engine/Terminal/Commands/Hello.cs b/ShiftOS.Engine/Terminal/Commands/Hello.cs new file mode 100644 index 0000000..daf8488 --- /dev/null +++ b/ShiftOS.Engine/Terminal/Commands/Hello.cs @@ -0,0 +1,21 @@ +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," + parameters[0]; + } + } +} diff --git a/ShiftOS.Engine/Terminal/TerminalBackend.cs b/ShiftOS.Engine/Terminal/TerminalBackend.cs new file mode 100644 index 0000000..7103238 --- /dev/null +++ b/ShiftOS.Engine/Terminal/TerminalBackend.cs @@ -0,0 +1,46 @@ +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 new file mode 100644 index 0000000..a344122 --- /dev/null +++ b/ShiftOS.Engine/Terminal/TerminalCommand.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShiftOS.Engine.Terminal +{ + public abstract class TerminalCommand + { + public abstract string GetName(); + + public abstract string Run(params string[] parameters); + } +} diff --git a/ShiftOS.Main/ShiftOS/Apps/Terminal.cs b/ShiftOS.Main/ShiftOS/Apps/Terminal.cs index cb5bed3..a9bd093 100644 --- a/ShiftOS.Main/ShiftOS/Apps/Terminal.cs +++ b/ShiftOS.Main/ShiftOS/Apps/Terminal.cs @@ -7,6 +7,8 @@ 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 { @@ -43,7 +45,8 @@ namespace ShiftOS.Main.ShiftOS.Apps // termmain.Paste(DataFormats.GetFormat(DataFormats.Text)); e.Handled = true; } else if (e.KeyCode == Keys.Enter) { - Print(RunCommand(termmain.Text.Substring(TrackingPosition, termmain.Text.Length - TrackingPosition))); // The most horrific line in the entire application! + Print(TerminalBackend.RunCommand(termmain.Text.Substring(TrackingPosition, termmain.Text.Length - TrackingPosition))); // The most horrific line in the entire application! + e.Handled = true; } } -- cgit v1.2.3