-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcolor_unix.go
More file actions
43 lines (36 loc) · 834 Bytes
/
color_unix.go
File metadata and controls
43 lines (36 loc) · 834 Bytes
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
//go:build linux || darwin || freebsd || openbsd || netbsd || dragonfly
// +build linux darwin freebsd openbsd netbsd dragonfly
package log
import (
"fmt"
"io"
"os"
"syscall"
"golang.org/x/term"
)
// Colors.
const (
ColorBlue = "\x1b[0;34m"
ColorGreen = "\x1b[0;32m"
ColorYellow = "\x1b[0;33m"
ColorRed = "\x1b[0;31m"
ColorMegenta = "\x1b[0;35m"
ColorRST = "\x1b[0;m"
)
func paint(str string, color string) string {
return fmt.Sprintf("%s%s%s", color, str, ColorRST)
}
// IsColoredTerminal returns true if the given writer supports colored output.
func IsColoredTerminal(w io.Writer) bool {
var fd int
switch w {
case os.Stdout:
fd = syscall.Stdout
case os.Stderr:
fd = syscall.Stderr
default:
return false
}
// NOTE: modern terminals support ANSI escape codes.
return term.IsTerminal(fd)
}