Fix crash when resizing terminal

Bug report by doranchak
This commit is contained in:
ORelio 2015-04-11 12:30:36 +02:00
parent ea17ec87f1
commit 2cf46c0487

View file

@ -193,26 +193,36 @@ namespace MinecraftClient
writing_lock = true; writing_lock = true;
if (reading) if (reading)
{ {
string buf = buffer; try
string buf2 = buffer2;
ClearLineAndBuffer();
if (Console.CursorLeft == 0)
{ {
Console.CursorLeft = Console.BufferWidth - 1; string buf = buffer;
Console.CursorTop--; string buf2 = buffer2;
Console.Write(' '); ClearLineAndBuffer();
Console.CursorLeft = Console.BufferWidth - 1; if (Console.CursorLeft == 0)
Console.CursorTop--; {
Console.CursorLeft = Console.BufferWidth - 1;
Console.CursorTop--;
Console.Write(' ');
Console.CursorLeft = Console.BufferWidth - 1;
Console.CursorTop--;
}
else Console.Write("\b \b");
Console.Write(text);
buffer = buf;
buffer2 = buf2;
Console.Write(">" + buffer);
if (buffer2.Length > 0)
{
Console.Write(buffer2 + " \b");
for (int i = 0; i < buffer2.Length; i++) { GoBack(); }
}
} }
else Console.Write("\b \b"); catch (ArgumentOutOfRangeException)
Console.Write(text);
buffer = buf;
buffer2 = buf2;
Console.Write(">" + buffer);
if (buffer2.Length > 0)
{ {
Console.Write(buffer2 + " \b"); //Console resized: Try again
for (int i = 0; i < buffer2.Length; i++) { GoBack(); } Console.Write('\n');
writing_lock = false;
Write(text);
} }
} }
else Console.Write(text); else Console.Write(text);