mirror of
https://github.com/ShiftOS-Rewind/ShiftOS.git
synced 2025-01-22 03:11:47 -05:00
things are working again
yoy
This commit is contained in:
parent
684cdb8e3b
commit
f847236b78
4 changed files with 178 additions and 2 deletions
|
@ -33,6 +33,9 @@
|
||||||
<LangVersion>latest</LangVersion>
|
<LangVersion>latest</LangVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Reference Include="DotNetZip, Version=1.10.1.0, Culture=neutral, PublicKeyToken=6583c7c814667745, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\DotNetZip.1.10.1\lib\net20\DotNetZip.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.Xml.Linq" />
|
<Reference Include="System.Xml.Linq" />
|
||||||
|
|
172
ShiftOS.Main/ShiftOS/Apps/Terminal.cs
Normal file
172
ShiftOS.Main/ShiftOS/Apps/Terminal.cs
Normal file
|
@ -0,0 +1,172 @@
|
||||||
|
using System;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using ShiftOS.Engine;
|
||||||
|
using ShiftOS.Main.Terminal;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing.Text;
|
||||||
|
using System.IO;
|
||||||
|
using ShiftOS.Main.Properties;
|
||||||
|
using Whoa;
|
||||||
|
|
||||||
|
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 = "";
|
||||||
|
public Stack<string> c = TerminalBackend.commandBuffer;
|
||||||
|
private PrivateFontCollection fontCollection = new PrivateFontCollection();
|
||||||
|
|
||||||
|
|
||||||
|
// The below variables makes the terminal... a terminal!
|
||||||
|
string OldText = "";
|
||||||
|
|
||||||
|
int TrackingPosition;
|
||||||
|
|
||||||
|
public Terminal()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
|
||||||
|
termmain.ContextMenuStrip = new ContextMenuStrip(); // Disables the right click of a richtextbox!
|
||||||
|
|
||||||
|
TerminalBackend.trm.Add(this);
|
||||||
|
|
||||||
|
|
||||||
|
Setup();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Print()
|
||||||
|
{
|
||||||
|
termmain.AppendText($"\n {defaulttextResult}");
|
||||||
|
TrackingPosition = termmain.Text.Length;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Print(string text)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
termmain.Select(termmain.TextLength, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Input(string request)
|
||||||
|
{
|
||||||
|
InputReturnText = "";
|
||||||
|
RunningCommand = false;
|
||||||
|
|
||||||
|
termmain.AppendText($"\n {request} ");
|
||||||
|
TrackingPosition = termmain.Text.Length;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Clear()
|
||||||
|
{
|
||||||
|
DoClear = true;
|
||||||
|
OldText = "";
|
||||||
|
termmain.Text = "";
|
||||||
|
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...
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
TerminalBackend.RunCommand(termmain.Text.Substring(TrackingPosition, termmain.Text.Length - TrackingPosition), TerminalID); // The most horrific line in the entire application!
|
||||||
|
Print();
|
||||||
|
e.Handled = true;
|
||||||
|
}
|
||||||
|
else if (e.KeyCode == Keys.Up)
|
||||||
|
{
|
||||||
|
if (c.Count == 0) return;
|
||||||
|
termmain.AppendText(c.Pop());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
if (!Directory.Exists(SaveSystem.gameDir)) Directory.CreateDirectory(SaveSystem.gameDir);
|
||||||
|
if (!Directory.Exists(SaveSystem.fontDir)) Directory.CreateDirectory(SaveSystem.fontDir);
|
||||||
|
if (!Directory.Exists(SaveSystem.dataDir)) Directory.CreateDirectory(SaveSystem.dataDir);
|
||||||
|
if (!File.Exists(SaveSystem.fontDir + "\\termFont.ttf")) File.WriteAllBytes(SaveSystem.fontDir + "\\termFont.ttf", Resources.UbuntuMono_R);
|
||||||
|
if (!File.Exists(SaveSystem.dataDir + "\\userCodePoints.whoa"))
|
||||||
|
{
|
||||||
|
using (var fobj = File.OpenWrite(SaveSystem.dataDir + "\\userCodePoints.whoa"))
|
||||||
|
{
|
||||||
|
Whoa.Whoa.SerialiseObject(fobj, SaveSystem.User.codePoints);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!Directory.Exists(SaveSystem.baseGameDir)) Directory.CreateDirectory(SaveSystem.baseGameDir);
|
||||||
|
if (!Directory.Exists(SaveSystem.desktopDir)) Directory.CreateDirectory(SaveSystem.desktopDir);
|
||||||
|
if (!Directory.Exists(SaveSystem.docDir)) Directory.CreateDirectory(SaveSystem.docDir);
|
||||||
|
if (!Directory.Exists(SaveSystem.downloadsDir)) Directory.CreateDirectory(SaveSystem.downloadsDir);
|
||||||
|
if (!Directory.Exists(SaveSystem.musicDir)) Directory.CreateDirectory(SaveSystem.musicDir);
|
||||||
|
if (!Directory.Exists(SaveSystem.picDir)) Directory.CreateDirectory(SaveSystem.picDir);
|
||||||
|
fontCollection.AddFontFile(SaveSystem.fontDir + "\\termFont.ttf");
|
||||||
|
termmain.Font = new System.Drawing.Font(fontCollection.Families[0], 12F, System.Drawing.FontStyle.Regular);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -30,12 +30,12 @@ namespace ShiftOS.Main.Terminal.Commands
|
||||||
break;
|
break;
|
||||||
case "incoming":
|
case "incoming":
|
||||||
WriteLine("Incoming connections from localhost:");
|
WriteLine("Incoming connections from localhost:");
|
||||||
WriteLine($"IP ADDRESS v4 COMPUTER NAME");
|
WriteLine($"IP ADDRESS IPv4 COMPUTER NAME");
|
||||||
WriteLine($"{r.Next(0, 255)}.{r.Next(0, 255)}.{r.Next(0, 255)}.{r.Next(255)} {gen}");
|
WriteLine($"{r.Next(0, 255)}.{r.Next(0, 255)}.{r.Next(0, 255)}.{r.Next(255)} {gen}");
|
||||||
break;
|
break;
|
||||||
case "outgoing":
|
case "outgoing":
|
||||||
WriteLine("Outgoing connections from localhost:");
|
WriteLine("Outgoing connections from localhost:");
|
||||||
WriteLine($"IP ADDRESS v4 COMPUTER NAME");
|
WriteLine($"IP ADDRESS IPv4 COMPUTER NAME");
|
||||||
WriteLine($"{r.Next(0, 255)}.{r.Next(0, 255)}.{r.Next(0, 255)}.{r.Next(255)} {gen}");
|
WriteLine($"{r.Next(0, 255)}.{r.Next(0, 255)}.{r.Next(0, 255)}.{r.Next(255)} {gen}");
|
||||||
WriteLine($"[1] outgoing connection(s) is using {r.Next(0, 16)} MiBs of bandwith.");
|
WriteLine($"[1] outgoing connection(s) is using {r.Next(0, 16)} MiBs of bandwith.");
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
|
<package id="DotNetZip" version="1.10.1" targetFramework="net45" />
|
||||||
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net45" />
|
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net45" />
|
||||||
<package id="Whoa" version="1.5.0" targetFramework="net45" />
|
<package id="Whoa" version="1.5.0" targetFramework="net45" />
|
||||||
</packages>
|
</packages>
|
Loading…
Reference in a new issue