diff options
Diffstat (limited to 'vendor/github.com')
-rw-r--r-- | vendor/github.com/jesseduffield/gocui/gui.go | 44 | ||||
-rw-r--r-- | vendor/github.com/jesseduffield/gocui/loader.go | 13 | ||||
-rw-r--r-- | vendor/github.com/jesseduffield/gocui/tcell_driver.go | 6 |
3 files changed, 46 insertions, 17 deletions
diff --git a/vendor/github.com/jesseduffield/gocui/gui.go b/vendor/github.com/jesseduffield/gocui/gui.go index c537a32b6..9b2d1ad25 100644 --- a/vendor/github.com/jesseduffield/gocui/gui.go +++ b/vendor/github.com/jesseduffield/gocui/gui.go @@ -13,6 +13,7 @@ import ( "sync" "time" + "github.com/gdamore/tcell/v2" "github.com/go-errors/errors" ) @@ -158,6 +159,10 @@ type Gui struct { SearchEscapeKey interface{} NextSearchMatchKey interface{} PrevSearchMatchKey interface{} + + screen tcell.Screen + suspendedMutex sync.Mutex + suspended bool } // NewGui returns a new Gui object with a given output mode. @@ -166,9 +171,9 @@ func NewGui(mode OutputMode, supportOverlaps bool, playMode PlayMode, headless b var err error if headless { - err = tcellInitSimulation() + err = g.tcellInitSimulation() } else { - err = tcellInit() + err = g.tcellInit() } if err != nil { return nil, err @@ -1000,6 +1005,10 @@ func (g *Gui) drawListFooter(v *View, fgColor, bgColor Attribute) error { // draw manages the cursor and calls the draw function of a view. func (g *Gui) draw(v *View) error { + if g.suspended { + return nil + } + if g.Cursor { if curview := g.currentView; curview != nil { vMaxX, vMaxY := curview.Size() @@ -1166,6 +1175,11 @@ func (g *Gui) StartTicking() { for { select { case <-ticker.C: + // I'm okay with having a data race here: there's no harm in letting one of these updates through + if g.suspended { + continue outer + } + for _, view := range g.Views() { if view.HasLoader { g.userEvents <- userEvent{func(g *Gui) error { return nil }} @@ -1290,3 +1304,29 @@ func (g *Gui) replayRecording() { log.Fatal("gocui should have already exited") } + +func (g *Gui) Suspend() error { + g.suspendedMutex.Lock() + defer g.suspendedMutex.Unlock() + + if g.suspended { + return errors.New("Already suspended") + } + + g.suspended = true + + return g.screen.Suspend() +} + +func (g *Gui) Resume() error { + g.suspendedMutex.Lock() + defer g.suspendedMutex.Unlock() + + if !g.suspended { + return errors.New("Cannot resume because we are not suspended") + } + + g.suspended = false + + return g.screen.Resume() +} diff --git a/vendor/github.com/jesseduffield/gocui/loader.go b/vendor/github.com/jesseduffield/gocui/loader.go index d6715ac6d..0aad5ae85 100644 --- a/vendor/github.com/jesseduffield/gocui/loader.go +++ b/vendor/github.com/jesseduffield/gocui/loader.go @@ -2,19 +2,6 @@ package gocui import "time" -func (g *Gui) loaderTick() { - go func() { - for range time.Tick(time.Millisecond * 50) { - for _, view := range g.Views() { - if view.HasLoader { - g.userEvents <- userEvent{func(g *Gui) error { return nil }} - break - } - } - } - }() -} - func (v *View) loaderLines() [][]cell { duplicate := make([][]cell, len(v.lines)) for i := range v.lines { diff --git a/vendor/github.com/jesseduffield/gocui/tcell_driver.go b/vendor/github.com/jesseduffield/gocui/tcell_driver.go index 3bc92b344..8d5045bce 100644 --- a/vendor/github.com/jesseduffield/gocui/tcell_driver.go +++ b/vendor/github.com/jesseduffield/gocui/tcell_driver.go @@ -21,23 +21,25 @@ type oldStyle struct { } // tcellInit initializes tcell screen for use. -func tcellInit() error { +func (g *Gui) tcellInit() error { if s, e := tcell.NewScreen(); e != nil { return e } else if e = s.Init(); e != nil { return e } else { + g.screen = s Screen = s return nil } } // tcellInitSimulation initializes tcell screen for use. -func tcellInitSimulation() error { +func (g *Gui) tcellInitSimulation() error { s := tcell.NewSimulationScreen("") if e := s.Init(); e != nil { return e } else { + g.screen = s Screen = s return nil } |