From 974c6d8958605401c195079fc8b3935494220f1e Mon Sep 17 00:00:00 2001 From: troido Date: Sat, 3 Oct 2020 11:01:38 +0200 Subject: [PATCH 1/2] restore tty settings after gh repo garden the command 'gh repo garden' used to leave the terminal in noecho mode when exiting This restores the tty settings to their state before running 'gh repo garden' --- pkg/cmd/repo/garden/garden.go | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/pkg/cmd/repo/garden/garden.go b/pkg/cmd/repo/garden/garden.go index e5129e4ad..5f81ccb3e 100644 --- a/pkg/cmd/repo/garden/garden.go +++ b/pkg/cmd/repo/garden/garden.go @@ -178,6 +178,18 @@ func gardenRun(opts *GardenOptions) error { } maxCommits := (geo.Width * geo.Height) / 2 + + sttyFileArg := "-F" + if runtime.GOOS == "darwin" { + sttyFileArg = "-f" + } + + oldTTYCommand := exec.Command("stty", sttyFileArg, "/dev/tty", "-g") + oldTTYSettings, err := oldTTYCommand.CombinedOutput() + if err != nil { + fmt.Fprintln(out, "getting TTY setings failed:", string(oldTTYSettings)) + return err + } opts.IO.StartProgressIndicator() fmt.Fprintln(out, "gathering commits; this could take a minute...") @@ -201,13 +213,8 @@ func gardenRun(opts *GardenOptions) error { drawGarden(out, garden, player) // thanks stackoverflow https://stackoverflow.com/a/17278776 - if runtime.GOOS == "darwin" { - _ = exec.Command("stty", "-f", "/dev/tty", "cbreak", "min", "1").Run() - _ = exec.Command("stty", "-f", "/dev/tty", "-echo").Run() - } else { - _ = exec.Command("stty", "-F", "/dev/tty", "cbreak", "min", "1").Run() - _ = exec.Command("stty", "-F", "/dev/tty", "-echo").Run() - } + _ = exec.Command("stty", sttyFileArg, "/dev/tty", "cbreak", "min", "1").Run() + _ = exec.Command("stty", sttyFileArg, "/dev/tty", "-echo").Run() var b []byte = make([]byte, 3) for { @@ -291,6 +298,7 @@ func gardenRun(opts *GardenOptions) error { clear(opts.IO) fmt.Fprint(out, "\033[?25h") + _ = exec.Command("stty", sttyFileArg, "/dev/tty", strings.TrimSpace(string(oldTTYSettings))).Run() fmt.Fprintln(out) fmt.Fprintln(out, utils.Bold("You turn and walk away from the wildflower garden...")) From fa68a3a8582121d5a1e10c3e2cd93f4c422ce56b Mon Sep 17 00:00:00 2001 From: vilmibm Date: Mon, 5 Oct 2020 15:19:49 -0500 Subject: [PATCH 2/2] linter appeasement --- pkg/cmd/repo/garden/garden.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/cmd/repo/garden/garden.go b/pkg/cmd/repo/garden/garden.go index 5f81ccb3e..2402ccbc1 100644 --- a/pkg/cmd/repo/garden/garden.go +++ b/pkg/cmd/repo/garden/garden.go @@ -178,12 +178,12 @@ func gardenRun(opts *GardenOptions) error { } maxCommits := (geo.Width * geo.Height) / 2 - + sttyFileArg := "-F" if runtime.GOOS == "darwin" { sttyFileArg = "-f" } - + oldTTYCommand := exec.Command("stty", sttyFileArg, "/dev/tty", "-g") oldTTYSettings, err := oldTTYCommand.CombinedOutput() if err != nil {