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() {
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) {

26
main.go
View File

@ -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()
}
}
}