Skip to content

Commit 5bf82cc

Browse files
committed
better handle signals
1 parent dc7cffd commit 5bf82cc

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

pkg/gui/gui.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import (
5151
"github.com/jesseduffield/lazygit/pkg/utils"
5252
"github.com/samber/lo"
5353
"github.com/sasha-s/go-deadlock"
54+
"golang.org/x/sys/unix"
5455
"gopkg.in/ozeidan/fuzzy-patricia.v3/patricia"
5556
)
5657

@@ -421,6 +422,20 @@ func (gui *Gui) getPerRepoConfigFiles() []*config.ConfigFile {
421422
return repoConfigFiles
422423
}
423424

425+
// setForegroundPgrp sets the current process group as the foreground process group
426+
// for the terminal, allowing the program to read input after resuming from suspension.
427+
func setForegroundPgrp() error {
428+
fd, err := unix.Open("/dev/tty", unix.O_RDWR, 0)
429+
if err != nil {
430+
return err
431+
}
432+
defer unix.Close(fd)
433+
434+
pgid := syscall.Getpgrp()
435+
436+
return unix.IoctlSetPointerInt(fd, unix.TIOCSPGRP, pgid)
437+
}
438+
424439
func (gui *Gui) suspendApp(g *gocui.Gui, v *gocui.View) error {
425440
if runtime.GOOS == "windows" {
426441
return nil
@@ -443,10 +458,15 @@ func (gui *Gui) handleResume(g *gocui.Gui) {
443458
go func() {
444459
sigs := make(chan os.Signal, 1)
445460
signal.Notify(sigs, syscall.SIGCONT)
446-
for range sigs {
447-
g.Resume()
461+
462+
for sig := range sigs {
463+
switch sig {
464+
case syscall.SIGCONT:
465+
setForegroundPgrp()
466+
g.Resume()
467+
gui.BackgroundRoutineMgr.PauseBackgroundRefreshes(false)
468+
}
448469
}
449-
gui.BackgroundRoutineMgr.PauseBackgroundRefreshes(false)
450470
}()
451471
}
452472

0 commit comments

Comments
 (0)