Merge branch 'handle-signals' of sloum/bombadillo into develop
Merging in after review completed.
This commit is contained in:
commit
d727f22fe7
21
cui/cui.go
21
cui/cui.go
|
@ -56,16 +56,29 @@ func moveCursorToward(dir string, amount int) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Exit performs cleanup operations before exiting the application
|
||||||
func Exit() {
|
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("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 off line wrap
|
Tput("smam") // turn on line wrap
|
||||||
Tput("rmcup") // use alternate screen
|
Tput("rmcup") // stop using alternate screen
|
||||||
os.Exit(0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Clear(dir string) {
|
func Clear(dir string) {
|
||||||
|
|
34
main.go
34
main.go
|
@ -140,7 +140,6 @@ func loadConfig() error {
|
||||||
|
|
||||||
func initClient() error {
|
func initClient() error {
|
||||||
bombadillo = MakeClient(" ((( Bombadillo ))) ")
|
bombadillo = MakeClient(" ((( Bombadillo ))) ")
|
||||||
cui.SetCharMode()
|
|
||||||
err := loadConfig()
|
err := loadConfig()
|
||||||
if bombadillo.Options["tlscertificate"] != "" && bombadillo.Options["tlskey"] != "" {
|
if bombadillo.Options["tlscertificate"] != "" && bombadillo.Options["tlskey"] != "" {
|
||||||
bombadillo.Certs.LoadCertificate(bombadillo.Options["tlscertificate"], bombadillo.Options["tlskey"])
|
bombadillo.Certs.LoadCertificate(bombadillo.Options["tlscertificate"], bombadillo.Options["tlskey"])
|
||||||
|
@ -148,16 +147,22 @@ func initClient() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// In the event of SIGCONT, ensure the display is shown correctly. Accepts a
|
// In the event of specific signals, ensure the display is shown correctly.
|
||||||
// signal, blocking until it is received. Once not blocked, corrects terminal
|
// Accepts a signal, blocking until it is received. Once not blocked, corrects
|
||||||
// display settings. Loops indefinitely, does not return.
|
// terminal display settings as appropriate for that signal. Loops
|
||||||
func handleSIGCONT(c <-chan os.Signal) {
|
// indefinitely, does not return.
|
||||||
|
func handleSignals(c <-chan os.Signal) {
|
||||||
for {
|
for {
|
||||||
<-c
|
switch <-c {
|
||||||
cui.Tput("rmam") // turn off line wrapping
|
case syscall.SIGTSTP:
|
||||||
cui.Tput("smcup") // use alternate screen
|
cui.CleanupTerm()
|
||||||
cui.SetCharMode()
|
syscall.Kill(syscall.Getpid(), syscall.SIGSTOP)
|
||||||
bombadillo.Draw()
|
case syscall.SIGCONT:
|
||||||
|
cui.InitTerm()
|
||||||
|
bombadillo.Draw()
|
||||||
|
case syscall.SIGINT:
|
||||||
|
cui.Exit()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,8 +196,7 @@ func main() {
|
||||||
// So that we can open files from gemini
|
// So that we can open files from gemini
|
||||||
mc = mailcap.NewMailcap()
|
mc = mailcap.NewMailcap()
|
||||||
|
|
||||||
cui.Tput("rmam") // turn off line wrapping
|
cui.InitTerm()
|
||||||
cui.Tput("smcup") // use alternate screen
|
|
||||||
defer cui.Exit()
|
defer cui.Exit()
|
||||||
err := initClient()
|
err := initClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -200,10 +204,10 @@ func main() {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// watch for SIGCONT, send it to be handled
|
// watch for signals, send them to be handled
|
||||||
c := make(chan os.Signal, 1)
|
c := make(chan os.Signal, 1)
|
||||||
signal.Notify(c, syscall.SIGCONT)
|
signal.Notify(c, syscall.SIGTSTP, syscall.SIGCONT, syscall.SIGINT)
|
||||||
go handleSIGCONT(c)
|
go handleSignals(c)
|
||||||
|
|
||||||
// Start polling for terminal size changes
|
// Start polling for terminal size changes
|
||||||
go bombadillo.GetSize()
|
go bombadillo.GetSize()
|
||||||
|
|
Loading…
Reference in New Issue