This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
pithos/mainWindow.cs

78 lines
3 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Pithos
{
public partial class mainWindow : Form
{
private decode decoder = new decode();
public bool adminMode = false;
public mainWindow()
{
InitializeComponent();
}
public void display(string text, Color colour) {
/* Message Color Codes:
* Green: User Messages (Mainly Echo)
* Orange: Admin Commands
* Black: General text / Date
* Red: Error Messages
* Blue: Messages from Program
*/
if (output.TextLength != 0) { output.AppendText("\n[" + DateTime.Now.ToString("hh:mm:ss") + "] "); } //so that the first line isnt a new line for no reason. (although its extra code)
else { output.AppendText("[" + DateTime.Now.ToString("hh:mm:ss") + "] "); }
int length = output.TextLength;
text = decoder.injectVariables(text);
output.AppendText(text);
output.SelectionStart = length;
output.SelectionLength = text.Length;
output.SelectionColor = colour;
output.SelectionStart = length + text.Length;
output.SelectionColor = Color.Black;
}
private void mainWindow_Load(object sender, EventArgs e)
{
display("Currently Logged in as: " + Environment.UserDomainName + "\\" + Environment.UserName, Color.Blue);
}
private void executeButton_Click(object sender, EventArgs e)
{
bool valid = true;
string input = inputBox.Text;
if (input == "") { display("Error: No command given.", Color.Red); return; } //if its empty, dont bother decoding
string initChar = input.Substring(0, 1); //gets the first character in the input
string[] args = input.Substring(1).Split(' '); //splits the input by spaces, and removes init character
switch (initChar)
{
case "/":
if (args[0] == "exec") //runs a pithos program
{
pithosPrograms.decodeInput(input);
return;
}
else if (args[0] == "start") //runs a program (using cmd)
{
}
else { valid = decoder.command(input); } //decode other commands
break;
case "¦": //admin commands
privateFunctions.adminCommands(input);
break;
}
if (input.Substring(0, 4).ToLower() == "echo")
{
display(input.Substring(5), Color.Green);
}
inputBox.Text = ""; //clear the contents after execution
}
}
}