Skip to content

Commit 828adc5

Browse files
committed
implement suspend
1 parent 143d476 commit 828adc5

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

pkg/gui/gui.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ import (
66
"fmt"
77
"io"
88
"os"
9+
"os/signal"
910
"path/filepath"
1011
"reflect"
1112
"regexp"
1213
"sort"
1314
"strings"
1415
"sync"
16+
"syscall"
1517

1618
"github.com/jesseduffield/gocui"
1719
"github.com/jesseduffield/lazycore/pkg/boxlayout"
@@ -418,6 +420,28 @@ func (gui *Gui) getPerRepoConfigFiles() []*config.ConfigFile {
418420
return repoConfigFiles
419421
}
420422

423+
func (gui *Gui) suspendApp(g *gocui.Gui, v *gocui.View) error {
424+
if err := g.Suspend(); err != nil {
425+
return err
426+
}
427+
428+
p, err := os.FindProcess(os.Getpid())
429+
if err != nil {
430+
return err
431+
}
432+
return p.Signal(syscall.SIGTSTP)
433+
}
434+
435+
func (gui *Gui) handleResume(g *gocui.Gui) {
436+
go func() {
437+
sigs := make(chan os.Signal, 1)
438+
signal.Notify(sigs, syscall.SIGCONT)
439+
for range sigs {
440+
g.Resume()
441+
}
442+
}()
443+
}
444+
421445
func (gui *Gui) onUserConfigLoaded() error {
422446
userConfig := gui.Config.GetUserConfig()
423447
gui.Common.SetUserConfig(userConfig)
@@ -819,6 +843,8 @@ func (gui *Gui) Run(startArgs appTypes.StartArgs) error {
819843
gui.g = g
820844
defer gui.g.Close()
821845

846+
gui.handleResume(gui.g)
847+
822848
g.ErrorHandler = gui.PopupHandler.ErrorHandler
823849

824850
// if the deadlock package wants to report a deadlock, we first need to
@@ -844,6 +870,10 @@ func (gui *Gui) Run(startArgs appTypes.StartArgs) error {
844870
return err
845871
}
846872

873+
if err := gui.g.SetKeybinding("", gocui.KeyCtrlA, gocui.ModNone, gui.suspendApp); err != nil {
874+
return err
875+
}
876+
847877
gui.waitForIntro.Add(1)
848878

849879
gui.BackgroundRoutineMgr.startBackgroundRoutines()

0 commit comments

Comments
 (0)