mirror of
https://git.alee14.me/shiftos-archive/ShiftOS_TheReturn.git
synced 2025-01-22 18:02:16 +00:00
Colored terminal text
This commit is contained in:
parent
d9b4e79bcf
commit
3f08cb807c
5 changed files with 83 additions and 0 deletions
|
@ -26,9 +26,11 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using ShiftOS.Engine;
|
||||
using ShiftOS.WinForms.Tools;
|
||||
|
||||
namespace ShiftOS.WinForms.Controls
|
||||
{
|
||||
|
@ -53,13 +55,21 @@ namespace ShiftOS.WinForms.Controls
|
|||
public void Write(string text)
|
||||
{
|
||||
this.HideSelection = true;
|
||||
this.Select(this.TextLength, 0);
|
||||
this.SelectionColor = ControlManager.ConvertColor(ConsoleEx.ForegroundColor);
|
||||
this.SelectionBackColor = ControlManager.ConvertColor(ConsoleEx.BackgroundColor);
|
||||
this.AppendText(Localization.Parse(text));
|
||||
this.HideSelection = false;
|
||||
}
|
||||
|
||||
public void WriteLine(string text)
|
||||
{
|
||||
this.HideSelection = true;
|
||||
this.Select(this.TextLength, 0);
|
||||
this.SelectionColor = ControlManager.ConvertColor(ConsoleEx.ForegroundColor);
|
||||
this.SelectionBackColor = ControlManager.ConvertColor(ConsoleEx.BackgroundColor);
|
||||
this.AppendText(Localization.Parse(text) + Environment.NewLine);
|
||||
this.HideSelection = false;
|
||||
}
|
||||
|
||||
bool quickCopying = false;
|
||||
|
|
|
@ -152,6 +152,48 @@ namespace ShiftOS.WinForms.Tools
|
|||
}
|
||||
}
|
||||
|
||||
internal static Color ConvertColor(ConsoleColor cCol)
|
||||
{
|
||||
switch (cCol)
|
||||
{
|
||||
case ConsoleColor.Black:
|
||||
return Color.Black;
|
||||
case ConsoleColor.Gray:
|
||||
return Color.Gray;
|
||||
case ConsoleColor.DarkGray:
|
||||
return Color.DarkGray;
|
||||
case ConsoleColor.Blue:
|
||||
return Color.Blue;
|
||||
case ConsoleColor.Cyan:
|
||||
return Color.Cyan;
|
||||
case ConsoleColor.DarkBlue:
|
||||
return Color.DarkBlue;
|
||||
case ConsoleColor.DarkCyan:
|
||||
return Color.DarkCyan;
|
||||
case ConsoleColor.DarkGreen:
|
||||
return Color.DarkGreen;
|
||||
case ConsoleColor.DarkMagenta:
|
||||
return Color.DarkMagenta;
|
||||
case ConsoleColor.DarkRed:
|
||||
return Color.DarkRed;
|
||||
case ConsoleColor.DarkYellow:
|
||||
return Color.YellowGreen;
|
||||
case ConsoleColor.Yellow:
|
||||
return Color.Yellow;
|
||||
case ConsoleColor.Green:
|
||||
return Color.Green;
|
||||
case ConsoleColor.Magenta:
|
||||
return Color.Magenta;
|
||||
case ConsoleColor.Red:
|
||||
return Color.Red;
|
||||
case ConsoleColor.White:
|
||||
return Color.White;
|
||||
default:
|
||||
return Color.Black;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void SetCursor(Control ctrl)
|
||||
{
|
||||
#if STUPID
|
||||
|
|
28
ShiftOS_TheReturn/ConsoleEx.cs
Normal file
28
ShiftOS_TheReturn/ConsoleEx.cs
Normal file
|
@ -0,0 +1,28 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ShiftOS.Engine
|
||||
{
|
||||
public static class ConsoleEx
|
||||
{
|
||||
static ConsoleEx()
|
||||
{
|
||||
ForegroundColor = ConsoleColor.White;
|
||||
BackgroundColor = ConsoleColor.Black;
|
||||
|
||||
Bold = false;
|
||||
Italic = false;
|
||||
Underline = false;
|
||||
}
|
||||
|
||||
public static ConsoleColor ForegroundColor { get; set; }
|
||||
public static ConsoleColor BackgroundColor { get; set; }
|
||||
|
||||
public static bool Bold { get; set; }
|
||||
public static bool Italic { get; set; }
|
||||
public static bool Underline { get; set; }
|
||||
}
|
||||
}
|
|
@ -154,7 +154,9 @@ namespace ShiftOS.Engine
|
|||
{
|
||||
var ex = JsonConvert.DeserializeObject<Exception>(msg.Contents);
|
||||
TerminalBackend.PrefixEnabled = true;
|
||||
ConsoleEx.ForegroundColor = ConsoleColor.DarkYellow;
|
||||
Console.WriteLine($@"{{MUD_ERROR}}: {ex.Message}");
|
||||
ConsoleEx.ForegroundColor = ConsoleColor.White;
|
||||
TerminalBackend.PrefixEnabled = true;
|
||||
Console.Write($"{SaveSystem.CurrentSave.Username}@{CurrentSave.SystemName}:~$ ");
|
||||
}
|
||||
|
|
|
@ -99,6 +99,7 @@
|
|||
<Compile Include="AudioManager.cs" />
|
||||
<Compile Include="Commands.cs" />
|
||||
<Compile Include="Command.cs" />
|
||||
<Compile Include="ConsoleEx.cs" />
|
||||
<Compile Include="CrashHandler.cs" />
|
||||
<Compile Include="CrashHandler.Designer.cs">
|
||||
<DependentUpon>CrashHandler.cs</DependentUpon>
|
||||
|
|
Loading…
Reference in a new issue