From fde463be0ffe437853e5c9af38398682b025e140 Mon Sep 17 00:00:00 2001 From: sloumdrone Date: Thu, 5 Dec 2019 22:01:22 -0800 Subject: [PATCH] Removes unnecessary variable from exit routine --- client.go | 10 ++++------ cui/cui.go | 8 +++----- main.go | 12 ++++++------ 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/client.go b/client.go index 6ae0f40..7a24c94 100644 --- a/client.go +++ b/client.go @@ -47,8 +47,7 @@ func (c *client) GetSizeOnce() { cmd.Stdin = os.Stdin out, err := cmd.Output() if err != nil { - cui.ExitMessage = "Fatal error: Unable to retrieve terminal size" - cui.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 { - cui.ExitMessage = "Fatal error: Unable to retrieve terminal size" - cui.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(0) + 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(0) + 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 3565461..b6ca90b 100644 --- a/cui/cui.go +++ b/cui/cui.go @@ -26,8 +26,6 @@ var Shapes = map[string]string{ "abr": "▟", } -var ExitMessage string - func MoveCursorTo(row, col int) { fmt.Printf("\033[%d;%dH", row, col) } @@ -46,10 +44,10 @@ func moveCursorToward(dir string, amount int) { } // Exit performs cleanup operations before exiting the application -func Exit(exitCode int) { +func Exit(exitCode int, msg string) { CleanupTerm() - if ExitMessage != "" { - fmt.Print(ExitMessage, "\n") + if msg != "" { + fmt.Print(msg, "\n") } os.Exit(exitCode) } diff --git a/main.go b/main.go index 3a6908f..abaf0eb 100644 --- a/main.go +++ b/main.go @@ -96,8 +96,8 @@ func lowerCaseOpt(opt, val string) string { func loadConfig() { err := os.MkdirAll(bombadillo.Options["configlocation"], 0755) if err != nil { - cui.ExitMessage = fmt.Sprintf("Error creating configlocation: %s", err.Error()) - cui.Exit(3) + exitMsg := fmt.Sprintf("Error creating configlocation: %s", err.Error()) + cui.Exit(3, exitMsg) } fp := filepath.Join(bombadillo.Options["configlocation"], ".bombadillo.ini") @@ -105,8 +105,8 @@ func loadConfig() { if err != nil { err = saveConfig() if err != nil { - cui.ExitMessage = fmt.Sprintf("Error saving config during bootup: %s", err.Error()) - cui.Exit(4) + exitMsg := fmt.Sprintf("Error saving config during bootup: %s", err.Error()) + cui.Exit(4, exitMsg) } } @@ -164,7 +164,7 @@ func handleSignals(c <-chan os.Signal) { cui.InitTerm() bombadillo.Draw() case syscall.SIGINT: - cui.Exit(130) + cui.Exit(130, "") } } } @@ -196,7 +196,7 @@ func main() { args := flag.Args() cui.InitTerm() - defer cui.Exit(0) + defer cui.Exit(0, "") initClient() // watch for signals, send them to be handled