spectre.console icon indicating copy to clipboard operation
spectre.console copied to clipboard

Added hex color conversion

Open jsheely opened this issue 1 year ago • 10 comments

Solves issue https://github.com/spectreconsole/spectre.console/issues/1354

I'm not sure if this is desired but seemed like an easy quality of life feature to allow hex to rgb for creating colors.


Please upvote :+1: this pull request if you are interested in it.

jsheely avatar Jan 15 '24 02:01 jsheely

  • I think public static Color.FromHex(string hex) would be a more desirable approach here from an API perspective.

I'd vote for a combination of public static Color ParseHex(string hex) and public static bool TryParseHex(string hex, out Color color)

nils-a avatar Jan 16 '24 15:01 nils-a

We use "ToHex" so "FromHex" and "TryFromHex" is more consistent API wise

patriksvensson avatar Jan 16 '24 15:01 patriksvensson

It looks like hex[2..4] is not supported in netstandard 2.0

FrankRay78 avatar Jan 18 '24 16:01 FrankRay78

Unfortunately, the build still breaks @jsheely - see the build log above, looks like simple char/string conversion error. Want to update and push again?

FrankRay78 avatar Jan 19 '24 08:01 FrankRay78

Thank you @jsheely, if no one else gets to it first, I'll review (and hopefully merge) your PR this week.

FrankRay78 avatar Jan 20 '24 17:01 FrankRay78

Dear @patriksvensson, I have rebased this branch, implemented full unit test coverage for both happy and unhappy paths, and ensured the failure to parse an invalid colour raises a FormatException with (what seems to me) to be a reasonable message.

I think it's suitable for merging, please re-review when you can.

FrankRay78 avatar Mar 20 '24 12:03 FrankRay78

Do we want to support the short-hands for hex values? (E.g. using #a1b instead of #aa11bb)

nils-a avatar May 30 '24 12:05 nils-a

Do we want to support the short-hands for hex values? (E.g. using #a1b instead of #aa11bb)

You tell me @nils-a 😉, as someone who would like to merge this PR for me... I'm happy to implement the short color code if you'd like.

This (seemingly trivial) PR has been hanging around for too long for my liking.

FrankRay78 avatar Jul 31 '24 11:07 FrankRay78

This (seemingly trivial) PR has been hanging around for too long for my liking.

Agreed. Let's use it as it is.

@patriksvensson I feel your requested changes were addressed, right?

nils-a avatar Jul 31 '24 21:07 nils-a

I'm pretty sure you want to merge this PR @nils-a . Remember that really nice, warm fuzzy feeling from doing so? It's waiting.

FrankRay78 avatar Aug 15 '24 20:08 FrankRay78