about summary refs log tree commit diff stats
path: root/widgets
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-05-26 15:48:29 -0400
committerDrew DeVault <sir@cmpwn.com>2019-05-26 15:48:29 -0400
commit62cd0b08aa82fe19e6d5d96b0341f7cffbb4cb7b (patch)
treeb8f55a97c05523ea164a9e17cf1f4f49ef31255d /widgets
parent855362d813deca81dfb802bf2ed4917031e2a898 (diff)
downloadaerc-62cd0b08aa82fe19e6d5d96b0341f7cffbb4cb7b.tar.gz
Update terminal color handling per vterm changes
Diffstat (limited to 'widgets')
-rw-r--r--widgets/terminal.go65
1 files changed, 22 insertions, 43 deletions
diff --git a/widgets/terminal.go b/widgets/terminal.go
index 1146b1a..ecb26aa 100644
--- a/widgets/terminal.go
+++ b/widgets/terminal.go
@@ -1,7 +1,6 @@
 package widgets
 
 import (
-	gocolor "image/color"
 	"os"
 	"os/exec"
 	"sync"
@@ -92,7 +91,6 @@ type Terminal struct {
 	ui.Invalidatable
 	closed      bool
 	cmd         *exec.Cmd
-	colors      map[tcell.Color]tcell.Color
 	ctx         *ui.Context
 	cursorPos   vterm.Pos
 	cursorShown bool
@@ -146,33 +144,6 @@ func NewTerminal(cmd *exec.Cmd) (*Terminal, error) {
 	screen.OnSetTermProp = term.onSetTermProp
 	screen.EnableAltScreen(true)
 	screen.Reset(true)
-
-	state := term.vterm.ObtainState()
-	term.colors = make(map[tcell.Color]tcell.Color)
-	for i := 0; i < 256; i += 1 {
-		tcolor := tcell.Color(i)
-		var r uint8 = 0
-		var g uint8 = 0
-		var b uint8 = uint8(i + 1)
-		if i < 16 {
-			// Set the first 16 colors to predictable near-black RGB values
-			state.SetPaletteColor(i,
-				vterm.NewVTermColorRGB(gocolor.RGBA{r, g, b, 255}))
-		} else {
-			// The rest use RGB
-			vcolor := state.GetPaletteColor(i)
-			r, g, b = vcolor.GetRGB()
-		}
-		term.colors[tcell.NewRGBColor(int32(r), int32(g), int32(b))] = tcolor
-	}
-	fg, bg := state.GetDefaultColors()
-	r, g, b := bg.GetRGB()
-	term.colors[tcell.NewRGBColor(
-		int32(r), int32(g), int32(b))] = tcell.ColorDefault
-	r, g, b = fg.GetRGB()
-	term.colors[tcell.NewRGBColor(
-		int32(r), int32(g), int32(b))] = tcell.ColorDefault
-
 	return term, nil
 }
 
@@ -402,22 +373,30 @@ func (term *Terminal) styleFromCell(cell *vterm.ScreenCell) tcell.Style {
 	style := tcell.StyleDefault
 
 	background := cell.Bg()
-	r, g, b := background.GetRGB()
-	bg := tcell.NewRGBColor(int32(r), int32(g), int32(b))
 	foreground := cell.Fg()
-	r, g, b = foreground.GetRGB()
-	fg := tcell.NewRGBColor(int32(r), int32(g), int32(b))
 
-	if color, ok := term.colors[bg]; ok {
-		style = style.Background(color)
-	} else {
-		style = style.Background(bg)
-	}
-	if color, ok := term.colors[fg]; ok {
-		style = style.Foreground(color)
-	} else {
-		style = style.Foreground(fg)
-	}
+	var (
+		bg tcell.Color
+		fg tcell.Color
+	)
+	if background.IsDefaultBg() {
+		bg = tcell.ColorDefault
+	} else if background.IsIndexed() {
+		bg = tcell.Color(background.GetIndex())
+	} else if background.IsRgb() {
+		r, g, b := background.GetRGB()
+		bg = tcell.NewRGBColor(int32(r), int32(g), int32(b))
+	}
+	if foreground.IsDefaultFg() {
+		fg = tcell.ColorDefault
+	} else if foreground.IsIndexed() {
+		fg = tcell.Color(foreground.GetIndex())
+	} else if foreground.IsRgb() {
+		r, g, b := foreground.GetRGB()
+		fg = tcell.NewRGBColor(int32(r), int32(g), int32(b))
+	}
+
+	style = style.Background(bg).Foreground(fg)
 
 	if cell.Attrs().Bold != 0 {
 		style = style.Bold(true)