Comments (8)
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.
from pswritecolor.
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.
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.
from pswritecolor.
from pswritecolor.
$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.
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)
- Default alias of wc will interfere with wc command on *nix systems HOT 2
- NuGet package does not install properly (v.0.85.0) HOT 4
- Doesn't seem to accept parameters when passed HOT 9
- request: support multiline split with separator HOT 2
- Output is multiple line in transcript HOT 2
- Transcript with Write-Color HOT 1
- write-color transcript output showing up on different lines HOT 1
- Improvment HOT 1
- Enhancement - Added PadLeft; PadCenter; PadRight; and PadCharacter Parameters to Write-Color Function HOT 3
- Extra Spaces in Log Files HOT 1
- show text like a progressbar HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pswritecolor.