Skip to content

Commit 9869b87

Browse files
author
Nate Smith
authored
Merge pull request cli#2072 from jmdejong/garden-resore-terminal
restore tty settings after gh repo garden
2 parents c1af527 + fa68a3a commit 9869b87

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

pkg/cmd/repo/garden/garden.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,18 @@ func gardenRun(opts *GardenOptions) error {
179179

180180
maxCommits := (geo.Width * geo.Height) / 2
181181

182+
sttyFileArg := "-F"
183+
if runtime.GOOS == "darwin" {
184+
sttyFileArg = "-f"
185+
}
186+
187+
oldTTYCommand := exec.Command("stty", sttyFileArg, "/dev/tty", "-g")
188+
oldTTYSettings, err := oldTTYCommand.CombinedOutput()
189+
if err != nil {
190+
fmt.Fprintln(out, "getting TTY setings failed:", string(oldTTYSettings))
191+
return err
192+
}
193+
182194
opts.IO.StartProgressIndicator()
183195
fmt.Fprintln(out, "gathering commits; this could take a minute...")
184196
commits, err := getCommits(httpClient, toView, maxCommits)
@@ -201,13 +213,8 @@ func gardenRun(opts *GardenOptions) error {
201213
drawGarden(out, garden, player)
202214

203215
// thanks stackoverflow https://stackoverflow.com/a/17278776
204-
if runtime.GOOS == "darwin" {
205-
_ = exec.Command("stty", "-f", "/dev/tty", "cbreak", "min", "1").Run()
206-
_ = exec.Command("stty", "-f", "/dev/tty", "-echo").Run()
207-
} else {
208-
_ = exec.Command("stty", "-F", "/dev/tty", "cbreak", "min", "1").Run()
209-
_ = exec.Command("stty", "-F", "/dev/tty", "-echo").Run()
210-
}
216+
_ = exec.Command("stty", sttyFileArg, "/dev/tty", "cbreak", "min", "1").Run()
217+
_ = exec.Command("stty", sttyFileArg, "/dev/tty", "-echo").Run()
211218

212219
var b []byte = make([]byte, 3)
213220
for {
@@ -291,6 +298,7 @@ func gardenRun(opts *GardenOptions) error {
291298

292299
clear(opts.IO)
293300
fmt.Fprint(out, "\033[?25h")
301+
_ = exec.Command("stty", sttyFileArg, "/dev/tty", strings.TrimSpace(string(oldTTYSettings))).Run()
294302
fmt.Fprintln(out)
295303
fmt.Fprintln(out, utils.Bold("You turn and walk away from the wildflower garden..."))
296304

0 commit comments

Comments
 (0)