From e32ba04a1a636ca7a60b368acf2cc89c2a068c65 Mon Sep 17 00:00:00 2001 From: asdf Date: Thu, 24 Oct 2019 13:42:38 +1100 Subject: [PATCH] Missed the for loop...plus some documentation --- cui/cui.go | 9 ++++++--- main.go | 26 +++++++++++++------------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/cui/cui.go b/cui/cui.go index 7d5d71a..fa57870 100644 --- a/cui/cui.go +++ b/cui/cui.go @@ -56,26 +56,29 @@ func moveCursorToward(dir string, amount int) { } } +// Exit performs cleanup operations before exiting the application func Exit() { CleanupTerm() os.Exit(0) } +// InitTerm sets the terminal modes appropriate for Bombadillo func InitTerm() { SetCharMode() Tput("rmam") // turn off line wrapping Tput("smcup") // use alternate screen } +// CleanupTerm reverts changs to terminal mode made by InitTerm func CleanupTerm() { moveCursorToward("down", 500) moveCursorToward("right", 500) SetLineMode() fmt.Print("\n") - fmt.Print("\033[?25h") - Tput("smam") // turn on line wrap - Tput("rmcup") // stop using alternate screen + fmt.Print("\033[?25h") // reenables cursor blinking + Tput("smam") // turn on line wrap + Tput("rmcup") // stop using alternate screen } func Clear(dir string) { diff --git a/main.go b/main.go index e7d7c2d..99e4c3c 100644 --- a/main.go +++ b/main.go @@ -149,20 +149,20 @@ func initClient() error { // In the event of specific signals, ensure the display is shown correctly. // Accepts a signal, blocking until it is received. Once not blocked, corrects -// terminal display settings. Loops indefinitely, does not return. +// terminal display settings as appropriate for that signal. Loops +// indefinitely, does not return. func handleSignals(c <-chan os.Signal) { - switch <-c { - case syscall.SIGTSTP: - cui.CleanupTerm() - //TODO: getting stuck here - // SIGSTOP seems to be the right signal, but the process - // does not recover? - syscall.Kill(syscall.Getpid(), syscall.SIGSTOP) - case syscall.SIGCONT: - cui.InitTerm() - bombadillo.Draw() - case syscall.SIGINT: - cui.Exit() + for { + switch <-c { + case syscall.SIGTSTP: + cui.CleanupTerm() + syscall.Kill(syscall.Getpid(), syscall.SIGSTOP) + case syscall.SIGCONT: + cui.InitTerm() + bombadillo.Draw() + case syscall.SIGINT: + cui.Exit() + } } }