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 cmd.Stdin = os.Stdin
out, err := cmd.Output() out, err := cmd.Output()
if err != nil { if err != nil {
cui.ExitMessage = "Fatal error: Unable to retrieve terminal size" cui.Exit(5, "Fatal error: Unable to retrieve terminal size")
cui.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 {
cui.ExitMessage = "Fatal error: Unable to retrieve terminal size" cui.Exit(5, "Fatal error: Unable to retrieve terminal size")
cui.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(0) 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(0) 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

@ -26,8 +26,6 @@ var Shapes = map[string]string{
"abr": "▟", "abr": "▟",
} }
var ExitMessage string
func MoveCursorTo(row, col int) { func MoveCursorTo(row, col int) {
fmt.Printf("\033[%d;%dH", row, col) 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 // Exit performs cleanup operations before exiting the application
func Exit(exitCode int) { func Exit(exitCode int, msg string) {
CleanupTerm() CleanupTerm()
if ExitMessage != "" { if msg != "" {
fmt.Print(ExitMessage, "\n") fmt.Print(msg, "\n")
} }
os.Exit(exitCode) os.Exit(exitCode)
} }

12
main.go
View File

@ -96,8 +96,8 @@ func lowerCaseOpt(opt, val string) string {
func loadConfig() { func loadConfig() {
err := os.MkdirAll(bombadillo.Options["configlocation"], 0755) err := os.MkdirAll(bombadillo.Options["configlocation"], 0755)
if err != nil { if err != nil {
cui.ExitMessage = fmt.Sprintf("Error creating configlocation: %s", err.Error()) exitMsg := fmt.Sprintf("Error creating configlocation: %s", err.Error())
cui.Exit(3) cui.Exit(3, exitMsg)
} }
fp := filepath.Join(bombadillo.Options["configlocation"], ".bombadillo.ini") fp := filepath.Join(bombadillo.Options["configlocation"], ".bombadillo.ini")
@ -105,8 +105,8 @@ func loadConfig() {
if err != nil { if err != nil {
err = saveConfig() err = saveConfig()
if err != nil { if err != nil {
cui.ExitMessage = fmt.Sprintf("Error saving config during bootup: %s", err.Error()) exitMsg := fmt.Sprintf("Error saving config during bootup: %s", err.Error())
cui.Exit(4) cui.Exit(4, exitMsg)
} }
} }
@ -164,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(130) cui.Exit(130, "")
} }
} }
} }
@ -196,7 +196,7 @@ func main() {
args := flag.Args() args := flag.Args()
cui.InitTerm() cui.InitTerm()
defer cui.Exit(0) defer cui.Exit(0, "")
initClient() initClient()
// watch for signals, send them to be handled // watch for signals, send them to be handled