Skip to content

Commit

Permalink
Support conversion to a StyledStrings.SimpleColor (#293)
Browse files Browse the repository at this point in the history
This enables easy interoperability with the Face constructor of
StyledStrings.
  • Loading branch information
tecosaur authored Oct 30, 2023
1 parent dba9e62 commit 808a60f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@ version = "0.12.0-dev"
FixedPointNumbers = "53c48c17-4a7d-5ca2-90c5-79b7896eea93"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[weakdeps]
StyledStrings = "f489334b-da3d-4c2e-b8f0-e476e12c162b"

[extensions]
StyledStringsExt = "StyledStrings"

[compat]
FixedPointNumbers = "0.5, 0.6, 0.7, 0.8"
StyledStrings = "1"
julia = "1"

[extras]
Expand Down
14 changes: 14 additions & 0 deletions ext/StyledStringsExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module StyledStringsExt

using ColorTypes
import StyledStrings: SimpleColor

function Base.convert(::Type{SimpleColor}, c::Colorant)
rgb = convert(RGB24, c)
r = reinterpret(red(rgb))
g = reinterpret(green(rgb))
b = reinterpret(blue(rgb))
SimpleColor((; r, g, b))
end

end

0 comments on commit 808a60f

Please sign in to comment.