Merge pull request #2072 from jmdejong/garden-resore-terminal
restore tty settings after gh repo garden
This commit is contained in:
commit
9869b874f8
1 changed files with 15 additions and 7 deletions
|
|
@ -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..."))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue