aboutsummaryrefslogtreecommitdiff
path: root/internal/admin/xterm_to_css.go
blob: 6c1fda40c97284661e55fce06305767c7b028882 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package admin

import (
	"fmt"
	"strconv"
	"strings"

	"thehouseoficarus/internal/color"
)

func XtermToCSS(xtermHex string) string {
	xtermHex = strings.TrimPrefix(xtermHex, "#")
	idx, err := strconv.ParseUint(xtermHex, 16, 8)
	if err != nil || idx > 255 {
		return "#808080"
	}
	r, g, b := color.Xterm256ToRGB(int(idx))
	return fmt.Sprintf("#%02x%02x%02x", r, g, b)
}

func XtermColorForCSS(idx int) string {
	if idx < 0 || idx > 255 {
		return "#808080"
	}
	r, g, b := color.Xterm256ToRGB(idx)
	return fmt.Sprintf("#%02x%02x%02x", r, g, b)
}