Missed the for loop...plus some documentation

This commit is contained in:
asdf 2019-10-24 13:42:38 +11:00
parent a393b00ad1
commit e32ba04a1a
2 changed files with 19 additions and 16 deletions

View File

@ -56,26 +56,29 @@ func moveCursorToward(dir string, amount int) {
} }
} }
// Exit performs cleanup operations before exiting the application
func Exit() { func Exit() {
CleanupTerm() CleanupTerm()
os.Exit(0) os.Exit(0)
} }
// InitTerm sets the terminal modes appropriate for Bombadillo
func InitTerm() { func InitTerm() {
SetCharMode() SetCharMode()
Tput("rmam") // turn off line wrapping Tput("rmam") // turn off line wrapping
Tput("smcup") // use alternate screen Tput("smcup") // use alternate screen
} }
// CleanupTerm reverts changs to terminal mode made by InitTerm
func CleanupTerm() { func CleanupTerm() {
moveCursorToward("down", 500) moveCursorToward("down", 500)
moveCursorToward("right", 500) moveCursorToward("right", 500)
SetLineMode() SetLineMode()
fmt.Print("\n") fmt.Print("\n")
fmt.Print("\033[?25h") fmt.Print("\033[?25h") // reenables cursor blinking
Tput("smam") // turn on line wrap Tput("smam") // turn on line wrap
Tput("rmcup") // stop using alternate screen Tput("rmcup") // stop using alternate screen
} }
func Clear(dir string) { func Clear(dir string) {

26
main.go
View File

@ -149,20 +149,20 @@ func initClient() error {
// In the event of specific signals, ensure the display is shown correctly. // In the event of specific signals, ensure the display is shown correctly.
// Accepts a signal, blocking until it is received. Once not blocked, corrects // 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) { func handleSignals(c <-chan os.Signal) {
switch <-c { for {
case syscall.SIGTSTP: switch <-c {
cui.CleanupTerm() case syscall.SIGTSTP:
//TODO: getting stuck here cui.CleanupTerm()
// SIGSTOP seems to be the right signal, but the process syscall.Kill(syscall.Getpid(), syscall.SIGSTOP)
// does not recover? case syscall.SIGCONT:
syscall.Kill(syscall.Getpid(), syscall.SIGSTOP) cui.InitTerm()
case syscall.SIGCONT: bombadillo.Draw()
cui.InitTerm() case syscall.SIGINT:
bombadillo.Draw() cui.Exit()
case syscall.SIGINT: }
cui.Exit()
} }
} }