From 4ceafd0b7b71bd934a0f15c1139ed74d0a518b70 Mon Sep 17 00:00:00 2001 From: Nojus Gudinavičius Date: Sun, 22 Oct 2023 19:54:48 +0300 Subject: commands: add :suspend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add :suspend to suspend the aerc process, returning to shell. Include documentation and default Ctrl-z keybinding for it. Changelog-added: New `:suspend` command bound to `` by default. Signed-off-by: Nojus Gudinavičius Signed-off-by: Robin Jarry --- lib/ui/ui.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'lib/ui/ui.go') diff --git a/lib/ui/ui.go b/lib/ui/ui.go index d2506b48..6a28eb9c 100644 --- a/lib/ui/ui.go +++ b/lib/ui/ui.go @@ -1,7 +1,10 @@ package ui import ( + "os" + "os/signal" "sync/atomic" + "syscall" "github.com/gdamore/tcell/v2" ) @@ -38,6 +41,8 @@ var state struct { screen tcell.Screen popover *Popover dirty uint32 // == 1 if render has been queued in Redraw channel + // == 1 if suspend is pending + suspending uint32 } func Initialize(content DrawableInteractive) error { @@ -79,6 +84,34 @@ func Exit() { close(Quit) } +var SuspendQueue = make(chan bool, 1) + +func QueueSuspend() { + if atomic.SwapUint32(&state.suspending, 1) != 1 { + SuspendQueue <- true + } +} + +func Suspend() error { + var err error + if atomic.SwapUint32(&state.suspending, 0) != 0 { + err = state.screen.Suspend() + if err == nil { + sigcont := make(chan os.Signal, 1) + signal.Notify(sigcont, syscall.SIGCONT) + err = syscall.Kill(0, syscall.SIGTSTP) + if err == nil { + <-sigcont + } + signal.Reset(syscall.SIGCONT) + err = state.screen.Resume() + state.content.Draw(state.ctx) + state.screen.Show() + } + } + return err +} + func Close() { state.screen.Fini() } -- cgit