From 7938b2481501eece95dbe3453c9d670b2075ac0d Mon Sep 17 00:00:00 2001 From: Ilya Date: Fri, 20 Mar 2020 20:34:05 +0500 Subject: [PATCH 1/4] Remove extra line before formatting group --- .../common/BaseFormattingCommand.cs | 21 +++++++++++++++++++ .../common/BaseOutputtingCommand.cs | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/System.Management.Automation/FormatAndOutput/common/BaseFormattingCommand.cs b/src/System.Management.Automation/FormatAndOutput/common/BaseFormattingCommand.cs index bb6e6cb50aa..5f81da9de5f 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/BaseFormattingCommand.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/BaseFormattingCommand.cs @@ -262,6 +262,9 @@ private void ProcessObject(PSObject so) } else if (transition == GroupTransition.startNew) { + // Add newline before each group except first + WriteNewLineObject(); + // double transition PopGroup(); // exit the current one PushGroup(so); // start a sibling group @@ -273,6 +276,24 @@ private void ProcessObject(PSObject so) } } + private void WriteNewLineObject() + { + FormatEntryData fed = new FormatEntryData(); + fed.outOfBand = true; + + ComplexViewEntry cve = new ComplexViewEntry(); + FormatEntry fe = new FormatEntry(); + cve.formatValueList.Add(fe); + + // Formating system writes newline before each object + // so no need to add newline here like: + // fe.formatValueList.Add(new FormatNewLine()); + + fed.formatEntryInfo = cve; + + this.WriteObject(fed); + } + private bool ShouldProcessOutOfBand { get diff --git a/src/System.Management.Automation/FormatAndOutput/common/BaseOutputtingCommand.cs b/src/System.Management.Automation/FormatAndOutput/common/BaseOutputtingCommand.cs index 5025fc6c381..0a6c04b8b52 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/BaseOutputtingCommand.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/BaseOutputtingCommand.cs @@ -476,7 +476,7 @@ private void ProcessGroupStart(FormatMessagesContextManager.OutputContext c) if (goc.Data.groupingEntry != null) { - _lo.WriteLine(string.Empty); + //_lo.WriteLine(string.Empty); ComplexWriter writer = new ComplexWriter(); writer.Initialize(_lo, _lo.ColumnNumber); From cb6872625abd07bfb25252108d5d3ca5a44e5554 Mon Sep 17 00:00:00 2001 From: Ilya Date: Fri, 20 Mar 2020 20:36:28 +0500 Subject: [PATCH 2/4] Remove commented code --- .../FormatAndOutput/common/BaseOutputtingCommand.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/System.Management.Automation/FormatAndOutput/common/BaseOutputtingCommand.cs b/src/System.Management.Automation/FormatAndOutput/common/BaseOutputtingCommand.cs index 0a6c04b8b52..7fe2126d296 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/BaseOutputtingCommand.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/BaseOutputtingCommand.cs @@ -476,8 +476,6 @@ private void ProcessGroupStart(FormatMessagesContextManager.OutputContext c) if (goc.Data.groupingEntry != null) { - //_lo.WriteLine(string.Empty); - ComplexWriter writer = new ComplexWriter(); writer.Initialize(_lo, _lo.ColumnNumber); writer.WriteObject(goc.Data.groupingEntry.formatValueList); From 71355f4cf28a6744bc8d497228fd4060c0d8c778 Mon Sep 17 00:00:00 2001 From: Ilya Date: Fri, 20 Mar 2020 20:38:58 +0500 Subject: [PATCH 3/4] Fix CodeFactor issue --- .../FormatAndOutput/common/BaseFormattingCommand.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/System.Management.Automation/FormatAndOutput/common/BaseFormattingCommand.cs b/src/System.Management.Automation/FormatAndOutput/common/BaseFormattingCommand.cs index 5f81da9de5f..ffccf13f4e1 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/BaseFormattingCommand.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/BaseFormattingCommand.cs @@ -288,7 +288,6 @@ private void WriteNewLineObject() // Formating system writes newline before each object // so no need to add newline here like: // fe.formatValueList.Add(new FormatNewLine()); - fed.formatEntryInfo = cve; this.WriteObject(fed); From 76b436b5f49fdef6fa8badb65fa3bc73c58ac98f Mon Sep 17 00:00:00 2001 From: Ilya Date: Fri, 20 Mar 2020 22:19:33 +0500 Subject: [PATCH 4/4] Modify tests --- .../Microsoft.PowerShell.Utility/Format-Custom.Tests.ps1 | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Custom.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Custom.Tests.ps1 index 75aece4546c..cfee43bf931 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Custom.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Custom.Tests.ps1 @@ -397,7 +397,6 @@ Describe "Format-Custom with expression based EntrySelectedBy in a CustomControl $ps.Streams.Error.Clear() $expectedOutput = @' - Entry selected by property Name @@ -424,7 +423,6 @@ testing $ps.Streams.Error.Clear() $expectedOutput = @' - Entry selected by ScriptBlock Name