updating code already written, I need help for triple loops ForEach-Object to varie 3 variables

  Kiến thức lập trình

PowerShell

Link to original code text

here my code :

FUNCTION NEW-ANSIBAR-16M
{
    [cmdletbinding()]
    PARAM (
            [PARAMETER(Mandatory, HelpMessage = "Enter a range of 16M color values, e.g. (1..255)")]
            [VALIDATENOTNULLOREMPTY()]
            [int[]]
            $RANGE_R,
            [int[]]
            $RANGE_G,
            [int[]]
            $RANGE_B,
            [Parameter(HelpMessage = "How many spaces do you want in the bar? This will increase the length of the bar.")]
            [int]
            $Spacing = 1
    )
    $ESC = "$([CHAR]0X1b)"
    $OUT = @()
    $BLANK = " " * $Spacing
    $out += $RANGE_R | ForEach-Object {         # ◄--- I need to include $Range_G and $Range_B.
        "$esc[48;2;$($_);$($_);$($_);1m$($blank)$esc[0m" 

        # now it's in shades of gray because it's still the same variable for the other 2 values ?

    }
    $OUT -JOIN ""
    
}

NEW-ANSIBAR-16M -RANGE_R (1..255) -RANGE_G (100..150) -RANGE_B (100..150) -Spacing 1 

Should I try iteratively ?
Or is there another way to do it ?

I tried with others ForEach-Object but it gave errors.

Thank you very much !

1

LEAVE A COMMENT