Skip to content
Browse files

avoid raw mode when not tty

  • Loading branch information...
1 parent f17cde4 commit f9263d0e802b7b58dea781f1d91462df68e00e03 @bmizerany bmizerany committed Jun 24, 2012
Showing with 15 additions and 17 deletions.
  1. +15 −17 run.go
View
32 run.go
@@ -31,8 +31,6 @@ func init() {
func stty(args ...string) *exec.Cmd {
c := exec.Command("stty", args...)
c.Stdin = os.Stdin
- c.Stdout = os.Stdout
- c.Stderr = os.Stderr
return c
}
@@ -83,20 +81,22 @@ func runRun(cmd *Command, args []string) {
}
}
- err = stty("-icanon", "-echo").Run()
- if err != nil {
- log.Fatal(err)
+ if isTerminal(os.Stdin) && isTerminal(os.Stdout) {
+ err = stty("-icanon", "-echo").Run()
+ if err != nil {
+ log.Fatal(err)
+ }
+ defer stty("icanon", "echo").Run()
+
+ sig := make(chan os.Signal)
+ signal.Notify(sig)
+ go func() {
+ <-sig
+ // This will get called after the first os.Exit()
+ stty("icanon", "echo").Run()
+ os.Exit(1)
+ }()
}
- defer stty("icanon", "echo").Run()
-
- sig := make(chan os.Signal)
- signal.Notify(sig)
- go func() {
- <-sig
- // This will get called after the first os.Exit()
- stty("icanon", "echo").Run()
- os.Exit(1)
- }()
cp := func(a io.Writer, b io.Reader, errc chan<- error) {
_, err := io.Copy(a, b)
@@ -109,6 +109,4 @@ func runRun(cmd *Command, args []string) {
if err = <-errc; err != nil {
log.Fatal(err)
}
-
- stty("icanon", "echo").Run()
}

0 comments on commit f9263d0

Please sign in to comment.
Something went wrong with that request. Please try again.