File: colorize_windows.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 (33 lines) | stat: -rw-r--r-- 795 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
28
29
30
31
32
33
// +build windows

package hclog

import (
	"os"

	colorable "github.com/mattn/go-colorable"
	"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:
		return
	case ForceColor:
		fi := l.checkWriterIsFile()
		l.writer.w = colorable.NewColorable(fi)
	case AutoColor:
		fi := l.checkWriterIsFile()
		isUnixTerm := isatty.IsTerminal(os.Stdout.Fd())
		isCygwinTerm := isatty.IsCygwinTerminal(os.Stdout.Fd())
		isTerm := isUnixTerm || isCygwinTerm
		if !isTerm {
			l.writer.color = ColorOff
			return
		}
		l.writer.w = colorable.NewColorable(fi)
	}
}