File: colorize_unix.go

package info (click to toggle)
golang-github-hashicorp-go-hclog 0.11.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, bullseye-backports, experimental, sid, trixie
  • size: 176 kB
  • sloc: makefile: 2
file content (27 lines) | stat: -rw-r--r-- 622 bytes parent folder | download
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
// +build !windows

package hclog

import (
	"github.com/mattn/go-isatty"
)

// setColorization will mutate the values of this logger
// to approperately configure colorization options. It provides
// a wrapper to the output stream on Windows systems.
func (l *intLogger) setColorization(opts *LoggerOptions) {
	switch opts.Color {
	case ColorOff:
		fallthrough
	case ForceColor:
		return
	case AutoColor:
		fi := l.checkWriterIsFile()
		isUnixTerm := isatty.IsTerminal(fi.Fd())
		isCygwinTerm := isatty.IsCygwinTerminal(fi.Fd())
		isTerm := isUnixTerm || isCygwinTerm
		if !isTerm {
			l.writer.color = ColorOff
		}
	}
}