From 5f0cfb100cc0698ede828857393b7fd3f44af73d Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 8 Mar 2017 19:08:35 -0500 Subject: selecting content in terminal copies to clipboard --- ShiftOS.WinForms/Controls/TerminalBox.cs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'ShiftOS.WinForms/Controls/TerminalBox.cs') diff --git a/ShiftOS.WinForms/Controls/TerminalBox.cs b/ShiftOS.WinForms/Controls/TerminalBox.cs index 4fcb429..b75d077 100644 --- a/ShiftOS.WinForms/Controls/TerminalBox.cs +++ b/ShiftOS.WinForms/Controls/TerminalBox.cs @@ -61,5 +61,29 @@ namespace ShiftOS.WinForms.Controls { this.AppendText(Localization.Parse(text) + Environment.NewLine); } + + bool quickCopying = false; + + protected override void OnMouseDown(MouseEventArgs e) + { + //if right-clicking, then we initiate a quick-copy. + if (e.Button == MouseButtons.Right) + quickCopying = true; + + //Override the mouse event so that it's a left-click at all times. + base.OnMouseDown(new MouseEventArgs(MouseButtons.Left, e.Clicks, e.X, e.Y, e.Delta)); + } + + protected override void OnMouseUp(MouseEventArgs mevent) + { + if(quickCopying == true) + { + if (!string.IsNullOrWhiteSpace(this.SelectedText)) + { + this.Copy(); + } + } + base.OnMouseUp(mevent); + } } } -- cgit v1.2.3 From 3f08cb807c1490af423450e3eb03a46aa11caf2f Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 9 Mar 2017 16:14:35 -0500 Subject: Colored terminal text --- ShiftOS.WinForms/Controls/TerminalBox.cs | 10 ++++++++ ShiftOS.WinForms/Tools/ControlManager.cs | 42 ++++++++++++++++++++++++++++++++ ShiftOS_TheReturn/ConsoleEx.cs | 28 +++++++++++++++++++++ ShiftOS_TheReturn/ServerManager.cs | 2 ++ ShiftOS_TheReturn/ShiftOS.Engine.csproj | 1 + 5 files changed, 83 insertions(+) create mode 100644 ShiftOS_TheReturn/ConsoleEx.cs (limited to 'ShiftOS.WinForms/Controls/TerminalBox.cs') diff --git a/ShiftOS.WinForms/Controls/TerminalBox.cs b/ShiftOS.WinForms/Controls/TerminalBox.cs index b75d077..7c0da57 100644 --- a/ShiftOS.WinForms/Controls/TerminalBox.cs +++ b/ShiftOS.WinForms/Controls/TerminalBox.cs @@ -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; diff --git a/ShiftOS.WinForms/Tools/ControlManager.cs b/ShiftOS.WinForms/Tools/ControlManager.cs index 5cc4813..52663d7 100644 --- a/ShiftOS.WinForms/Tools/ControlManager.cs +++ b/ShiftOS.WinForms/Tools/ControlManager.cs @@ -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 diff --git a/ShiftOS_TheReturn/ConsoleEx.cs b/ShiftOS_TheReturn/ConsoleEx.cs new file mode 100644 index 0000000..69f6a18 --- /dev/null +++ b/ShiftOS_TheReturn/ConsoleEx.cs @@ -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; } + } +} diff --git a/ShiftOS_TheReturn/ServerManager.cs b/ShiftOS_TheReturn/ServerManager.cs index a121ab6..7da09f1 100644 --- a/ShiftOS_TheReturn/ServerManager.cs +++ b/ShiftOS_TheReturn/ServerManager.cs @@ -154,7 +154,9 @@ namespace ShiftOS.Engine { var ex = JsonConvert.DeserializeObject(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}:~$ "); } diff --git a/ShiftOS_TheReturn/ShiftOS.Engine.csproj b/ShiftOS_TheReturn/ShiftOS.Engine.csproj index 20ca879..00d828f 100644 --- a/ShiftOS_TheReturn/ShiftOS.Engine.csproj +++ b/ShiftOS_TheReturn/ShiftOS.Engine.csproj @@ -99,6 +99,7 @@ + CrashHandler.cs -- cgit v1.2.3 From 251521835b60024dec292a759d738e2b81bf1417 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 9 Mar 2017 16:46:34 -0500 Subject: Console colors! --- ShiftOS.WinForms/Applications/Terminal.cs | 4 ++-- ShiftOS.WinForms/Controls/TerminalBox.cs | 16 +++++++++++++++ ShiftOS_TheReturn/ServerManager.cs | 11 +++++++--- ShiftOS_TheReturn/TerminalBackend.cs | 34 ++++++++++++++++++++++++++++++- 4 files changed, 59 insertions(+), 6 deletions(-) (limited to 'ShiftOS.WinForms/Controls/TerminalBox.cs') diff --git a/ShiftOS.WinForms/Applications/Terminal.cs b/ShiftOS.WinForms/Applications/Terminal.cs index 7bab213..65a8f0f 100644 --- a/ShiftOS.WinForms/Applications/Terminal.cs +++ b/ShiftOS.WinForms/Applications/Terminal.cs @@ -134,7 +134,7 @@ namespace ShiftOS.WinForms.Applications rtbterm.Text = ""; TerminalBackend.PrefixEnabled = true; TerminalBackend.InStory = false; - Console.Write($"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ "); + TerminalBackend.PrintPrompt(); if (Shiftorium.UpgradeInstalled("wm_free_placement")) { this.ParentForm.Width = 640; @@ -276,7 +276,7 @@ namespace ShiftOS.WinForms.Applications } if (TerminalBackend.PrefixEnabled) { - Console.Write($"{SaveSystem.CurrentSave.Username}@{SaveSystem.CurrentSave.SystemName}:~$ "); + TerminalBackend.PrintPrompt(); } } } diff --git a/ShiftOS.WinForms/Controls/TerminalBox.cs b/ShiftOS.WinForms/Controls/TerminalBox.cs index 7c0da57..9e4c61c 100644 --- a/ShiftOS.WinForms/Controls/TerminalBox.cs +++ b/ShiftOS.WinForms/Controls/TerminalBox.cs @@ -24,6 +24,7 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.Linq; using System.Text; using System.Threading; @@ -56,16 +57,31 @@ namespace ShiftOS.WinForms.Controls { this.HideSelection = true; this.Select(this.TextLength, 0); + this.SelectionFont = ConstructFont(); this.SelectionColor = ControlManager.ConvertColor(ConsoleEx.ForegroundColor); this.SelectionBackColor = ControlManager.ConvertColor(ConsoleEx.BackgroundColor); this.AppendText(Localization.Parse(text)); this.HideSelection = false; } + private Font ConstructFont() + { + FontStyle fs = FontStyle.Regular; + if (ConsoleEx.Bold) + fs = fs | FontStyle.Bold; + if (ConsoleEx.Italic) + fs = fs | FontStyle.Italic; + if (ConsoleEx.Underline) + fs = fs | FontStyle.Underline; + + return new Font(this.Font, fs); + } + public void WriteLine(string text) { this.HideSelection = true; this.Select(this.TextLength, 0); + this.SelectionFont = ConstructFont(); this.SelectionColor = ControlManager.ConvertColor(ConsoleEx.ForegroundColor); this.SelectionBackColor = ControlManager.ConvertColor(ConsoleEx.BackgroundColor); this.AppendText(Localization.Parse(text) + Environment.NewLine); diff --git a/ShiftOS_TheReturn/ServerManager.cs b/ShiftOS_TheReturn/ServerManager.cs index 7da09f1..4d599cd 100644 --- a/ShiftOS_TheReturn/ServerManager.cs +++ b/ShiftOS_TheReturn/ServerManager.cs @@ -132,6 +132,7 @@ namespace ShiftOS.Engine { Console.WriteLine(acc); } + TerminalBackend.PrintPrompt(); } else if(msg.Name == "update_your_cp") { @@ -154,11 +155,15 @@ namespace ShiftOS.Engine { var ex = JsonConvert.DeserializeObject(msg.Contents); TerminalBackend.PrefixEnabled = true; + ConsoleEx.ForegroundColor = ConsoleColor.Red; + ConsoleEx.Bold = true; + Console.Write($@"{{MUD_ERROR}}: "); + ConsoleEx.Bold = false; + ConsoleEx.Italic = true; ConsoleEx.ForegroundColor = ConsoleColor.DarkYellow; - Console.WriteLine($@"{{MUD_ERROR}}: {ex.Message}"); - ConsoleEx.ForegroundColor = ConsoleColor.White; + Console.WriteLine(ex.Message); TerminalBackend.PrefixEnabled = true; - Console.Write($"{SaveSystem.CurrentSave.Username}@{CurrentSave.SystemName}:~$ "); + TerminalBackend.PrintPrompt(); } else { diff --git a/ShiftOS_TheReturn/TerminalBackend.cs b/ShiftOS_TheReturn/TerminalBackend.cs index f78d7a5..841fd6a 100644 --- a/ShiftOS_TheReturn/TerminalBackend.cs +++ b/ShiftOS_TheReturn/TerminalBackend.cs @@ -283,7 +283,39 @@ namespace ShiftOS.Engine } return false; } - + + public static void PrintPrompt() + { + ConsoleEx.Italic = false; + ConsoleEx.Underline = false; + + ConsoleEx.ForegroundColor = ConsoleColor.Magenta; + ConsoleEx.Bold = true; + Console.Write(SaveSystem.CurrentSave.Username); + ConsoleEx.Bold = false; + ConsoleEx.ForegroundColor = ConsoleColor.Gray; + Console.Write("@"); + ConsoleEx.Italic = true; + ConsoleEx.Bold = true; + ConsoleEx.ForegroundColor = ConsoleColor.Yellow; + Console.Write(SaveSystem.CurrentSave.SystemName); + ConsoleEx.Italic = false; + ConsoleEx.Bold = false; + ConsoleEx.ForegroundColor = ConsoleColor.Gray; + Console.Write(":~"); + Console.ForegroundColor = ConsoleColor.White; + ConsoleEx.Italic = true; + if (KernelWatchdog.InKernelMode == true) + Console.Write("#"); + else + Console.Write("$"); + ConsoleEx.Italic = false; + ConsoleEx.Bold = false; + ConsoleEx.ForegroundColor = ConsoleColor.White; + Console.Write(" "); + } + + static TerminalBackend() { ServerMessageReceived onMessageReceived = (msg) => -- cgit v1.2.3