diff options
author | Benjamin Chaussé <Benjamin.Chausse@goto.com> | 2024-12-16 13:34:44 -0500 |
---|---|---|
committer | Benjamin Chaussé <Benjamin.Chausse@goto.com> | 2024-12-16 13:34:44 -0500 |
commit | 53d7cbf983420753e83a22e24aa8d19f413f3ff3 (patch) | |
tree | 7db38fe9d4ea4fc92237cfcc8c7a4d59749ac9e5 /internal/colors | |
parent | 7938c2926338526390624a1f9004f6ad2699cd2b (diff) |
Copy hex escape sequences directlyesc-seq
Diffstat (limited to 'internal/colors')
-rw-r--r-- | internal/colors/precise.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/internal/colors/precise.go b/internal/colors/precise.go index a58d7c5..a84e629 100644 --- a/internal/colors/precise.go +++ b/internal/colors/precise.go @@ -6,6 +6,8 @@ import ( "strings" ) +const esc = "\\X1B" + type ColorSpace interface { ToPrecise() PreciseColor FromPrecise(PreciseColor) ColorSpace @@ -40,3 +42,19 @@ func Hex(cs ColorSpace) string { int(math.Round(p.B*255)), )) } + +func EscapedSeq(cs ColorSpace, fg bool) string { + p := cs.ToPrecise() + mod := 38 // fg by default + if !fg { + mod += 10 + } + + r := int(math.Round(p.R * 255)) + g := int(math.Round(p.G * 255)) + b := int(math.Round(p.B * 255)) + + return fmt.Sprintf("%s[%d;2;%d;%d;%dm", + esc, mod, r, g, b, + ) +} |