From 82c95be611a68d1e14813651140a01d32220c6d4 Mon Sep 17 00:00:00 2001 From: ORelio Date: Wed, 25 Mar 2015 19:45:50 +0100 Subject: [PATCH] Fix console background color - Save & Restore background color when needed - Remove useless color modifications - Fix issue #71 --- MinecraftClient/ChatBots/Alerts.cs | 9 ++++++--- MinecraftClient/ConsoleIO.cs | 6 ------ 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/MinecraftClient/ChatBots/Alerts.cs b/MinecraftClient/ChatBots/Alerts.cs index b60a39ee..5cdff088 100644 --- a/MinecraftClient/ChatBots/Alerts.cs +++ b/MinecraftClient/ChatBots/Alerts.cs @@ -67,10 +67,13 @@ namespace MinecraftClient.ChatBots if (ConsoleIO.basicIO) //Using a GUI? Pass text as is. ConsoleIO.WriteLine(text.Replace(alert, "§c" + alert + "§r")); - else //Using Consome Prompt : Print text with alert highlighted + else //Using Console Prompt : Print text with alert highlighted { string[] splitted = text.Split(new string[] { alert }, StringSplitOptions.None); + ConsoleColor fore = Console.ForegroundColor; + ConsoleColor back = Console.BackgroundColor; + if (splitted.Length > 0) { Console.BackgroundColor = ConsoleColor.DarkGray; @@ -89,8 +92,8 @@ namespace MinecraftClient.ChatBots } } - Console.BackgroundColor = ConsoleColor.Black; - Console.ForegroundColor = ConsoleColor.Gray; + Console.BackgroundColor = back; + Console.ForegroundColor = fore; ConsoleIO.Write('\n'); } } diff --git a/MinecraftClient/ConsoleIO.cs b/MinecraftClient/ConsoleIO.cs index f73514a5..ac627c28 100644 --- a/MinecraftClient/ConsoleIO.cs +++ b/MinecraftClient/ConsoleIO.cs @@ -193,8 +193,6 @@ namespace MinecraftClient writing_lock = true; if (reading) { - ConsoleColor fore = Console.ForegroundColor; - ConsoleColor back = Console.BackgroundColor; string buf = buffer; string buf2 = buffer2; ClearLineAndBuffer(); @@ -208,8 +206,6 @@ namespace MinecraftClient } else Console.Write("\b \b"); Console.Write(text); - Console.ForegroundColor = ConsoleColor.Gray; - Console.BackgroundColor = ConsoleColor.Black; buffer = buf; buffer2 = buf2; Console.Write(">" + buffer); @@ -218,8 +214,6 @@ namespace MinecraftClient Console.Write(buffer2 + " \b"); for (int i = 0; i < buffer2.Length; i++) { GoBack(); } } - Console.ForegroundColor = fore; - Console.BackgroundColor = back; } else Console.Write(text); writing_lock = false;