Fix console background color

- Save & Restore background color when needed
- Remove useless color modifications
- Fix issue #71
This commit is contained in:
ORelio 2015-03-25 19:45:50 +01:00
parent aaced855d8
commit 82c95be611
2 changed files with 6 additions and 9 deletions

View file

@ -67,10 +67,13 @@ namespace MinecraftClient.ChatBots
if (ConsoleIO.basicIO) //Using a GUI? Pass text as is. if (ConsoleIO.basicIO) //Using a GUI? Pass text as is.
ConsoleIO.WriteLine(text.Replace(alert, "§c" + alert + "§r")); 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); string[] splitted = text.Split(new string[] { alert }, StringSplitOptions.None);
ConsoleColor fore = Console.ForegroundColor;
ConsoleColor back = Console.BackgroundColor;
if (splitted.Length > 0) if (splitted.Length > 0)
{ {
Console.BackgroundColor = ConsoleColor.DarkGray; Console.BackgroundColor = ConsoleColor.DarkGray;
@ -89,8 +92,8 @@ namespace MinecraftClient.ChatBots
} }
} }
Console.BackgroundColor = ConsoleColor.Black; Console.BackgroundColor = back;
Console.ForegroundColor = ConsoleColor.Gray; Console.ForegroundColor = fore;
ConsoleIO.Write('\n'); ConsoleIO.Write('\n');
} }
} }

View file

@ -193,8 +193,6 @@ namespace MinecraftClient
writing_lock = true; writing_lock = true;
if (reading) if (reading)
{ {
ConsoleColor fore = Console.ForegroundColor;
ConsoleColor back = Console.BackgroundColor;
string buf = buffer; string buf = buffer;
string buf2 = buffer2; string buf2 = buffer2;
ClearLineAndBuffer(); ClearLineAndBuffer();
@ -208,8 +206,6 @@ namespace MinecraftClient
} }
else Console.Write("\b \b"); else Console.Write("\b \b");
Console.Write(text); Console.Write(text);
Console.ForegroundColor = ConsoleColor.Gray;
Console.BackgroundColor = ConsoleColor.Black;
buffer = buf; buffer = buf;
buffer2 = buf2; buffer2 = buf2;
Console.Write(">" + buffer); Console.Write(">" + buffer);
@ -218,8 +214,6 @@ namespace MinecraftClient
Console.Write(buffer2 + " \b"); Console.Write(buffer2 + " \b");
for (int i = 0; i < buffer2.Length; i++) { GoBack(); } for (int i = 0; i < buffer2.Length; i++) { GoBack(); }
} }
Console.ForegroundColor = fore;
Console.BackgroundColor = back;
} }
else Console.Write(text); else Console.Write(text);
writing_lock = false; writing_lock = false;