make terminal 256 color output the default (#93)

this will allow terminals that support 256 color ansi codes to have
preview applications use 256 colors
This commit is contained in:
Chris Howey 2017-12-31 16:10:00 -06:00 committed by gokcehan
parent dd7b3f95c7
commit ec8e75ba30
2 changed files with 16 additions and 0 deletions

View File

@ -28,6 +28,8 @@ func run() {
} }
defer termbox.Close() defer termbox.Close()
termbox.SetOutputMode(termbox.Output256)
app := newApp() app := newApp()
if _, err := os.Stat(gConfigPath); !os.IsNotExist(err) { if _, err := os.Stat(gConfigPath); !os.IsNotExist(err) {

14
ui.go
View File

@ -146,6 +146,20 @@ func applyAnsiCodes(s string, fg, bg termbox.Attribute) (termbox.Attribute, term
nums = append(nums, n) 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 { for _, n := range nums {
attr, ok := gAnsiCodes[n] attr, ok := gAnsiCodes[n]
if !ok { if !ok {