From ec8e75ba307f427aed83341c29b36a60ddc9052d Mon Sep 17 00:00:00 2001 From: Chris Howey Date: Sun, 31 Dec 2017 16:10:00 -0600 Subject: [PATCH] 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 --- client.go | 2 ++ ui.go | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/client.go b/client.go index 1b9093de..563a5a4e 100644 --- a/client.go +++ b/client.go @@ -28,6 +28,8 @@ func run() { } defer termbox.Close() + termbox.SetOutputMode(termbox.Output256) + app := newApp() if _, err := os.Stat(gConfigPath); !os.IsNotExist(err) { diff --git a/ui.go b/ui.go index dd3e5d98..08bafaaf 100644 --- a/ui.go +++ b/ui.go @@ -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 {