feat: add ctrl+z support

This commit is contained in:
chen 2023-05-02 14:07:27 +08:00 committed by Alex Goodman
parent a7dfbb7927
commit 77c11047cf

View file

@ -2,6 +2,7 @@ package ui
import (
"sync"
"syscall"
"github.com/wagoodman/dive/dive/image"
"github.com/wagoodman/dive/runtime/ui/key"
@ -135,6 +136,14 @@ func (a *app) quit() error {
return gocui.ErrQuit
}
// handle ctrl+z
func handle_ctrl_z(g *gocui.Gui, v *gocui.View) error {
gocui.Suspend()
syscall.Kill(syscall.Getpid(), syscall.SIGSTOP)
gocui.Resume()
return nil
}
// Run is the UI entrypoint.
func Run(imageName string, analysis *image.AnalysisResult, treeStack filetree.Comparer) error {
var err error
@ -150,6 +159,11 @@ func Run(imageName string, analysis *image.AnalysisResult, treeStack filetree.Co
return err
}
key, mod := gocui.MustParse("Ctrl+Z")
if err := g.SetKeybinding("", key, mod, handle_ctrl_z); err != nil {
return err
}
if err := g.MainLoop(); err != nil && err != gocui.ErrQuit {
logrus.Error("main loop error: ", err)
return err