mirror of
https://github.com/rwinkhart/glamour-temp-MUTN.git
synced 2026-09-06 08:57:14 -04:00
Support 24bit color space in terminals with support
Currently supported by xterm, Konsole, gnome Terminal, VTE, iTerm2.
This commit is contained in:
@@ -2,10 +2,13 @@ package gold
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/logrusorgru/aurora"
|
"github.com/logrusorgru/aurora"
|
||||||
|
"github.com/lucasb-eyer/go-colorful"
|
||||||
bf "gopkg.in/russross/blackfriday.v2"
|
bf "gopkg.in/russross/blackfriday.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -28,11 +31,36 @@ func color(c string) (uint8, error) {
|
|||||||
return uint8(i), err
|
return uint8(i), err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func colorSeq(c string) (string, error) {
|
||||||
|
if len(c) == 0 {
|
||||||
|
return "", errors.New("Invalid color")
|
||||||
|
}
|
||||||
|
|
||||||
|
col, err := colorful.Hex(c)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("%d;%d;%dm", uint8(col.R*255), uint8(col.G*255), uint8(col.B*255)), nil
|
||||||
|
}
|
||||||
|
|
||||||
func renderText(w io.Writer, rules *ElementStyle, s string) {
|
func renderText(w io.Writer, rules *ElementStyle, s string) {
|
||||||
if len(s) == 0 {
|
if len(s) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: ugly hack
|
||||||
|
if os.Getenv("COLORTERM") == "truecolor" {
|
||||||
|
bg, err := colorSeq(rules.BackgroundColor)
|
||||||
|
if err == nil {
|
||||||
|
s = "\x1b[48;2;" + bg + s
|
||||||
|
}
|
||||||
|
fg, err := colorSeq(rules.Color)
|
||||||
|
if err == nil {
|
||||||
|
s = "\x1b[38;2;" + fg + s
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
out := aurora.Reset(s)
|
out := aurora.Reset(s)
|
||||||
|
|
||||||
if rules != nil {
|
if rules != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user