nightroman / FarNet

Far Manager framework for .NET modules and scripts in PowerShell, F#, JavaScript.
https://github.com/nightroman/FarNet/wiki
BSD 3-Clause "New" or "Revised" License
136 stars 19 forks source link

PSF First output line is not colored #6

Closed nightroman closed 8 years ago

nightroman commented 8 years ago

PowerShellFar 5.2.3 Script Write-Red.ps1

    function Write-Red ($text) {
        $color = $host.UI.RawUI.ForegroundColor
        $host.UI.RawUI.ForegroundColor = 'Red'
        $text
        $host.UI.RawUI.ForegroundColor = $color
    }

    Write-Red 'must be red, it is not in PSF 5.2.3'
    Write-Red 'must be red, it is'

It is a generic PS script, not specific for Far. We can call it by powershell.exe

powershell.exe .\Write-Red.ps1

and it writes two red lines.

To make colored output, the script uses ForegroundColor instead of Write-Host -ForegroundColor .... This technique allows redirection of output, i.e. we can

powershell.exe .\Write-Red.ps1 > log.txt

and log.txt contains our two lines. This is not possible with Write-Host.

This technique of colored output is commonly used in PS, e.g. by

The problem

If we invoke the above script in PSF (or use the mentioned or similar tools in PSF):

ps: .\Write-Red.ps1

then the first line is not colored, as we expect.

The problem is caused by a known change in Far, to be discussed with its author.