Skip to content

Commit

Permalink
make terminal 256 color output the default (#93)
Browse files Browse the repository at this point in the history
this will allow terminals that support 256 color ansi codes to have
preview applications use 256 colors
  • Loading branch information
howeyc authored and gokcehan committed Dec 31, 2017
1 parent dd7b3f9 commit ec8e75b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ func run() {
}
defer termbox.Close()

termbox.SetOutputMode(termbox.Output256)

app := newApp()

if _, err := os.Stat(gConfigPath); !os.IsNotExist(err) {
Expand Down
14 changes: 14 additions & 0 deletions ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,20 @@ func applyAnsiCodes(s string, fg, bg termbox.Attribute) (termbox.Attribute, term
nums = append(nums, n)
}

// Parse 256 color terminal ansi codes
// termbox-go has a color offset of one, because of attributes
if len(nums) == 3 {
if nums[0] == 48 && nums[1] == 5 {
bg = termbox.Attribute(nums[2])
bg++
}
if nums[0] == 38 && nums[1] == 5 {
fg = termbox.Attribute(nums[2])
fg++
}
return fg, bg
}

for _, n := range nums {
attr, ok := gAnsiCodes[n]
if !ok {
Expand Down

0 comments on commit ec8e75b

Please sign in to comment.