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
out, err := cmd.Output()
if err != nil {
fmt.Println("Fatal error: Unable to retrieve terminal size")
os.Exit(5)
cui.Exit(5, "Fatal error: Unable to retrieve terminal size")
}
var h, w int
_, _ = fmt.Sscan(string(out), &h, &w)
@ -66,8 +65,7 @@ func (c *client) GetSize() {
cmd.Stdin = os.Stdin
out, err := cmd.Output()
if err != nil {
fmt.Println("Fatal error: Unable to retrieve terminal size")
os.Exit(5)
cui.Exit(5, "Fatal error: Unable to retrieve terminal size")
}
var h, w int
_, _ = fmt.Sscan(string(out), &h, &w)
@ -157,7 +155,7 @@ func (c *client) TakeControlInput() {
c.Scroll(-1)
case 'q', 'Q':
// quit bombadillo
cui.Exit()
cui.Exit(0, "")
case 'g':
// scroll to top
c.ClearMessage()
@ -278,7 +276,7 @@ func (c *client) simpleCommand(action string) {
action = strings.ToUpper(action)
switch action {
case "Q", "QUIT":
cui.Exit()
cui.Exit(0, "")
case "H", "HOME":
if c.Options["homeurl"] != "unset" {
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
func Exit() {
func Exit(exitCode int, msg string) {
CleanupTerm()
os.Exit(0)
if msg != "" {
fmt.Print(msg, "\n")
}
os.Exit(exitCode)
}
// 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)
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")
@ -104,7 +105,8 @@ func loadConfig() error {
if err != nil {
err = saveConfig()
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 {
bombadillo.Certs.Add(v.Key, v.Value)
}
return nil
}
func initClient() error {
func initClient() {
bombadillo = MakeClient(" ((( Bombadillo ))) ")
err := loadConfig()
loadConfig()
if 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.
@ -165,7 +164,7 @@ func handleSignals(c <-chan os.Signal) {
cui.InitTerm()
bombadillo.Draw()
case syscall.SIGINT:
cui.Exit()
cui.Exit(130, "")
}
}
}
@ -197,12 +196,8 @@ func main() {
args := flag.Args()
cui.InitTerm()
defer cui.Exit()
err := initClient()
if err != nil {
// if we can't initialize we should bail out
panic(err)
}
defer cui.Exit(0, "")
initClient()
// watch for signals, send them to be handled
c := make(chan os.Signal, 1)