diff --git a/client.go b/client.go index 1704ad6..6ae0f40 100644 --- a/client.go +++ b/client.go @@ -47,8 +47,8 @@ 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.ExitMessage = "Fatal error: Unable to retrieve terminal size" + cui.Exit(5) } var h, w int _, _ = fmt.Sscan(string(out), &h, &w) @@ -66,8 +66,8 @@ 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.ExitMessage = "Fatal error: Unable to retrieve terminal size" + cui.Exit(5) } var h, w int _, _ = fmt.Sscan(string(out), &h, &w) @@ -157,7 +157,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 +278,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"]) diff --git a/cui/cui.go b/cui/cui.go index 85b14cc..3565461 100644 --- a/cui/cui.go +++ b/cui/cui.go @@ -26,6 +26,8 @@ var Shapes = map[string]string{ "abr": "▟", } +var ExitMessage string + func MoveCursorTo(row, col int) { fmt.Printf("\033[%d;%dH", row, col) } @@ -44,9 +46,12 @@ func moveCursorToward(dir string, amount int) { } // Exit performs cleanup operations before exiting the application -func Exit() { +func Exit(exitCode int) { CleanupTerm() - os.Exit(0) + if ExitMessage != "" { + fmt.Print(ExitMessage, "\n") + } + os.Exit(exitCode) } // InitTerm sets the terminal modes appropriate for Bombadillo diff --git a/main.go b/main.go index bc986c0..205f772 100644 --- a/main.go +++ b/main.go @@ -165,7 +165,7 @@ func handleSignals(c <-chan os.Signal) { cui.InitTerm() bombadillo.Draw() case syscall.SIGINT: - cui.Exit() + cui.Exit(130) } } } @@ -197,11 +197,12 @@ func main() { args := flag.Args() cui.InitTerm() - defer cui.Exit() + defer cui.Exit(0) err := initClient() if err != nil { // if we can't initialize we should bail out - panic(err) + cui.ExitMessage = err.Error() + cui.Exit(1) } // watch for signals, send them to be handled