Merge pull request #2072 from jmdejong/garden-resore-terminal

restore tty settings after gh repo garden
This commit is contained in:
Nate Smith 2020-10-05 15:34:18 -05:00 committed by GitHub
commit 9869b874f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -179,6 +179,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...")
commits, err := getCommits(httpClient, toView, maxCommits)
@ -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..."))