diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs index 950b240f41..888f454ded 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs @@ -1545,6 +1545,9 @@ namespace Microsoft.PowerShell set { Console.BackgroundColor = value; } } + // TODO: Make wrap width user-customizable. + private static Size WrapSize = new Size(80, 40); + /// /// Gets or sets the size of the host buffer. In this example the /// buffer size is adapted from the Console buffer size members. @@ -1553,19 +1556,17 @@ namespace Microsoft.PowerShell { get { - try + // When stdout is redirected, the buffer size is (0, 0); + // however, this is still queried for use in formatting, so we + // provide the WrapSize. + if (Console.IsOutputRedirected) + { + return WrapSize; + } + else { 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); } } diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs index a685772f3e..7106b101f8 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs @@ -1148,7 +1148,7 @@ namespace Microsoft.PowerShell // we leave a 1-cell margin on the end because if the very last character butts up against the // edge of the screen buffer, then the console will wrap the line. - List lines = WrapText(text, RawUI.WindowSize.Width - 1); + List lines = WrapText(text, RawUI.BufferSize.Width - 1); int count = 0; foreach (string s in lines) {