From b67d765b3a8e151b7d60492fae2474da9f1890f6 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Tue, 17 May 2016 12:10:45 -0700 Subject: [PATCH] Use WrapSize for WindowSize when unavailable --- .../host/msh/ConsoleHostRawUserInterface.cs | 12 +++++++++++- .../host/msh/ConsoleHostUserInterface.cs | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs index 333435781..79b390d04 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs @@ -1653,7 +1653,17 @@ namespace Microsoft.PowerShell /// public override Size WindowSize { - get { return new Size(Console.WindowWidth, Console.WindowHeight); } + get + { + if (Console.IsOutputRedirected) + { + return WrapSize; + } + else + { + return new Size(Console.WindowWidth, Console.WindowHeight); + } + } set { Console.SetWindowSize(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 9c7333ca8..90893506f 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.BufferSize.Width - 1); + List lines = WrapText(text, RawUI.WindowSize.Width - 1); int count = 0; foreach (string s in lines) {