Skip to content

Commit

Permalink
feat(color): add support to xterm 256 colors.
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMarble committed Mar 10, 2022
1 parent adb9048 commit a70eeab
Show file tree
Hide file tree
Showing 3 changed files with 383 additions and 26 deletions.
33 changes: 7 additions & 26 deletions pkg/color/color.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,19 @@ import (
"github.com/hinshun/vt10x"
)

//nolint
var ansiColors = []string{
"#000000", // Black
"#800000", // Red
"#008000", // Green
"#808000", // Yellow
"#000080", // Blue
"#800080", // Magent
"#008080", // Cyan
"#c0c0c0", // Grey

"#808080", // Dark Grey
"#ff0000", // Light Red
"#00ff00", // Light Green
"#ffff00", // Light Yellow
"#0000ff", // Light Blue
"#ff00ff", // Light Magent
"#00ffff", // Light Cyan
"#ffffff", // White
}

func ansiToColor(ansi uint32) string {
return ansiColors[ansi]
}
//go:generate go run colorsgen.go

func GetColor(c vt10x.Color) string {
var colorStr string

if c == vt10x.DefaultFG {
return ansiColors[int(vt10x.LightGrey)]
}

if c.ANSI() {
colorStr = ansiToColor(uint32(c))
colorStr = ansiColors[int(c)]
} else {
colorStr = ansiToColor(uint32(vt10x.LightGrey))
colorStr = xtermColors[int(c)]
}

return colorStr
Expand Down
266 changes: 266 additions & 0 deletions pkg/color/colors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a70eeab

Please sign in to comment.