aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ui/ui.go
diff options
context:
space:
mode:
authorNojus Gudinavičius <nojus.gudinavicius@gmail.com>2023-10-22 19:54:48 +0300
committerRobin Jarry <robin@jarry.cc>2023-10-24 22:55:40 +0200
commit4ceafd0b7b71bd934a0f15c1139ed74d0a518b70 (patch)
tree69a90cf7bff1b6b6c2db9f45ace3a66e0d8916ef /lib/ui/ui.go
parentcbc43e891a8e7ada2c95bd4a2a161facb5156516 (diff)
downloadaerc-4ceafd0b7b71bd934a0f15c1139ed74d0a518b70.tar.gz
commands: add :suspend
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 `<C-z>` by default. Signed-off-by: Nojus Gudinavičius <nojus.gudinavicius@gmail.com> Signed-off-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'lib/ui/ui.go')
-rw-r--r--lib/ui/ui.go33
1 files changed, 33 insertions, 0 deletions
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()
}