Merge branch 'panic-errors' of sloum/bombadillo into develop

This commit is contained in:
Sloom Sloum Sluom IV 2019-12-06 22:44:09 -05:00 committed by Gitea
commit 3a226f3769
3 changed files with 19 additions and 23 deletions

View File

@ -47,8 +47,7 @@ func (c *client) GetSizeOnce() {
cmd.Stdin = os.Stdin cmd.Stdin = os.Stdin
out, err := cmd.Output() out, err := cmd.Output()
if err != nil { if err != nil {
fmt.Println("Fatal error: Unable to retrieve terminal size") cui.Exit(5, "Fatal error: Unable to retrieve terminal size")
os.Exit(5)
} }
var h, w int var h, w int
_, _ = fmt.Sscan(string(out), &h, &w) _, _ = fmt.Sscan(string(out), &h, &w)
@ -66,8 +65,7 @@ func (c *client) GetSize() {
cmd.Stdin = os.Stdin cmd.Stdin = os.Stdin
out, err := cmd.Output() out, err := cmd.Output()
if err != nil { if err != nil {
fmt.Println("Fatal error: Unable to retrieve terminal size") cui.Exit(5, "Fatal error: Unable to retrieve terminal size")
os.Exit(5)
} }
var h, w int var h, w int
_, _ = fmt.Sscan(string(out), &h, &w) _, _ = fmt.Sscan(string(out), &h, &w)
@ -157,7 +155,7 @@ func (c *client) TakeControlInput() {
c.Scroll(-1) c.Scroll(-1)
case 'q', 'Q': case 'q', 'Q':
// quit bombadillo // quit bombadillo
cui.Exit() cui.Exit(0, "")
case 'g': case 'g':
// scroll to top // scroll to top
c.ClearMessage() c.ClearMessage()
@ -278,7 +276,7 @@ func (c *client) simpleCommand(action string) {
action = strings.ToUpper(action) action = strings.ToUpper(action)
switch action { switch action {
case "Q", "QUIT": case "Q", "QUIT":
cui.Exit() cui.Exit(0, "")
case "H", "HOME": case "H", "HOME":
if c.Options["homeurl"] != "unset" { if c.Options["homeurl"] != "unset" {
go c.Visit(c.Options["homeurl"]) go c.Visit(c.Options["homeurl"])

View File

@ -44,9 +44,12 @@ func moveCursorToward(dir string, amount int) {
} }
// Exit performs cleanup operations before exiting the application // Exit performs cleanup operations before exiting the application
func Exit() { func Exit(exitCode int, msg string) {
CleanupTerm() CleanupTerm()
os.Exit(0) if msg != "" {
fmt.Print(msg, "\n")
}
os.Exit(exitCode)
} }
// InitTerm sets the terminal modes appropriate for Bombadillo // InitTerm sets the terminal modes appropriate for Bombadillo

25
main.go
View File

@ -93,10 +93,11 @@ func lowerCaseOpt(opt, val string) string {
} }
} }
func loadConfig() error { func loadConfig() {
err := os.MkdirAll(bombadillo.Options["configlocation"], 0755) err := os.MkdirAll(bombadillo.Options["configlocation"], 0755)
if err != nil { if err != nil {
return fmt.Errorf("Error creating configlocation: %s", err.Error()) exitMsg := fmt.Sprintf("Error creating 'configlocation' directory: %s", err.Error())
cui.Exit(3, exitMsg)
} }
fp := filepath.Join(bombadillo.Options["configlocation"], ".bombadillo.ini") fp := filepath.Join(bombadillo.Options["configlocation"], ".bombadillo.ini")
@ -104,7 +105,8 @@ func loadConfig() error {
if err != nil { if err != nil {
err = saveConfig() err = saveConfig()
if err != nil { if err != nil {
return err exitMsg := fmt.Sprintf("Error writing config file during bootup: %s", err.Error())
cui.Exit(4, exitMsg)
} }
} }
@ -138,17 +140,14 @@ func loadConfig() error {
for _, v := range settings.Certs { for _, v := range settings.Certs {
bombadillo.Certs.Add(v.Key, v.Value) bombadillo.Certs.Add(v.Key, v.Value)
} }
return nil
} }
func initClient() error { func initClient() {
bombadillo = MakeClient(" ((( Bombadillo ))) ") bombadillo = MakeClient(" ((( Bombadillo ))) ")
err := loadConfig() 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"])
} }
return err
} }
// In the event of specific signals, ensure the display is shown correctly. // In the event of specific signals, ensure the display is shown correctly.
@ -165,7 +164,7 @@ func handleSignals(c <-chan os.Signal) {
cui.InitTerm() cui.InitTerm()
bombadillo.Draw() bombadillo.Draw()
case syscall.SIGINT: case syscall.SIGINT:
cui.Exit() cui.Exit(130, "")
} }
} }
} }
@ -197,12 +196,8 @@ func main() {
args := flag.Args() args := flag.Args()
cui.InitTerm() cui.InitTerm()
defer cui.Exit() defer cui.Exit(0, "")
err := initClient() initClient()
if err != nil {
// if we can't initialize we should bail out
panic(err)
}
// watch for signals, send them to be handled // watch for signals, send them to be handled
c := make(chan os.Signal, 1) c := make(chan os.Signal, 1)