Inital try at handling SIGCONT

This commit is contained in:
asdf 2019-10-10 17:05:50 +11:00
parent 282bd9d246
commit 86485154c9
1 changed files with 25 additions and 7 deletions

32
main.go
View File

@ -1,4 +1,5 @@
package main package main
// Bombadillo is a gopher and gemini client for the terminal of unix or unix-like systems. // Bombadillo is a gopher and gemini client for the terminal of unix or unix-like systems.
// //
// Copyright (C) 2019 Brian Evans // Copyright (C) 2019 Brian Evans
@ -16,17 +17,18 @@ package main
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
import ( import (
"flag" "flag"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"os/signal"
"strings" "strings"
"syscall"
_ "tildegit.org/sloum/bombadillo/gemini"
"tildegit.org/sloum/bombadillo/config" "tildegit.org/sloum/bombadillo/config"
"tildegit.org/sloum/bombadillo/cui" "tildegit.org/sloum/bombadillo/cui"
_ "tildegit.org/sloum/bombadillo/gemini"
"tildegit.org/sloum/mailcap" "tildegit.org/sloum/mailcap"
) )
@ -58,13 +60,13 @@ func saveConfig() error {
opts.WriteString(certs) opts.WriteString(certs)
return ioutil.WriteFile(bombadillo.Options["configlocation"] + "/.bombadillo.ini", []byte(opts.String()), 0644) return ioutil.WriteFile(bombadillo.Options["configlocation"]+"/.bombadillo.ini", []byte(opts.String()), 0644)
} }
func validateOpt(opt, val string) bool { func validateOpt(opt, val string) bool {
var validOpts = map[string][]string{ var validOpts = map[string][]string{
"openhttp": []string{"true", "false"}, "openhttp": []string{"true", "false"},
"theme": []string{"normal", "inverse"}, "theme": []string{"normal", "inverse"},
"terminalonly": []string{"true", "false"}, "terminalonly": []string{"true", "false"},
} }
@ -115,7 +117,7 @@ func loadConfig() error {
} }
if _, ok := bombadillo.Options[lowerkey]; ok { if _, ok := bombadillo.Options[lowerkey]; ok {
if validateOpt(lowerkey, v.Value) { if validateOpt(lowerkey, v.Value) {
bombadillo.Options[lowerkey] = v.Value bombadillo.Options[lowerkey] = v.Value
} else { } else {
bombadillo.Options[lowerkey] = defaultOptions[lowerkey] bombadillo.Options[lowerkey] = defaultOptions[lowerkey]
@ -144,6 +146,17 @@ func initClient() error {
return err return err
} }
// On SIGCONT, ensure the terminal is still in the correct mode
// Accepts the signal, does the work, then starts another instance
// to handle any future occurences of SIGCONT
func handleSIGCONT(c <-chan os.Signal) {
<-c
cui.Tput("rmam") // turn off line wrapping
cui.Tput("smcup") // use alternate screen
cui.SetCharMode()
go handleSIGCONT(c)
}
func main() { func main() {
getVersion := flag.Bool("v", false, "See version number") getVersion := flag.Bool("v", false, "See version number")
flag.Parse() flag.Parse()
@ -153,11 +166,16 @@ func main() {
} }
args := flag.Args() args := flag.Args()
// buffered channel to capture SIGCONT for handling
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGCONT)
go handleSIGCONT(c)
// Build the mailcap db // Build the mailcap db
// 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.Tput("rmam") // turn off line wrapping
cui.Tput("smcup") // use alternate screen cui.Tput("smcup") // use alternate screen
defer cui.Exit() defer cui.Exit()
err := initClient() err := initClient()