Skip to content
This repository has been archived by the owner on Mar 19, 2021. It is now read-only.

Commit

Permalink
Better exits
Browse files Browse the repository at this point in the history
  • Loading branch information
alfredxing committed Feb 7, 2018
1 parent 0b39213 commit 93c5e45
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func main() {
input := strings.Replace(strings.Join(os.Args[1:], ""), " ", "", -1)
res, err := compute.Evaluate(input)
if err != nil {
fmt.Println("Error: " + err.Error())
return
}
fmt.Printf("%s\n", strconv.FormatFloat(res, 'G', -1, 64))
Expand All @@ -45,8 +44,7 @@ func main() {
if err != nil {
if err == io.EOF {
// Quit without error on Ctrl^D
fmt.Println()
break
exit()
}
panic(err)
}
Expand All @@ -67,9 +65,14 @@ func main() {

func handleKey(line string, pos int, key rune) (newLine string, newPos int, ok bool) {
if key == '\x03' {
fmt.Println()
terminal.Restore(0, regularState)
os.Exit(0)
// Quit without error on Ctrl^C
exit()
}
return "", 0, false
}

func exit() {
terminal.Restore(0, regularState)
fmt.Println()
os.Exit(0)
}

0 comments on commit 93c5e45

Please sign in to comment.