Skip to content

Commit

Permalink
adds background hex colors
Browse files Browse the repository at this point in the history
  • Loading branch information
donuts-are-good authored May 17, 2023
1 parent 4623c70 commit de6c0dd
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions colors.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,35 @@ func Hex(hexColor string) string {
return fmt.Sprintf("\033[38;2;%d;%d;%dm", r, g, b)
}

func BGHex(hexColor string) string {
hexColor = strings.TrimPrefix(hexColor, "#")

if len(hexColor) != 3 && len(hexColor) != 6 {
return ""
}

if len(hexColor) == 3 {
hexColor = strings.Repeat(string(hexColor[0]), 2) + strings.Repeat(string(hexColor[1]), 2) + strings.Repeat(string(hexColor[2]), 2)
}

r, err := strconv.ParseInt(hexColor[0:2], 16, 64)
if err != nil {
return ""
}

g, err := strconv.ParseInt(hexColor[2:4], 16, 64)
if err != nil {
return ""
}

b, err := strconv.ParseInt(hexColor[4:6], 16, 64)
if err != nil {
return ""
}

return fmt.Sprintf("\033[48;2;%d;%d;%dm", r, g, b)
}

func HexGradient(startColor, endColor, input string) string {
if len(input) == 0 {
return ""
Expand Down

0 comments on commit de6c0dd

Please sign in to comment.