-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
terminal.go
47 lines (38 loc) · 1 KB
/
terminal.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package pio
import (
"io"
"runtime"
"github.com/kataras/pio/terminal"
)
// outputWriter just caches the "supportColors"
// in order to reduce syscalls for known printers.
type outputWriter struct {
io.Writer
supportColors bool
}
func wrapWriters(output ...io.Writer) []*outputWriter {
outs := make([]*outputWriter, 0, len(output))
for _, w := range output {
outs = append(outs, &outputWriter{
Writer: w,
supportColors: SupportColors(w),
})
}
return outs
}
// SupportColors reports whether the "w" io.Writer is not a file and it does support colors.
func SupportColors(w io.Writer) bool {
if w == nil {
return false
}
if sc, ok := w.(*outputWriter); ok {
return sc.supportColors
}
isTerminal := !IsNop(w) && terminal.IsTerminal(w)
if isTerminal && runtime.GOOS == "windows" {
// if on windows then return true only when it does support 256-bit colors,
// this is why we initially do that terminal check for the "w" writer.
return terminal.SupportColors
}
return isTerminal
}