Skip to content

Commit a7a4929

Browse files
authored
Remove the extra new line form List formatting (PowerShell#18185)
1 parent d9d6b7f commit a7a4929

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/System.Management.Automation/FormatAndOutput/common/BaseOutputtingCommand.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -456,9 +456,16 @@ private void ProcessFormatStart(FormatMessagesContextManager.OutputContext c)
456456
/// <param name="c">Current context, with Fs in it.</param>
457457
private void ProcessFormatEnd(FormatEndData fe, FormatMessagesContextManager.OutputContext c)
458458
{
459-
// Console.WriteLine("ProcessFormatEnd");
460-
// we just add an empty line to the display
461-
this.LineOutput.WriteLine(string.Empty);
459+
if (c is FormatOutputContext foContext
460+
&& foContext.Data.shapeInfo is ListViewHeaderInfo)
461+
{
462+
// Skip writing out a new line for List view, because we already wrote out
463+
// an extra new line after displaying the last list entry.
464+
return;
465+
}
466+
467+
// We just add an empty line to the display.
468+
LineOutput.WriteLine(string.Empty);
462469
}
463470

464471
/// <summary>

test/powershell/Modules/Microsoft.PowerShell.Utility/Format-List.Tests.ps1

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Describe "Format-List" -Tags "CI" {
3737
}
3838

3939
It "Should produce the expected output" {
40-
$expected = "${nl}testName : testValue${nl}${nl}${nl}"
40+
$expected = "${nl}testName : testValue${nl}${nl}"
4141
$in = New-Object PSObject
4242
Add-Member -InputObject $in -MemberType NoteProperty -Name testName -Value testValue
4343

@@ -201,7 +201,6 @@ dbda : KM
201201
消息 : 千
202202
203203
204-
205204
"@
206205
$expected = $expected -replace "`r`n", "`n"
207206

@@ -224,7 +223,6 @@ float : 9876.543
224223
decimal : 4567.123456789
225224
226225
227-
228226
"@
229227

230228
$actual = $o | Format-List | Out-String

0 commit comments

Comments
 (0)