|
@@ -20,6 +20,7 @@ import (
|
20
|
20
|
"fmt"
|
21
|
21
|
"os"
|
22
|
22
|
"strings"
|
|
23
|
+ "syscall"
|
23
|
24
|
|
24
|
25
|
"github.com/chzyer/readline"
|
25
|
26
|
"github.com/google/pprof/driver"
|
|
@@ -76,7 +77,10 @@ func (r *readlineUI) PrintErr(args ...interface{}) {
|
76
|
77
|
if !strings.HasSuffix(text, "\n") {
|
77
|
78
|
text += "\n"
|
78
|
79
|
}
|
79
|
|
- fmt.Fprint(r.rl.Stderr(), colorize(text))
|
|
80
|
+ if readline.IsTerminal(int(syscall.Stderr)) {
|
|
81
|
+ text = colorize(text)
|
|
82
|
+ }
|
|
83
|
+ fmt.Fprint(r.rl.Stderr(), text)
|
80
|
84
|
}
|
81
|
85
|
|
82
|
86
|
// colorize the msg using ANSI color escapes.
|
|
@@ -90,8 +94,7 @@ func colorize(msg string) string {
|
90
|
94
|
// IsTerminal returns whether the UI is known to be tied to an
|
91
|
95
|
// interactive terminal (as opposed to being redirected to a file).
|
92
|
96
|
func (r *readlineUI) IsTerminal() bool {
|
93
|
|
- const stdout = 1
|
94
|
|
- return readline.IsTerminal(stdout)
|
|
97
|
+ return readline.IsTerminal(int(syscall.Stdout))
|
95
|
98
|
}
|
96
|
99
|
|
97
|
100
|
// Start a browser on interactive mode.
|