mirror of
https://github.com/ShiftOS-Rewind/ShiftOS.git
synced 2025-01-22 17:52:15 +00:00
It's broken.
This commit is contained in:
parent
7efdde5832
commit
b2f7322f30
10 changed files with 181 additions and 85 deletions
|
@ -52,9 +52,6 @@
|
||||||
<DesignTime>True</DesignTime>
|
<DesignTime>True</DesignTime>
|
||||||
<DependentUpon>Resources.resx</DependentUpon>
|
<DependentUpon>Resources.resx</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Terminal\Commands\Hello.cs" />
|
|
||||||
<Compile Include="Terminal\TerminalBackend.cs" />
|
|
||||||
<Compile Include="Terminal\TerminalCommand.cs" />
|
|
||||||
<Compile Include="Tools.cs" />
|
<Compile Include="Tools.cs" />
|
||||||
<Compile Include="WindowManager\InfoboxTemplate.cs">
|
<Compile Include="WindowManager\InfoboxTemplate.cs">
|
||||||
<SubType>UserControl</SubType>
|
<SubType>UserControl</SubType>
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
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, " + String.Join(" ", parameters);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ShiftOS.Engine.Terminal
|
|
||||||
{
|
|
||||||
public class TerminalCommand
|
|
||||||
{
|
|
||||||
public string GetName() { return ""; }
|
|
||||||
|
|
||||||
public void Run(params string[] parameters) { return ""; }
|
|
||||||
|
|
||||||
public void Run(params string[] parameters) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -88,6 +88,9 @@
|
||||||
<Compile Include="ShiftOS\Desktop.Designer.cs">
|
<Compile Include="ShiftOS\Desktop.Designer.cs">
|
||||||
<DependentUpon>Desktop.cs</DependentUpon>
|
<DependentUpon>Desktop.cs</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="Terminal\Commands\Hello.cs" />
|
||||||
|
<Compile Include="Terminal\TerminalBackend.cs" />
|
||||||
|
<Compile Include="Terminal\TerminalCommand.cs" />
|
||||||
<EmbeddedResource Include="HijackScreen.resx">
|
<EmbeddedResource Include="HijackScreen.resx">
|
||||||
<DependentUpon>HijackScreen.cs</DependentUpon>
|
<DependentUpon>HijackScreen.cs</DependentUpon>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
|
|
2
ShiftOS.Main/ShiftOS/Apps/Terminal.Designer.cs
generated
2
ShiftOS.Main/ShiftOS/Apps/Terminal.Designer.cs
generated
|
@ -60,6 +60,6 @@
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private System.Windows.Forms.RichTextBox termmain;
|
public System.Windows.Forms.RichTextBox termmain;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,15 +8,19 @@ using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using ShiftOS.Engine;
|
using ShiftOS.Engine;
|
||||||
using ShiftOS.Engine.Terminal;
|
using ShiftOS.Main.Terminal;
|
||||||
|
|
||||||
namespace ShiftOS.Main.ShiftOS.Apps
|
namespace ShiftOS.Main.ShiftOS.Apps
|
||||||
{
|
{
|
||||||
public partial class Terminal : UserControl
|
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 defaulttextBefore = "user> ";
|
||||||
public string defaulttextResult = "user@shiftos> "; // NOT YET IMPLEMENTED!!!
|
public string defaulttextResult = "user@shiftos> "; // NOT YET IMPLEMENTED!!!
|
||||||
public bool doClear = false;
|
public bool DoClear = false;
|
||||||
|
public bool RunningCommand = false;
|
||||||
|
public bool WaitingResponse = false;
|
||||||
|
public string InputReturnText = "";
|
||||||
|
|
||||||
// The below variables makes the terminal... a terminal!
|
// The below variables makes the terminal... a terminal!
|
||||||
public string OldText = "";
|
public string OldText = "";
|
||||||
|
@ -27,12 +31,8 @@ namespace ShiftOS.Main.ShiftOS.Apps
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
termmain.ContextMenuStrip = new ContextMenuStrip(); // Disables the right click of a richtextbox!
|
termmain.ContextMenuStrip = new ContextMenuStrip(); // Disables the right click of a richtextbox!
|
||||||
}
|
|
||||||
|
|
||||||
public void Print(string text)
|
TerminalBackend.trm.Add(this); // Makes the commands run!
|
||||||
{
|
|
||||||
termmain.AppendText($"\n {text} \n {defaulttextResult}");
|
|
||||||
TrackingPosition = termmain.Text.Length;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void termmain_KeyDown(object sender, KeyEventArgs e)
|
private void termmain_KeyDown(object sender, KeyEventArgs e)
|
||||||
|
@ -45,51 +45,67 @@ namespace ShiftOS.Main.ShiftOS.Apps
|
||||||
// termmain.Paste(DataFormats.GetFormat(DataFormats.Text));
|
// termmain.Paste(DataFormats.GetFormat(DataFormats.Text));
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
} else if (e.KeyCode == Keys.Enter) {
|
} 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!
|
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;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void termmain_TextChanged(object sender, EventArgs e)
|
private void termmain_TextChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (termmain.SelectionStart < TrackingPosition)
|
if (!RunningCommand)
|
||||||
{
|
{
|
||||||
if (doClear == false) // If it's not clearing the terminal
|
if (termmain.SelectionStart < TrackingPosition)
|
||||||
{
|
{
|
||||||
termmain.Text = OldText;
|
if (!DoClear) // If it's not clearing the terminal
|
||||||
termmain.Select(termmain.Text.Length, 0);
|
{
|
||||||
|
termmain.Text = OldText;
|
||||||
|
termmain.Select(termmain.Text.Length, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
OldText = termmain.Text;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
OldText = termmain.Text;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void termmain_SelectionChanged(object sender, EventArgs e)
|
private void termmain_SelectionChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (termmain.SelectionStart < TrackingPosition)
|
if (!RunningCommand)
|
||||||
{
|
{
|
||||||
termmain.Text = OldText;
|
if (termmain.SelectionStart < TrackingPosition)
|
||||||
termmain.Select(termmain.Text.Length, 0);
|
{
|
||||||
|
termmain.Text = OldText;
|
||||||
|
termmain.Select(termmain.Text.Length, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Terminal_Load(object sender, EventArgs e)
|
private void Terminal_Load(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Print("\n");
|
termmain.Text = $"\n {defaulttextResult}";
|
||||||
|
TrackingPosition = termmain.Text.Length;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string RunCommand(string command)
|
public void Input(string request)
|
||||||
{
|
{
|
||||||
string ToReturn = "";
|
InputReturnText = "";
|
||||||
|
RunningCommand = false;
|
||||||
|
|
||||||
if (command == "hi")
|
termmain.AppendText($"\n {request} ");
|
||||||
{
|
TrackingPosition = termmain.Text.Length;
|
||||||
ToReturn = $"{ToReturn} \n Hi!";
|
}
|
||||||
MessageBox.Show("HI!");
|
|
||||||
}
|
public void Clear()
|
||||||
return ToReturn;
|
{
|
||||||
|
DoClear = true;
|
||||||
|
termmain.Text = $"\n {defaulttextResult}";
|
||||||
|
TrackingPosition = termmain.Text.Length;
|
||||||
|
DoClear = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ namespace ShiftOS.Main.ShiftOS
|
||||||
private void terminalToolStripMenuItem_Click(object sender, EventArgs e)
|
private void terminalToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Apps.Terminal trm = new Apps.Terminal();
|
Apps.Terminal trm = new Apps.Terminal();
|
||||||
|
|
||||||
ShiftWM.Init(trm, "Terminal", null, false, true);
|
ShiftWM.Init(trm, "Terminal", null, false, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
25
ShiftOS.Main/Terminal/Commands/Hello.cs
Normal file
25
ShiftOS.Main/Terminal/Commands/Hello.cs
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ShiftOS.Main.Terminal.Commands
|
||||||
|
{
|
||||||
|
public class Hello : TerminalCommand
|
||||||
|
{
|
||||||
|
public override string Name { get; } = "Hello";
|
||||||
|
public override string Summary { get; } = "Just an example command.";
|
||||||
|
public override string Usage { get; } = "Hello <NAME>.";
|
||||||
|
public override bool Unlocked { get; set; } = false;
|
||||||
|
|
||||||
|
public override async 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}.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,8 +4,9 @@ using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace ShiftOS.Engine.Terminal
|
namespace ShiftOS.Main.Terminal
|
||||||
{
|
{
|
||||||
public static class TerminalBackend
|
public static class TerminalBackend
|
||||||
{
|
{
|
||||||
|
@ -15,12 +16,14 @@ namespace ShiftOS.Engine.Terminal
|
||||||
&& t.GetConstructor(Type.EmptyTypes) != null
|
&& t.GetConstructor(Type.EmptyTypes) != null
|
||||||
select Activator.CreateInstance(t) as TerminalCommand;
|
select Activator.CreateInstance(t) as TerminalCommand;
|
||||||
|
|
||||||
|
public static List<ShiftOS.Apps.Terminal> trm = new List<ShiftOS.Apps.Terminal>();
|
||||||
|
public static int trmTopID = 0;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Runs a terminal command.
|
/// Runs a terminal command.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="command"></param>
|
/// <param name="command"></param>
|
||||||
/// <returns>Returns all the output from that command.</returns>
|
/// <param name="rtb"><summary>The rich text box that the text will be written to.</summary></param>
|
||||||
public static string RunCommand(string command)
|
public static void RunCommand(string command, int TermID)
|
||||||
{
|
{
|
||||||
string name;
|
string name;
|
||||||
try { name = command.Split(' ')[0]; } catch { name = command; }
|
try { name = command.Split(' ')[0]; } catch { name = command; }
|
||||||
|
@ -30,17 +33,17 @@ namespace ShiftOS.Engine.Terminal
|
||||||
|
|
||||||
foreach (TerminalCommand instance in instances)
|
foreach (TerminalCommand instance in instances)
|
||||||
{
|
{
|
||||||
if (instance.GetName() == name)
|
if (instance.Name.ToLower() == name.ToLower())
|
||||||
return instance.Run(theParams);
|
{
|
||||||
|
instance.TermID = TermID;
|
||||||
|
// Add a new line!
|
||||||
|
Array.Find(trm.ToArray(), w => w.TerminalID == TermID).termmain.AppendText("\n");
|
||||||
|
instance.Run(theParams);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return "The command cannot be found.";
|
Array.Find(trm.ToArray(), w => w.TerminalID == TermID).termmain.Text += " \n The command cannot be found. \n";
|
||||||
}
|
|
||||||
|
|
||||||
// An extra function ;)
|
|
||||||
private static Type[] GetTypesInNamespace(Assembly assembly, string nameSpace)
|
|
||||||
{
|
|
||||||
return assembly.GetTypes().Where(t => String.Equals(t.Namespace, nameSpace, StringComparison.Ordinal)).ToArray();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
92
ShiftOS.Main/Terminal/TerminalCommand.cs
Normal file
92
ShiftOS.Main/Terminal/TerminalCommand.cs
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue