summary refs log tree commit diff stats
path: root/widgets/terminal.go
diff options
context:
space:
mode:
Diffstat (limited to 'widgets/terminal.go')
-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)
7 -0800 committer Kartik K. Agaram <vc@akkartik.com> 2015-02-17 17:14:45 -0800 775 - starting to reorg C++ mu to use layers' href='/akkartik/mu/commit/cpp/literate/001test?h=main&id=515309164793b2e03c15954bf8a89f0f288a7f2c'>51530916 ^
60c566ea ^
54e4548d ^
51530916 ^
2ed1aa9c ^
51530916 ^


60c566ea ^
54e4548d ^
51530916 ^

2ed1aa9c ^
51530916 ^

ec99eb7a ^
de49fb42 ^

b39ceb27 ^
df0b469f ^
b39ceb27 ^






51530916 ^
6ff9413c ^
b39ceb27 ^
6c96a437 ^
9e608a77 ^
6c96a437 ^
46b6e2a3 ^
9e608a77 ^
6ff9413c ^

9e608a77 ^
b39ceb27 ^
5a9e3a11 ^
6ff9413c ^


b39ceb27 ^
683d53ca ^

b39ceb27 ^
df0b469f ^
ccd792da ^
51530916 ^
ac0e9db5 ^
7d13531e ^



6573fe1f ^
eb3a527a ^

b5ab709c ^
51530916 ^

53172ce1 ^
17d3003d ^




53172ce1 ^











51530916 ^
f2043a73 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104