diff --git a/PSWriteColor.psd1 b/PSWriteColor.psd1 index fa3464e..97b770e 100644 --- a/PSWriteColor.psd1 +++ b/PSWriteColor.psd1 @@ -8,7 +8,7 @@ Description = 'Write-Color is a wrapper around Write-Host allowing you to create nice looking scripts, with colorized output. It provides easy manipulation of colors, logging output to file (log) and nice formatting options out of the box.' FunctionsToExport = 'Write-Color' GUID = '0b0ba5c5-ec85-4c2b-a718-874e55a8bc3f' - ModuleVersion = '1.0.6' + ModuleVersion = '1.0.7' PowerShellVersion = '5.1' PrivateData = @{ PSData = @{ diff --git a/Public/Write-Color.ps1 b/Public/Write-Color.ps1 index 9e29f96..2785d11 100644 --- a/Public/Write-Color.ps1 +++ b/Public/Write-Color.ps1 @@ -179,7 +179,7 @@ function Write-Color { $TextToFile = $Text -join '' # Handle Ignore at this boundary: Windows PowerShell 5.1 cannot pass an inherited # Ignore preference through to nested Write-Host calls. - $SuppressConsole = $NoConsoleOutput -or $PSBoundParameters['InformationAction'] -eq [System.Management.Automation.ActionPreference]::Ignore + $SuppressConsole = $NoConsoleOutput -or $PSBoundParameters['InformationAction'] -eq [System.Management.Automation.ActionPreference]::Ignore -or $InformationPreference -eq [System.Management.Automation.ActionPreference]::Ignore if (-not $NoConsoleOutput -and $OutputStream -ne 'Host') { $Message = $TextToFile if ($ShowTime) { diff --git a/Tests/Write-Color.Streams.Tests.ps1 b/Tests/Write-Color.Streams.Tests.ps1 index 7e3e4b8..1c10a79 100644 --- a/Tests/Write-Color.Streams.Tests.ps1 +++ b/Tests/Write-Color.Streams.Tests.ps1 @@ -8,6 +8,25 @@ BeforeAll { } Describe 'Write-Color message streams' { + It 'honors inherited information suppression for without losing file logs' -ForEach @( + @{ Stream = 'Host' }, @{ Stream = 'Information' } + ) { + $log = Join-Path $TestDrive "$Stream-inherited.log" + $records = @(& (Get-Module PSWriteColor) { + param($Stream, $LogPath) + function Invoke-NestedColor { + [CmdletBinding()] + param($Stream, $LogPath) + Write-Color 'one', 'two' -OutputStream $Stream -LogFile $LogPath -LogTime $false + } + Invoke-NestedColor -Stream $Stream -LogPath $LogPath -InformationAction Ignore *>&1 + } $Stream $log) + $records.Count | Should -Be 0 + Get-Content -LiteralPath $log | Should -BeExactly 'onetwo' + $after = @(Write-Color 'visible' -InformationAction Continue 6>&1) + ($after.MessageData.Message -join '') | Should -Match 'visible' + } + It 'emits one plain success string without enabling diagnostic preferences' { $records = @(Write-Color 'one', 'two' -OutputStream Output -Verbose:$false -InformationAction Ignore *>&1) $records.Count | Should -Be 1