Git Product home page Git Product logo

Comments (7)

scooley avatar scooley commented on July 17, 2024

I don't have time to fix this right now. It's on my backlog but in case someone finds time first, I'll add my discovery from a quick email to someone on PowerShell ISE:

"In the console, you have 16 colors via an enum System.ConsoleColor. The names in the enum are mere suggestions, they don’t reflect the user’s choice of RGB values.

For tools that must work in both the console and the ISE, I suggest sticking to using System.ConsoleColor instead of a real color type like System.Windows.Media.Color. You can map the ConsoleColor back to another color type as needed in host specific code, or you can stick with PowerShell cmdlets that only know about ConsoleColor (like Write-Host) and avoid host issues like this."

from virtualization-documentation.

daviwil avatar daviwil commented on July 17, 2024

The problem here is that the user cannot change the variable stored in the ISE host's PrivateData.ErrorForegroundColor variable:

PS C:\Users\daviwil> (Get-Host).PrivateData.ErrorForegroundColor = [System.ConsoleColor]::Red
Exception setting "ErrorForegroundColor": "Cannot convert value "Red" to type 
"System.Windows.Media.Color". Error: "Invalid cast from 'System.ConsoleColor' to 
'System.Windows.Media.Color'.""
At line:1 char:1
+ (Get-Host).PrivateData.ErrorForegroundColor = [System.ConsoleColor]:: ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], SetValueInvocationException
    + FullyQualifiedErrorId : ExceptionWhenSetting

This is definitely a consequence of the ISE using WPF colors, but this makes sense because the ISE's host needs to write output to a WPF control and the user has the ability to change these colors in their settings.

I'd recommend using Write-Error instead of writing errors in your own way. This will cause the right output color to be used in any PowerShell host regardless of what form it's stored in.

from virtualization-documentation.

janssenjones avatar janssenjones commented on July 17, 2024

I guess the bigger question is why any of the Write-W2Vxxxxxx functions even exist (Write-W2VError, Write-W2VTrace,Write-W2VWarning,Write-W2VInfo), rather than just using Write-Error, Write-Verbose, Write-Warning, and Write-Host. I was trying to look through to see if there was some sort of tee- or transcript-writing combo or something, but I didn't find the reasoning. It seems like a find/replace of Write-W2Vxxx with their native equivalents would remove the need for all of those functions.

from virtualization-documentation.

mebersol avatar mebersol commented on July 17, 2024

Agreed - these wrapper functions are historical artefacts. IIRC, Artem was going to work on this.

from virtualization-documentation.

mebersol avatar mebersol commented on July 17, 2024

@pronichkin will address this one

from virtualization-documentation.

pronichkin avatar pronichkin commented on July 17, 2024

Thanks Mike,

Pardon my ignorance, but I’m really new to all this GitHub stuff. Do I need to do something special to get access to this project? Or to be listed as an official Microsoft contributor?

From: Mike Ebersol [mailto:[email protected]]
Sent: Friday, February 12, 2016 10:22 PM
To: Microsoft/Virtualization-Documentation [email protected]
Cc: Artem Pronichkin [email protected]
Subject: Re: [Virtualization-Documentation] Convert-WindowsImage Write-W2VError doesn't work in ISE due to conversion of the color (#137)

@Pronichkinhttps://github.com/Pronichkin will address this one


Reply to this email directly or view it on GitHubhttps://github.com//issues/137#issuecomment-183456434.

from virtualization-documentation.

kallie-b avatar kallie-b commented on July 17, 2024

Closing issue due to lack of activity.

from virtualization-documentation.

Related Issues (20)

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.