Giter Site home page Giter Site logo

Comments (8)

PrzemyslawKlys avatar PrzemyslawKlys commented on June 13, 2024

Well, I just did a small test

Write-Color test,test -Color Red,Yellow
Write-Color test,test2 -Color Red,Yellow,White
Write-Color test,test

All works fine. The error on your screen says "Cannot proces the color because -1 is not a valid color". Maybe you're passing Color as variables or something? Alternatively, provide some test case that fails?

from pswritecolor.

EricZimmerman avatar EricZimmerman commented on June 13, 2024

from pswritecolor.

PrzemyslawKlys avatar PrzemyslawKlys commented on June 13, 2024

On MacOS

(get-host).ui.rawui  

returns -1 for foregroundcolor and for bacckgroundcolor, hence your problem.

Also why would you need Write-Color if you're using Write-Host all over the place ?:-)

Write-Host ""
Write-Host "This script will discover and download all available programs" -BackgroundColor Blue
Write-Host "from https://ericzimmerman.github.io and download them to $Dest" -BackgroundColor Blue
Write-Host "`nA file will also be created in $Dest that tracks the SHA-1 of each file,"
Write-Host "so rerunning the script will only download new versions."
Write-Host "`nTo redownload, remove lines from or delete the CSV file created under $Dest and rerun. Enjoy!`n"

Could be replaced with:

Write-Color "This script will discover and download all available programs" -BackgroundColor Blue
Write-Color "from https://ericzimmerman.github.io and download them to $Dest" -BackgroundColor Blue -LinesAfter 1
Write-Color  "A file will also be created in $Dest that tracks the SHA-1 of each file,"
Write-Color "so rerunning the script will only download new versions."
Write-Color -LinesBefore 1 -Text "To redownload, remove lines from or delete the CSV file created under $Dest and rerun. Enjoy!" -LinesAfter 1

Also it's Gray not Grey, maybe that's why?

from pswritecolor.

PrzemyslawKlys avatar PrzemyslawKlys commented on June 13, 2024

Also

Write-Host ""
write-color -Text "* ", "Saving downloaded version information to $localDetailsFile" -Color Green,Red
Write-host "`n"

Can be replaced with single line:

write-color -Text "* ", "Saving downloaded version information to $localDetailsFile" -Color Green,Red -LinesBefore 1 -LinesAfter 1

from pswritecolor.

EricZimmerman avatar EricZimmerman commented on June 13, 2024

from pswritecolor.

EricZimmerman avatar EricZimmerman commented on June 13, 2024

from pswritecolor.

PrzemyslawKlys avatar PrzemyslawKlys commented on June 13, 2024
$TestColor = (Get-Host).ui.rawui.ForegroundColor
if ($TestColor -eq -1) {
    $defaultColor = [ConsoleColor]::Gray
} else {
    $defaultColor = $TestColor
}

The only thing that comes to my mind is that the user didn't save it properly. The -1 had to come from somewhere and that's the only place I see. The other reason would be that you were trying to save Gray color to $TestColor which was -1 and type of int at that point. You can try above and see if it works.

from pswritecolor.

EricZimmerman avatar EricZimmerman commented on June 13, 2024

i found it strange the mac set the colors to -1 at all. i will test out the code and finish porting the write-host calls. thanks for your help and nice function

from pswritecolor.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.