Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lookup HtmlColors before ConsoleColors #536

Merged
merged 2 commits into from
Jan 18, 2018

Conversation

rkeithhill
Copy link
Collaborator

@rkeithhill rkeithhill commented Jan 18, 2018

Turns out ConsoleColors are a lot easier to specify than HtmlColors (that happen to match ConsoleColor names).

Add PSEdition_Core tag so that posh-git shows up if someone searches for that tag - https://www.powershellgallery.com/items?q=tags%3Apsedition_core&x=0&y=0

Turns out ConsoleColors are a lot easier to specify than HtmlColors (that happen to match ConsoleColor names).

Add PSEdition_Core tag so that posh-git shows up if someone searches for that tag - https://www.powershellgallery.com/items?q=tags%3Apsedition_core&x=0&y=0
$color = $ColorTranslatorType::FromHtml($color)
}
elseif ($null -ne ($color -as [System.ConsoleColor])) {
$color = [System.ConsoleColor]$color
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the anti-pattern of converting twice - you should either use -as or the cast, but not both.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, caught me being lazy but at least we fixed the bug where [System.ConsoleColor]::Black (value of 0) was not registering as a ConsoleColor. :-)

Actually this found a bit of a corner case issue where a string that was not a valid HTML color name BUT a valid ConsoleColor name (DarkYellow) wouldn't work because we blew by the ConsoleColor code straight to the catch.
@dahlbyk dahlbyk merged commit 46c47d7 into develop Jan 18, 2018
@dahlbyk dahlbyk deleted the rkeithhill/reorder-clr-lookup branch January 18, 2018 09:02
@dahlbyk dahlbyk added this to the v1.0 milestone Apr 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants