Skip to content

Change the behavior of Out-File and Out-String regarding $PSStyle.OutputRendering #8892

@daxian-dbw

Description

@daxian-dbw

Prerequisites

  • Write a descriptive title.
  • Search the existing issues.

Summary of the new feature or changed behavior

The issue: PowerShell/PowerShell#17452
The PR: PowerShell/PowerShell#17455

The changes in this PR update the behavior of Out-File and Out-String regarding the RenderingOutput setting to be the following:

  • when the input object is pure string, these 2 cmdlets keep the string input unchanged regardless of the RenderingOutput setting
  • when the input object needs to have formatting views applied to it, these 2 cmdlets remove escape sequences from the formatting output strings based on the RenderingOutput setting.

List of articles that need to be updated

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_ansi_terminals?view=powershell-7.2, more specifically, the section about OutputRendering enum.

We should call out that $PSStyle.OutputRendering affect formatting and text rendering on console screen, but it doesn't affect other scenarios. Example, $PSStyle.Foreground.Red + "abc" + $PSStyle.Reset | % { $_.Length } returns 12 regardless of $PSStyle.OutputRendering.

Out-File and Out-String respect $PSStyle.OutputRendering when the piped-in object needs to be applied with formatting views. Otherwise, it keeps the escape sequences regardless of $PSStyle.OutputRendering, such as when the piped-in object are pure strings.

Link to related PR in PowerShell/PowerShell repo

Link to related Issues in PowerShell/PowerShell repo

Metadata

Metadata

Assignees

Labels

area-aboutArea - About_ topicsarea-utilityArea - Microsoft.PowerShell.Utility moduleissue-doc-ideaIssue - request for new content

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions