Removes unnecessary variable from exit routine

This commit is contained in:
sloumdrone 2019-12-05 22:01:22 -08:00
parent 8b004df1d5
commit fde463be0f
3 changed files with 13 additions and 17 deletions

View File

@ -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"])

View File

@ -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)
}

12
main.go
View File

@ -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