Update terminal color handling per vterm changes
This commit is contained in:
parent
855362d813
commit
62cd0b08aa
3 changed files with 23 additions and 42 deletions
2
go.mod
2
go.mod
|
@ -4,7 +4,7 @@ require (
|
||||||
git.sr.ht/~sircmpwn/getopt v0.0.0-20190214165041-9a4f886f9fc7
|
git.sr.ht/~sircmpwn/getopt v0.0.0-20190214165041-9a4f886f9fc7
|
||||||
git.sr.ht/~sircmpwn/pty v0.0.0-20190330154901-3a43678975a9
|
git.sr.ht/~sircmpwn/pty v0.0.0-20190330154901-3a43678975a9
|
||||||
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964
|
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964
|
||||||
github.com/ddevault/go-libvterm v0.0.0-20190526191137-d855ab13e5c4
|
github.com/ddevault/go-libvterm v0.0.0-20190526194226-b7d861da3810
|
||||||
github.com/emersion/go-imap v1.0.0-beta.5
|
github.com/emersion/go-imap v1.0.0-beta.5
|
||||||
github.com/emersion/go-imap-idle v0.0.0-20190519112320-2704abd7050e
|
github.com/emersion/go-imap-idle v0.0.0-20190519112320-2704abd7050e
|
||||||
github.com/emersion/go-message v0.10.3
|
github.com/emersion/go-message v0.10.3
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -20,6 +20,8 @@ github.com/ddevault/go-libvterm v0.0.0-20190526190351-a5805ce7162a h1:S/pRkJoJCh
|
||||||
github.com/ddevault/go-libvterm v0.0.0-20190526190351-a5805ce7162a/go.mod h1:Ow1oE1Hr4xE7eWY2/Ih2kbcOyyXDH7G0XKv/I4yiCYs=
|
github.com/ddevault/go-libvterm v0.0.0-20190526190351-a5805ce7162a/go.mod h1:Ow1oE1Hr4xE7eWY2/Ih2kbcOyyXDH7G0XKv/I4yiCYs=
|
||||||
github.com/ddevault/go-libvterm v0.0.0-20190526191137-d855ab13e5c4 h1:pYf6iVibYvCeJDPIguZoguGMKYnqIoiTKAWBoTSe4/4=
|
github.com/ddevault/go-libvterm v0.0.0-20190526191137-d855ab13e5c4 h1:pYf6iVibYvCeJDPIguZoguGMKYnqIoiTKAWBoTSe4/4=
|
||||||
github.com/ddevault/go-libvterm v0.0.0-20190526191137-d855ab13e5c4/go.mod h1:Ow1oE1Hr4xE7eWY2/Ih2kbcOyyXDH7G0XKv/I4yiCYs=
|
github.com/ddevault/go-libvterm v0.0.0-20190526191137-d855ab13e5c4/go.mod h1:Ow1oE1Hr4xE7eWY2/Ih2kbcOyyXDH7G0XKv/I4yiCYs=
|
||||||
|
github.com/ddevault/go-libvterm v0.0.0-20190526194226-b7d861da3810 h1:VlHKuIrEvuGlED53TkovT4AVUjrqTyeCt3wiqw1OsFc=
|
||||||
|
github.com/ddevault/go-libvterm v0.0.0-20190526194226-b7d861da3810/go.mod h1:Ow1oE1Hr4xE7eWY2/Ih2kbcOyyXDH7G0XKv/I4yiCYs=
|
||||||
github.com/emersion/go-imap v1.0.0-beta.5 h1:KpOPIoPNNq5m9LpWqRZcUgoDoc4SBy+TdYniGdwBJiU=
|
github.com/emersion/go-imap v1.0.0-beta.5 h1:KpOPIoPNNq5m9LpWqRZcUgoDoc4SBy+TdYniGdwBJiU=
|
||||||
github.com/emersion/go-imap v1.0.0-beta.5/go.mod h1:hwG4om0BJJYYFktL0Wm3xHhL3kybvG0hlm94ZofzwWQ=
|
github.com/emersion/go-imap v1.0.0-beta.5/go.mod h1:hwG4om0BJJYYFktL0Wm3xHhL3kybvG0hlm94ZofzwWQ=
|
||||||
github.com/emersion/go-imap-idle v0.0.0-20190519112320-2704abd7050e h1:L7bswVJZcf2YHofgom49oFRwVqmBj/qZqDy9/SJpZMY=
|
github.com/emersion/go-imap-idle v0.0.0-20190519112320-2704abd7050e h1:L7bswVJZcf2YHofgom49oFRwVqmBj/qZqDy9/SJpZMY=
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package widgets
|
package widgets
|
||||||
|
|
||||||
import (
|
import (
|
||||||
gocolor "image/color"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -92,7 +91,6 @@ type Terminal struct {
|
||||||
ui.Invalidatable
|
ui.Invalidatable
|
||||||
closed bool
|
closed bool
|
||||||
cmd *exec.Cmd
|
cmd *exec.Cmd
|
||||||
colors map[tcell.Color]tcell.Color
|
|
||||||
ctx *ui.Context
|
ctx *ui.Context
|
||||||
cursorPos vterm.Pos
|
cursorPos vterm.Pos
|
||||||
cursorShown bool
|
cursorShown bool
|
||||||
|
@ -146,33 +144,6 @@ func NewTerminal(cmd *exec.Cmd) (*Terminal, error) {
|
||||||
screen.OnSetTermProp = term.onSetTermProp
|
screen.OnSetTermProp = term.onSetTermProp
|
||||||
screen.EnableAltScreen(true)
|
screen.EnableAltScreen(true)
|
||||||
screen.Reset(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
|
return term, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -402,23 +373,31 @@ func (term *Terminal) styleFromCell(cell *vterm.ScreenCell) tcell.Style {
|
||||||
style := tcell.StyleDefault
|
style := tcell.StyleDefault
|
||||||
|
|
||||||
background := cell.Bg()
|
background := cell.Bg()
|
||||||
r, g, b := background.GetRGB()
|
|
||||||
bg := tcell.NewRGBColor(int32(r), int32(g), int32(b))
|
|
||||||
foreground := cell.Fg()
|
foreground := cell.Fg()
|
||||||
r, g, b = foreground.GetRGB()
|
|
||||||
fg := tcell.NewRGBColor(int32(r), int32(g), int32(b))
|
|
||||||
|
|
||||||
if color, ok := term.colors[bg]; ok {
|
var (
|
||||||
style = style.Background(color)
|
bg tcell.Color
|
||||||
} else {
|
fg tcell.Color
|
||||||
style = style.Background(bg)
|
)
|
||||||
|
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 color, ok := term.colors[fg]; ok {
|
if foreground.IsDefaultFg() {
|
||||||
style = style.Foreground(color)
|
fg = tcell.ColorDefault
|
||||||
} else {
|
} else if foreground.IsIndexed() {
|
||||||
style = style.Foreground(fg)
|
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 {
|
if cell.Attrs().Bold != 0 {
|
||||||
style = style.Bold(true)
|
style = style.Bold(true)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue