From 8fb26329ee377a7ec1d2e6a0f46809e2ca5eb4aa Mon Sep 17 00:00:00 2001 From: sloumdrone Date: Mon, 18 Mar 2019 20:11:02 -0700 Subject: [PATCH] Fixed fatal error on load as well as osx compatible stty command structure --- gclient.go => bombadillo.go | 44 ++++++++++++++++++++++--------------- config/parser.go | 2 +- cui/cui.go | 12 ++++++---- 3 files changed, 35 insertions(+), 23 deletions(-) rename gclient.go => bombadillo.go (91%) diff --git a/gclient.go b/bombadillo.go similarity index 91% rename from gclient.go rename to bombadillo.go index ed3cf0d..57ffc81 100644 --- a/gclient.go +++ b/bombadillo.go @@ -1,10 +1,10 @@ package main import ( - "gsock/gopher" - "gsock/cmdparse" - "gsock/config" - "gsock/cui" + "bombadillo/gopher" + "bombadillo/cmdparse" + "bombadillo/config" + "bombadillo/cui" "os/user" "io/ioutil" "os" @@ -19,7 +19,7 @@ var screen *cui.Screen var userinfo, _ = user.Current() var settings config.Config var options = map[string]string{ - "homeurl": "", + "homeurl": "unset", "savelocation": userinfo.HomeDir + "/Downloads/", "searchengine": "gopher://gopher.floodgap.com:70/7/v2/vs", "openhttp": "false", @@ -138,6 +138,7 @@ func go_to_url(u string) error { } } else if v.Address.IsBinary { // TO DO: run this into the write to file method + return fmt.Errorf("Not built yet") } else { history.Add(v) } @@ -178,7 +179,7 @@ func go_to_link(l string) error { } func go_home() error { - if options["homeurl"] != "" { + if options["homeurl"] != "unset" { return go_to_url(options["homeurl"]) } return fmt.Errorf("No home address has been set") @@ -292,11 +293,14 @@ func save_config() { opts += v opts += "\n" } - ioutil.WriteFile(userinfo.HomeDir + "/.badger.ini", []byte(bkmrks+opts), 0644) + ioutil.WriteFile(userinfo.HomeDir + "/.bombadillo.ini", []byte(bkmrks+opts), 0644) } func load_config() { - file, _ := os.Open(userinfo.HomeDir + "/.badger.ini") + file, err := os.Open(userinfo.HomeDir + "/.bombadillo.ini") + if err != nil { + save_config() + } confparser := config.NewParser(file) settings, _ = confparser.Parse() file.Close() @@ -309,6 +313,12 @@ func load_config() { } } +func display_error(err error, redraw *bool) { + cui.MoveCursorTo(screen.Height, 0) + fmt.Print("\033[41m\033[37m", err, "\033[0m") + *redraw = false +} + func initClient() { history.Position = -1 screen = cui.NewScreen() @@ -328,17 +338,19 @@ func main() { initClient() mainWindow := screen.Windows[0] first_load := true - redrawScreen := true for { screen.ReflashScreen(redrawScreen) if first_load { - go_home() first_load = false - mainWindow.Content = history.Collection[history.Position].Content - screen.Bars[0].SetMessage(history.Collection[history.Position].Address.Full) + err := go_home() + + if err == nil { + mainWindow.Content = history.Collection[history.Position].Content + screen.Bars[0].SetMessage(history.Collection[history.Position].Address.Full) + } continue } @@ -375,16 +387,12 @@ func main() { parser := cmdparse.NewParser(strings.NewReader(entry)) p, err := parser.Parse() if err != nil { - cui.MoveCursorTo(screen.Height, 0) - fmt.Print("\033[41m\033[37m", err, "\033[0m") + display_error(err, &redrawScreen) // Set screen to not reflash - redrawScreen = false } else { err := route_input(p) if err != nil { - cui.MoveCursorTo(screen.Height, 0) - fmt.Print("\033[41m\033[37m", err, "\033[0m") - redrawScreen = false + display_error(err, &redrawScreen) } else { mainWindow.Scrollposition = 0 } diff --git a/config/parser.go b/config/parser.go index 8e74ee6..9d759dc 100644 --- a/config/parser.go +++ b/config/parser.go @@ -4,7 +4,7 @@ import ( "io" "fmt" "strings" - "gsock/gopher" + "bombadillo/gopher" ) diff --git a/cui/cui.go b/cui/cui.go index 7214ecb..3d94ea1 100644 --- a/cui/cui.go +++ b/cui/cui.go @@ -127,12 +127,16 @@ func GetLine() string { } func SetCharMode() { - exec.Command("stty", "-F", "/dev/tty", "cbreak", "min", "1").Run() - exec.Command("stty", "-F", "/dev/tty", "-echo").Run() + cmd := exec.Command("stty", "cbreak", "-echo") + cmd.Stdin = os.Stdin + cmd.Stdout = os.Stdout + cmd.Run() fmt.Print("\033[?25l") } func SetLineMode() { - exec.Command("stty", "-F", "/dev/tty", "-cbreak").Run() - exec.Command("stty", "-F", "/dev/tty", "echo").Run() + cmd := exec.Command("stty", "-cbreak", "echo") + cmd.Stdin = os.Stdin + cmd.Stdout = os.Stdout + cmd.Run() }