2023-07-03 20:21:30 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2022-08-06 14:21:18 +00:00
|
|
|
//go:build !windows
|
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package hclog
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/mattn/go-isatty"
|
|
|
|
)
|
|
|
|
|
2023-07-03 20:21:30 +00:00
|
|
|
// hasFD is used to check if the writer has an Fd value to check
|
|
|
|
// if it's a terminal.
|
|
|
|
type hasFD interface {
|
|
|
|
Fd() uintptr
|
|
|
|
}
|
|
|
|
|
2022-08-06 14:21:18 +00:00
|
|
|
// setColorization will mutate the values of this logger
|
2023-03-20 20:25:53 +00:00
|
|
|
// to appropriately configure colorization options. It provides
|
2022-08-06 14:21:18 +00:00
|
|
|
// a wrapper to the output stream on Windows systems.
|
|
|
|
func (l *intLogger) setColorization(opts *LoggerOptions) {
|
2023-07-03 20:21:30 +00:00
|
|
|
if opts.Color != AutoColor {
|
2022-08-06 14:21:18 +00:00
|
|
|
return
|
2023-07-03 20:21:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if sc, ok := l.writer.w.(SupportsColor); ok {
|
|
|
|
if !sc.SupportsColor() {
|
2022-08-06 14:21:18 +00:00
|
|
|
l.headerColor = ColorOff
|
|
|
|
l.writer.color = ColorOff
|
|
|
|
}
|
2023-07-03 20:21:30 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
fi, ok := l.writer.w.(hasFD)
|
|
|
|
if !ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if !isatty.IsTerminal(fi.Fd()) {
|
|
|
|
l.headerColor = ColorOff
|
|
|
|
l.writer.color = ColorOff
|
2022-08-06 14:21:18 +00:00
|
|
|
}
|
|
|
|
}
|