Handle more signals without breaking terminal
This commit is contained in:
parent
18c2fc1322
commit
a393b00ad1
16
cui/cui.go
16
cui/cui.go
|
@ -57,15 +57,25 @@ func moveCursorToward(dir string, amount int) {
|
|||
}
|
||||
|
||||
func Exit() {
|
||||
CleanupTerm()
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
func InitTerm() {
|
||||
SetCharMode()
|
||||
Tput("rmam") // turn off line wrapping
|
||||
Tput("smcup") // use alternate screen
|
||||
}
|
||||
|
||||
func CleanupTerm() {
|
||||
moveCursorToward("down", 500)
|
||||
moveCursorToward("right", 500)
|
||||
SetLineMode()
|
||||
|
||||
fmt.Print("\n")
|
||||
fmt.Print("\033[?25h")
|
||||
Tput("smam") // turn off line wrap
|
||||
Tput("rmcup") // use alternate screen
|
||||
os.Exit(0)
|
||||
Tput("smam") // turn on line wrap
|
||||
Tput("rmcup") // stop using alternate screen
|
||||
}
|
||||
|
||||
func Clear(dir string) {
|
||||
|
|
36
main.go
36
main.go
|
@ -112,7 +112,7 @@ func loadConfig() error {
|
|||
if lowerkey == "configlocation" {
|
||||
// The config defaults to the home folder.
|
||||
// Users cannot really edit this value. But
|
||||
// a compile time override is available.
|
||||
// a compile time override is available.
|
||||
// It is still stored in the ini and as a part
|
||||
// of the options map.
|
||||
continue
|
||||
|
@ -140,7 +140,6 @@ func loadConfig() error {
|
|||
|
||||
func initClient() error {
|
||||
bombadillo = MakeClient(" ((( Bombadillo ))) ")
|
||||
cui.SetCharMode()
|
||||
err := loadConfig()
|
||||
if bombadillo.Options["tlscertificate"] != "" && bombadillo.Options["tlskey"] != "" {
|
||||
bombadillo.Certs.LoadCertificate(bombadillo.Options["tlscertificate"], bombadillo.Options["tlskey"])
|
||||
|
@ -148,16 +147,22 @@ func initClient() error {
|
|||
return err
|
||||
}
|
||||
|
||||
// In the event of SIGCONT, 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.
|
||||
func handleSIGCONT(c <-chan os.Signal) {
|
||||
for {
|
||||
<-c
|
||||
cui.Tput("rmam") // turn off line wrapping
|
||||
cui.Tput("smcup") // use alternate screen
|
||||
cui.SetCharMode()
|
||||
// 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.
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -174,8 +179,7 @@ func main() {
|
|||
// So that we can open files from gemini
|
||||
mc = mailcap.NewMailcap()
|
||||
|
||||
cui.Tput("rmam") // turn off line wrapping
|
||||
cui.Tput("smcup") // use alternate screen
|
||||
cui.InitTerm()
|
||||
defer cui.Exit()
|
||||
err := initClient()
|
||||
if err != nil {
|
||||
|
@ -183,10 +187,10 @@ func main() {
|
|||
panic(err)
|
||||
}
|
||||
|
||||
// watch for SIGCONT, send it to be handled
|
||||
// watch for signals, send them to be handled
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, syscall.SIGCONT)
|
||||
go handleSIGCONT(c)
|
||||
signal.Notify(c, syscall.SIGTSTP, syscall.SIGCONT, syscall.SIGINT)
|
||||
go handleSignals(c)
|
||||
|
||||
// Start polling for terminal size changes
|
||||
go bombadillo.GetSize()
|
||||
|
|
Loading…
Reference in New Issue