Retain color from the outlet on the pipeline

I have this extremely simple powershell script that adds each line to a number.

function number
{    
    $i = 0;
    foreach($line in $input)
    {
        [string]$i + ":" + $line
        ++$i
    }
}

I would like this function to preserve input colors. For example, if I execute the following command, colors are lost:

git status -s | number

While doing

git status -s

Gives me beautiful products. What can I change in my powershell function to accomplish this.

Note. I already tried telling git to always output colors with information in the answers to this question , so I think my side is that ignores the colors.

This is not a duplicate of a question that was previously marked as a duplicate .

, , MSBuild , . , , . ( HTML) , , .

+4
3

, git status -s , PowerShell StdIn. , PowerShell StdIn, "".

, , - RegEx , Write-Host "line section" -ForegroundColor COLOR -NoNewline .

System.IO.StreamReader StdIn. [Console]::In | Get-Member PowerShell/ISE.

+3

o/p [Host - ]. Write-Host, " " "", .

0
  • ( ), , , stdout (), , .

    • , , ( ).
  • , IF, .

PowerShell , - , git, .

PS> git -c color.status=always status -b --short | % { $i=0 } { "$((++$i)): $_" }
1: ## master

The word master(or any branch is active) should be displayed in green.

The answer from which the method was obtained has been -c color.status=alwaysupdated since it was bound to it, so I suspect that the earlier form is simply not effective for forcing unconditional color output.

0
source

Source: https://habr.com/ru/post/1653110/


All Articles