ShiftOS-Rewind/ShiftOS.Main/Terminal/TerminalCommand.cs

103 lines
3.6 KiB
C#
Raw Permalink Normal View History

2017-10-15 15:25:37 -04:00
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)
{
2017-11-21 17:32:56 -05:00
Array.Find(TerminalBackend.trm.ToArray(), w => w.TerminalID == TermID).termmain.AppendText($" {value} \n");
2017-10-15 15:25:37 -04:00
}
/// <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)
{
Main.Apps.Terminal trm = Array.Find(TerminalBackend.trm.ToArray(), w => w.TerminalID == TermID);
2017-10-15 15:25:37 -04:00
int startPoint = trm.termmain.Text.Length;
2017-11-21 17:32:56 -05:00
trm.termmain.AppendText($" {value} \n");
trm.termmain.Select(startPoint, $" {value} \n".Length);
2017-10-15 15:25:37 -04:00
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)
{
Main.Apps.Terminal trm = Array.Find(TerminalBackend.trm.ToArray(), w => w.TerminalID == TermID);
2017-10-15 15:25:37 -04:00
int startPoint = trm.termmain.Text.Length;
2017-11-21 17:32:56 -05:00
trm.termmain.AppendText($" {value}");
trm.termmain.Select(startPoint, $" {value}".Length);
2017-10-15 15:25:37 -04:00
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>
2017-11-18 11:09:54 -05:00
//public virtual Task<string> Input(string value = "")
//{
// ShiftOS.Apps.Terminal trm = Array.Find(TerminalBackend.trm.ToArray(), w => w.TerminalID == TermID);
// trm.Input(value);
2017-10-15 15:25:37 -04:00
2017-11-18 11:09:54 -05:00
// Task<string> Input = new Task<string>(() =>
// {
// while (true)
// if (trm.InputReturnText != "") break;
2017-10-15 15:25:37 -04:00
2017-11-18 11:09:54 -05:00
// // The terminal has finally decided!
2017-10-15 15:25:37 -04:00
2017-11-18 11:09:54 -05:00
// return trm.InputReturnText;
// });
// Input.Start();
// return Input;
//}
2017-11-23 13:25:57 -05:00
2017-11-23 12:20:53 -05:00
/// <summary>
/// Clears all text from the terminal.
/// </summary>
public virtual void Clear()
{
Main.Apps.Terminal trm = Array.Find(TerminalBackend.trm.ToArray(), w => w.TerminalID == TermID);
2017-11-23 12:20:53 -05:00
trm.Clear();
}
2017-10-15 15:25:37 -04:00
}
}