Skip to content

Commit

Permalink
export middleware.IsTTY so it can be set in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pkieltyka committed Mar 24, 2020
1 parent 1f2d167 commit 6874595
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions middleware/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var (
reset = []byte{'\033', '[', '0', 'm'}
)

var isTTY bool
var IsTTY bool

func init() {
// This is sort of cheating: if stdout is a character device, we assume
Expand All @@ -47,17 +47,17 @@ func init() {
fi, err := os.Stdout.Stat()
if err == nil {
m := os.ModeDevice | os.ModeCharDevice
isTTY = fi.Mode()&m == m
IsTTY = fi.Mode()&m == m
}
}

// colorWrite
func cW(w io.Writer, useColor bool, color []byte, s string, args ...interface{}) {
if isTTY && useColor {
if IsTTY && useColor {
w.Write(color)
}
fmt.Fprintf(w, s, args...)
if isTTY && useColor {
if IsTTY && useColor {
w.Write(reset)
}
}

0 comments on commit 6874595

Please sign in to comment.