diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2021-04-02 21:14:09 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2021-04-06 19:34:32 +1000 |
commit | 5289d49f75e9735f129e1f8e2a2f9dc74373515b (patch) | |
tree | 4ccb6567cbbd4318924f021b2e35d390c9a724e6 /vendor | |
parent | 69e9f6d29da5be2d6250444ee46b05c81d668d8e (diff) |
more efficient gocui
Diffstat (limited to 'vendor')
-rw-r--r-- | vendor/github.com/jesseduffield/gocui/gui.go | 12 | ||||
-rw-r--r-- | vendor/github.com/jesseduffield/gocui/tcell_driver.go | 35 | ||||
-rw-r--r-- | vendor/modules.txt | 2 |
3 files changed, 30 insertions, 19 deletions
diff --git a/vendor/github.com/jesseduffield/gocui/gui.go b/vendor/github.com/jesseduffield/gocui/gui.go index c30765390..a6348fafa 100644 --- a/vendor/github.com/jesseduffield/gocui/gui.go +++ b/vendor/github.com/jesseduffield/gocui/gui.go @@ -533,10 +533,6 @@ func (g *Gui) SetManagerFunc(manager func(*Gui) error) { // MainLoop runs the main loop until an error is returned. A successful // finish should return ErrQuit. func (g *Gui) MainLoop() error { - if err := g.flush(); err != nil { - return err - } - go func() { for { select { @@ -552,9 +548,6 @@ func (g *Gui) MainLoop() error { Screen.EnableMouse() } - if err := g.flush(); err != nil { - return err - } for { select { case ev := <-g.gEvents: @@ -619,7 +612,8 @@ func (g *Gui) handleEvent(ev *GocuiEvent) error { // flush updates the gui, re-drawing frames and buffers. func (g *Gui) flush() error { - g.clear(g.FgColor, g.BgColor) + // pretty sure we don't need this, but keeping it here in case we get weird visual artifacts + // g.clear(g.FgColor, g.BgColor) maxX, maxY := Screen.Size() // if GUI's size has changed, we need to redraw all views @@ -690,7 +684,7 @@ func (g *Gui) flush() error { } func (g *Gui) clear(fg, bg Attribute) (int, int) { - st := getTcellStyle(fg, bg, g.outputMode) + st := getTcellStyle(oldStyle{fg: fg, bg: bg, outputMode: g.outputMode}) w, h := Screen.Size() for row := 0; row < h; row++ { for col := 0; col < w; col++ { diff --git a/vendor/github.com/jesseduffield/gocui/tcell_driver.go b/vendor/github.com/jesseduffield/gocui/tcell_driver.go index 1bc4c1217..edfff081e 100644 --- a/vendor/github.com/jesseduffield/gocui/tcell_driver.go +++ b/vendor/github.com/jesseduffield/gocui/tcell_driver.go @@ -11,6 +11,17 @@ import ( // We probably don't want this being a global variable for YOLO for now var Screen tcell.Screen +// oldStyle is a representation of how a cell would be styled when we were using termbox +type oldStyle struct { + fg Attribute + bg Attribute + outputMode OutputMode +} + +// we're using this cache to speed up rendering, because obtaining the tcell style +// from the old style is deterministic +var cellStyleCache map[oldStyle]tcell.Style = map[oldStyle]tcell.Style{} + // tcellInit initializes tcell screen for use. func tcellInit() error { if s, e := tcell.NewScreen(); e != nil { @@ -25,25 +36,31 @@ func tcellInit() error { // tcellSetCell sets the character cell at a given location to the given // content (rune) and attributes using provided OutputMode -func tcellSetCell(x, y int, ch rune, fg, bg Attribute, omode OutputMode) { - st := getTcellStyle(fg, bg, omode) +func tcellSetCell(x, y int, ch rune, fg, bg Attribute, outputMode OutputMode) { + st := getTcellStyle(oldStyle{fg: fg, bg: bg, outputMode: outputMode}) Screen.SetContent(x, y, ch, nil, st) } // getTcellStyle creates tcell.Style from Attributes -func getTcellStyle(fg, bg Attribute, omode OutputMode) tcell.Style { +func getTcellStyle(input oldStyle) tcell.Style { + if cachedResult, ok := cellStyleCache[input]; ok { + return cachedResult + } + st := tcell.StyleDefault // extract colors and attributes - if fg != ColorDefault { - st = st.Foreground(getTcellColor(fg, omode)) - st = setTcellFontEffectStyle(st, fg) + if input.fg != ColorDefault { + st = st.Foreground(getTcellColor(input.fg, input.outputMode)) + st = setTcellFontEffectStyle(st, input.fg) } - if bg != ColorDefault { - st = st.Background(getTcellColor(bg, omode)) - st = setTcellFontEffectStyle(st, bg) + if input.bg != ColorDefault { + st = st.Background(getTcellColor(input.bg, input.outputMode)) + st = setTcellFontEffectStyle(st, input.bg) } + cellStyleCache[input] = st + return st } diff --git a/vendor/modules.txt b/vendor/modules.txt index 6bfcac748..0671374dd 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -149,7 +149,7 @@ github.com/jesseduffield/go-git/v5/utils/merkletrie/filesystem github.com/jesseduffield/go-git/v5/utils/merkletrie/index github.com/jesseduffield/go-git/v5/utils/merkletrie/internal/frame github.com/jesseduffield/go-git/v5/utils/merkletrie/noder -# github.com/jesseduffield/gocui v0.3.1-0.20210402040718-77a1b9631715 +# github.com/jesseduffield/gocui v0.3.1-0.20210402113210-6fd7ef27ce76 ## explicit github.com/jesseduffield/gocui # github.com/jesseduffield/termbox-go v0.0.0-20200823212418-a2289ed6aafe |