From fbc794b9331be5eb6d74553d98ab5b0071e9a479 Mon Sep 17 00:00:00 2001 From: Andy Schwartzmeyer Date: Thu, 12 May 2016 11:59:42 -0700 Subject: [PATCH] Guard BufferSize for improper terminals --- .../host/msh/ConsoleHostRawUserInterface.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs index 9c4d087121..950b240f41 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs @@ -1551,7 +1551,22 @@ namespace Microsoft.PowerShell /// public override Size BufferSize { - get { return new Size(Console.BufferWidth, Console.BufferHeight); } + get + { + try + { + return new Size(Console.BufferWidth, Console.BufferHeight); + } + catch (System.IO.IOException) + { + // When running without a proper terminal (like on AppVeyor) + // the above will throw because there is no available buffer + // information, so we make a good guess here (since this + // size is mostly used for formatting, this lets wrapping + // work well). + return new Size(80, 80); + } + } set { Console.SetBufferSize(value.Width, value.Height); } }