Fix formatting and output when stdout is redirected
This commit is contained in:
parent
fa86c89925
commit
44028f0da3
|
@ -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);
|
||||
|
||||
/// <summary>
|
||||
/// 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); }
|
||||
}
|
||||
|
|
|
@ -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<string> lines = WrapText(text, RawUI.WindowSize.Width - 1);
|
||||
List<string> lines = WrapText(text, RawUI.BufferSize.Width - 1);
|
||||
int count = 0;
|
||||
foreach (string s in lines)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue