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
|
//go:build darwin
// +build darwin
package logger
import (
"os"
"golang.org/x/sys/unix"
)
const SupportsColorEscapes = true
func GetTerminalInfo(file *os.File) (info TerminalInfo) {
fd := file.Fd()
// Is this file descriptor a terminal?
if _, err := unix.IoctlGetTermios(int(fd), unix.TIOCGETA); err == nil {
info.IsTTY = true
info.UseColorEscapes = !hasNoColorEnvironmentVariable()
// Get the width of the window
if w, err := unix.IoctlGetWinsize(int(fd), unix.TIOCGWINSZ); err == nil {
info.Width = int(w.Col)
info.Height = int(w.Row)
}
}
return
}
func writeStringWithColor(file *os.File, text string) {
file.WriteString(text)
}
|