summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/jesseduffield/gocui/gui.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/jesseduffield/gocui/gui.go')
-rw-r--r--vendor/github.com/jesseduffield/gocui/gui.go44
1 files changed, 42 insertions, 2 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()
+}