127 lines
3.7 KiB
C#
127 lines
3.7 KiB
C#
// Decompiled with JetBrains decompiler
|
|
// Type: Raton.RatonForms.ConsoleTextBox
|
|
// Assembly: Raton, Version=0.4.0.0, Culture=neutral, PublicKeyToken=null
|
|
// MVID: 36C4E416-7F8D-4D23-930F-B5CCB0D810E7
|
|
// Assembly location: C:\Users\user\Desktop\v3.8.0 Deluxe Plugins (v4.0.0) cracked\Raton.exe
|
|
|
|
using System;
|
|
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
|
|
#nullable disable
|
|
namespace Raton.RatonForms;
|
|
|
|
public class ConsoleTextBox : RichTextBox
|
|
{
|
|
private int inputStart;
|
|
|
|
public string UserID { get; set; }
|
|
|
|
public string Username { get; set; }
|
|
|
|
public event Action<string> CommandEntered;
|
|
|
|
public Func<string, string> AutoCompleteHandler { get; set; }
|
|
|
|
public ConsoleTextBox()
|
|
{
|
|
this.BorderStyle = BorderStyle.None;
|
|
this.BackColor = Color.Black;
|
|
this.ForeColor = Color.Lime;
|
|
this.Font = new Font("Consolas", 10f);
|
|
this.DetectUrls = false;
|
|
this.Multiline = true;
|
|
this.ScrollBars = RichTextBoxScrollBars.Vertical;
|
|
this.AcceptsTab = true;
|
|
this.PreviewKeyDown += new PreviewKeyDownEventHandler(this.Console_PreviewKeyDown);
|
|
this.KeyDown += new KeyEventHandler(this.Console_KeyDown);
|
|
this.KeyPress += new KeyPressEventHandler(this.Console_KeyPress);
|
|
}
|
|
|
|
private void Console_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
|
|
{
|
|
if (e.KeyCode != Keys.Tab)
|
|
return;
|
|
e.IsInputKey = true;
|
|
}
|
|
|
|
public void ShowPrompt()
|
|
{
|
|
string str;
|
|
if (string.IsNullOrWhiteSpace(this.UserID) || string.IsNullOrWhiteSpace(this.Username))
|
|
str = "$ ";
|
|
else
|
|
str = $"raton@{this.UserID} {this.Username} ~\n$ ";
|
|
string text = str;
|
|
this.SelectionStart = this.TextLength;
|
|
this.SelectionColor = Color.Lime;
|
|
this.AppendText(text);
|
|
this.SelectionColor = this.ForeColor;
|
|
this.inputStart = this.TextLength;
|
|
this.MoveCaretToEnd();
|
|
}
|
|
|
|
private void Console_KeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
if (e.KeyCode == Keys.Tab)
|
|
{
|
|
e.SuppressKeyPress = true;
|
|
if (this.AutoCompleteHandler != null)
|
|
{
|
|
string str = this.AutoCompleteHandler(this.Text.Substring(this.inputStart));
|
|
if (!string.IsNullOrEmpty(str))
|
|
{
|
|
this.SelectionStart = this.inputStart;
|
|
this.SelectionLength = this.TextLength - this.inputStart;
|
|
this.SelectedText = str;
|
|
}
|
|
}
|
|
this.MoveCaretToEnd();
|
|
}
|
|
else if (e.KeyCode == Keys.Return)
|
|
{
|
|
e.SuppressKeyPress = true;
|
|
string str = this.Text.Substring(this.inputStart).Trim();
|
|
this.AppendText(Environment.NewLine);
|
|
Action<string> commandEntered = this.CommandEntered;
|
|
if (commandEntered != null)
|
|
commandEntered(str);
|
|
this.ShowPrompt();
|
|
}
|
|
else if (e.KeyCode == Keys.Back && this.SelectionStart <= this.inputStart && this.SelectionLength == 0)
|
|
{
|
|
e.SuppressKeyPress = true;
|
|
}
|
|
else
|
|
{
|
|
if (e.KeyCode != Keys.Left && e.KeyCode != Keys.Home || this.SelectionStart > this.inputStart)
|
|
return;
|
|
e.SuppressKeyPress = true;
|
|
}
|
|
}
|
|
|
|
private void Console_KeyPress(object sender, KeyPressEventArgs e)
|
|
{
|
|
if (this.SelectionStart >= this.inputStart)
|
|
return;
|
|
this.MoveCaretToEnd();
|
|
}
|
|
|
|
private void MoveCaretToEnd()
|
|
{
|
|
this.SelectionStart = this.TextLength;
|
|
this.SelectionLength = 0;
|
|
this.ScrollToCaret();
|
|
this.Focus();
|
|
}
|
|
|
|
public void WriteLine(string text, Color? color = null)
|
|
{
|
|
this.SelectionStart = this.TextLength;
|
|
this.SelectionColor = color ?? this.ForeColor;
|
|
this.AppendText(text + Environment.NewLine);
|
|
this.SelectionColor = this.ForeColor;
|
|
this.MoveCaretToEnd();
|
|
}
|
|
}
|