From 9c5303999508b45a0490fff018e6a2837c236828 Mon Sep 17 00:00:00 2001 From: chen Date: Tue, 23 May 2023 23:25:47 +0800 Subject: [PATCH 1/2] feat: add ctrl+z for job control --- tui/keys.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tui/keys.go b/tui/keys.go index 730534c32..95687f08a 100644 --- a/tui/keys.go +++ b/tui/keys.go @@ -2,12 +2,18 @@ package tui import ( "fmt" + "syscall" "github.com/dundee/gdu/v5/pkg/fs" "github.com/gdamore/tcell/v2" + "github.com/rivo/tview" ) func (ui *UI) keyPressed(key *tcell.EventKey) *tcell.EventKey { + if ui.handleCtrlZ(key) == nil { + return nil + } + if ui.pages.HasPage("file") { return key // send event to primitive } @@ -107,6 +113,22 @@ func (ui *UI) handleInfoPageEvents(key *tcell.EventKey) *tcell.EventKey { return key } +// handle ctrl+z job control +func (ui *UI) handleCtrlZ(key *tcell.EventKey) *tcell.EventKey { + if key.Key() == tcell.KeyCtrlZ { + ui.app.Suspend(func() { + termApp := ui.app.(*tview.Application) + termApp.Lock() + defer termApp.Unlock() + + syscall.Kill(syscall.Getpid(), syscall.SIGTSTP) + }) + return nil + } + + return key +} + func (ui *UI) handleQuit(key *tcell.EventKey) *tcell.EventKey { switch key.Rune() { case 'Q': From 21a706d8629d223e15266bb5eee7e2a7a5ff1191 Mon Sep 17 00:00:00 2001 From: Daniel Milde Date: Wed, 31 May 2023 11:27:53 +0200 Subject: [PATCH 2/2] fix: err check --- tui/keys.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tui/keys.go b/tui/keys.go index 95687f08a..6c4dc5797 100644 --- a/tui/keys.go +++ b/tui/keys.go @@ -121,7 +121,10 @@ func (ui *UI) handleCtrlZ(key *tcell.EventKey) *tcell.EventKey { termApp.Lock() defer termApp.Unlock() - syscall.Kill(syscall.Getpid(), syscall.SIGTSTP) + err := syscall.Kill(syscall.Getpid(), syscall.SIGTSTP) + if err != nil { + ui.showErr("Error sending STOP signal", err) + } }) return nil }