Fixed fatal error on load as well as osx compatible stty command structure

This commit is contained in:
sloumdrone 2019-03-18 20:11:02 -07:00
parent d0a3b85c9f
commit 8fb26329ee
3 changed files with 35 additions and 23 deletions

View File

@ -1,10 +1,10 @@
package main package main
import ( import (
"gsock/gopher" "bombadillo/gopher"
"gsock/cmdparse" "bombadillo/cmdparse"
"gsock/config" "bombadillo/config"
"gsock/cui" "bombadillo/cui"
"os/user" "os/user"
"io/ioutil" "io/ioutil"
"os" "os"
@ -19,7 +19,7 @@ var screen *cui.Screen
var userinfo, _ = user.Current() var userinfo, _ = user.Current()
var settings config.Config var settings config.Config
var options = map[string]string{ var options = map[string]string{
"homeurl": "", "homeurl": "unset",
"savelocation": userinfo.HomeDir + "/Downloads/", "savelocation": userinfo.HomeDir + "/Downloads/",
"searchengine": "gopher://gopher.floodgap.com:70/7/v2/vs", "searchengine": "gopher://gopher.floodgap.com:70/7/v2/vs",
"openhttp": "false", "openhttp": "false",
@ -138,6 +138,7 @@ func go_to_url(u string) error {
} }
} else if v.Address.IsBinary { } else if v.Address.IsBinary {
// TO DO: run this into the write to file method // TO DO: run this into the write to file method
return fmt.Errorf("Not built yet")
} else { } else {
history.Add(v) history.Add(v)
} }
@ -178,7 +179,7 @@ func go_to_link(l string) error {
} }
func go_home() error { func go_home() error {
if options["homeurl"] != "" { if options["homeurl"] != "unset" {
return go_to_url(options["homeurl"]) return go_to_url(options["homeurl"])
} }
return fmt.Errorf("No home address has been set") return fmt.Errorf("No home address has been set")
@ -292,11 +293,14 @@ func save_config() {
opts += v opts += v
opts += "\n" 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() { 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) confparser := config.NewParser(file)
settings, _ = confparser.Parse() settings, _ = confparser.Parse()
file.Close() 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() { func initClient() {
history.Position = -1 history.Position = -1
screen = cui.NewScreen() screen = cui.NewScreen()
@ -328,17 +338,19 @@ func main() {
initClient() initClient()
mainWindow := screen.Windows[0] mainWindow := screen.Windows[0]
first_load := true first_load := true
redrawScreen := true redrawScreen := true
for { for {
screen.ReflashScreen(redrawScreen) screen.ReflashScreen(redrawScreen)
if first_load { if first_load {
go_home()
first_load = false first_load = false
mainWindow.Content = history.Collection[history.Position].Content err := go_home()
screen.Bars[0].SetMessage(history.Collection[history.Position].Address.Full)
if err == nil {
mainWindow.Content = history.Collection[history.Position].Content
screen.Bars[0].SetMessage(history.Collection[history.Position].Address.Full)
}
continue continue
} }
@ -375,16 +387,12 @@ func main() {
parser := cmdparse.NewParser(strings.NewReader(entry)) parser := cmdparse.NewParser(strings.NewReader(entry))
p, err := parser.Parse() p, err := parser.Parse()
if err != nil { if err != nil {
cui.MoveCursorTo(screen.Height, 0) display_error(err, &redrawScreen)
fmt.Print("\033[41m\033[37m", err, "\033[0m")
// Set screen to not reflash // Set screen to not reflash
redrawScreen = false
} else { } else {
err := route_input(p) err := route_input(p)
if err != nil { if err != nil {
cui.MoveCursorTo(screen.Height, 0) display_error(err, &redrawScreen)
fmt.Print("\033[41m\033[37m", err, "\033[0m")
redrawScreen = false
} else { } else {
mainWindow.Scrollposition = 0 mainWindow.Scrollposition = 0
} }

View File

@ -4,7 +4,7 @@ import (
"io" "io"
"fmt" "fmt"
"strings" "strings"
"gsock/gopher" "bombadillo/gopher"
) )

View File

@ -127,12 +127,16 @@ func GetLine() string {
} }
func SetCharMode() { func SetCharMode() {
exec.Command("stty", "-F", "/dev/tty", "cbreak", "min", "1").Run() cmd := exec.Command("stty", "cbreak", "-echo")
exec.Command("stty", "-F", "/dev/tty", "-echo").Run() cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Run()
fmt.Print("\033[?25l") fmt.Print("\033[?25l")
} }
func SetLineMode() { func SetLineMode() {
exec.Command("stty", "-F", "/dev/tty", "-cbreak").Run() cmd := exec.Command("stty", "-cbreak", "echo")
exec.Command("stty", "-F", "/dev/tty", "echo").Run() cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Run()
} }