summaryrefslogtreecommitdiff
path: root/internal/colors/precise.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/colors/precise.go')
-rw-r--r--internal/colors/precise.go18
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,
+ )
+}