Skip to content

Commit

Permalink
Merge pull request #17 from wader/sgr-5-color-fix
Browse files Browse the repository at this point in the history
Correct map SGR 6*6*6 color
  • Loading branch information
wader committed Dec 14, 2023
2 parents d9b30bd + db51341 commit 8c5471f
Show file tree
Hide file tree
Showing 3 changed files with 1,127 additions and 1,122 deletions.
16 changes: 11 additions & 5 deletions ansidecoder/ansidecoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,17 @@ func intsToColor(fo int, bo int, cs []int) (Color, int) {
g := n / 6
n %= 6
b := n
return Color{RGB: []int{
int(float32(r) / 6 * 256),
int(float32(g) / 6 * 256),
int(float32(b) / 6 * 256),
}}, 2

// iterm2 mapping of 0-5 -> 0-255 is 0 -> 0, 1-5 -> n*40+55
// https://github.com/gnachman/iTerm2/blob/5fc45c349417b8483dfe8426432fcbadc32cb6d9/sources/NSColor%2BiTerm.m#L335
// Is this documented somewhere?
f := func(c int) int {
if c == 0 {
return 0
}
return c*40 + 55
}
return Color{RGB: []int{f(r), f(g), f(b)}}, 2
case n >= 232 && n <= 255:
// 232-255: grayscale from black to white in 24 steps
g := int(255 * ((float32(n) - 232.0) / 23))
Expand Down
84 changes: 42 additions & 42 deletions ansitosvg/testdata/params-colon-semicolon.ansi.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 8c5471f

Please sign in to comment.