From 0152f2a1a2ff86e1156d82cbb42c709e58b65e4f Mon Sep 17 00:00:00 2001 From: Gaurav Gogia <16029099+gaurav-gogia@users.noreply.github.com> Date: Sun, 26 Jun 2022 22:47:17 +0530 Subject: [PATCH 1/2] go version upgrade --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index d45218f..19290bc 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module mutant -go 1.16 +go 1.18 From 6f2bf109032e84491703363ddae947bc28066c52 Mon Sep 17 00:00:00 2001 From: Gaurav Gogia <16029099+gaurav-gogia@users.noreply.github.com> Date: Sun, 26 Jun 2022 22:47:24 +0530 Subject: [PATCH 2/2] graceful exit --- cli/cli.go | 5 +---- repl/repl.go | 13 ++++++++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/cli/cli.go b/cli/cli.go index 975efc7..0527b22 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -19,10 +19,7 @@ func RunRepl() { signal.Notify(c, os.Interrupt) go func() { <-c - fmt.Printf("\n\n") - fmt.Println("---- Leaving for a byte? I'll see you later! ----") - fmt.Printf("\n\n") - os.Exit(0) + repl.GracefulExit() }() repl.Start(os.Stdin, os.Stdout) } diff --git a/repl/repl.go b/repl/repl.go index b9281f1..d7e76f2 100644 --- a/repl/repl.go +++ b/repl/repl.go @@ -91,7 +91,7 @@ func Start(in io.Reader, out io.Writer) { } func welcome() { - fmt.Println(banner) + fmt.Print(banner) user, err := user.Current() if err != nil { @@ -132,5 +132,16 @@ func vanity(line string, out io.Writer) bool { return true } + if line == "exit" { + GracefulExit() + } + return false } + +func GracefulExit() { + fmt.Printf("\n\n") + fmt.Println("---- Leaving for a byte? I'll see you later! ----") + fmt.Printf("\n\n") + os.Exit(0) +}