2017-10-14 16:23:41 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Windows.Forms;
|
2017-10-14 18:42:11 +01:00
|
|
|
|
using ShiftOS.Engine.Terminal;
|
2017-10-14 16:23:41 +01:00
|
|
|
|
|
|
|
|
|
namespace ShiftOS.Main.ShiftOS.Apps
|
|
|
|
|
{
|
2017-11-05 18:47:46 -05:00
|
|
|
|
public partial class Terminal : UserControl
|
|
|
|
|
{
|
|
|
|
|
public string DefaulttextBefore = "user> ";
|
|
|
|
|
string DefaulttextResult = "user@shiftos> "; // NOT YET IMPLEMENTED!!!
|
|
|
|
|
bool DoClear = false;
|
2017-10-14 16:23:41 +01:00
|
|
|
|
|
2017-11-05 18:47:46 -05:00
|
|
|
|
// The below variables makes the terminal... a terminal!
|
|
|
|
|
string OldText = "";
|
2017-10-14 16:23:41 +01:00
|
|
|
|
|
2017-11-05 18:47:46 -05:00
|
|
|
|
int TrackingPosition;
|
2017-10-14 16:23:41 +01:00
|
|
|
|
|
2017-11-05 18:47:46 -05:00
|
|
|
|
public Terminal()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2017-10-14 16:23:41 +01:00
|
|
|
|
|
2017-11-05 18:47:46 -05:00
|
|
|
|
termmain.ContextMenuStrip = new ContextMenuStrip(); // Disables the right click of a richtextbox!
|
|
|
|
|
}
|
2017-10-14 16:23:41 +01:00
|
|
|
|
|
2017-11-05 18:47:46 -05:00
|
|
|
|
void Print(string text)
|
|
|
|
|
{
|
|
|
|
|
termmain.AppendText($"\n {text} \n {DefaulttextResult}");
|
|
|
|
|
TrackingPosition = termmain.Text.Length;
|
|
|
|
|
}
|
2017-10-14 16:23:41 +01:00
|
|
|
|
|
2017-11-05 18:47:46 -05:00
|
|
|
|
void termmain_KeyDown(object sender, KeyEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// The below code disables the ability to paste anything other then text...
|
2017-10-14 16:23:41 +01:00
|
|
|
|
|
2017-11-05 18:47:46 -05:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-10-14 16:23:41 +01:00
|
|
|
|
|
2017-11-05 18:47:46 -05:00
|
|
|
|
void termmain_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (termmain.SelectionStart < TrackingPosition)
|
|
|
|
|
{
|
|
|
|
|
if (DoClear) return;
|
|
|
|
|
|
|
|
|
|
termmain.Text = OldText;
|
|
|
|
|
termmain.Select(termmain.Text.Length, 0);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
OldText = termmain.Text;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-10-14 16:23:41 +01:00
|
|
|
|
|
2017-11-05 18:47:46 -05:00
|
|
|
|
void termmain_SelectionChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (termmain.SelectionStart >= TrackingPosition) return;
|
|
|
|
|
|
|
|
|
|
termmain.Text = OldText;
|
|
|
|
|
termmain.Select(termmain.Text.Length, 0);
|
|
|
|
|
}
|
2017-10-14 16:23:41 +01:00
|
|
|
|
|
2017-11-05 18:47:46 -05:00
|
|
|
|
void Terminal_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Print("\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|