github.com/evanw/esbuild@v0.21.4/internal/logger/logger_linux.go (about) 1 //go:build linux 2 // +build linux 3 4 package logger 5 6 import ( 7 "os" 8 9 "golang.org/x/sys/unix" 10 ) 11 12 const SupportsColorEscapes = true 13 14 func GetTerminalInfo(file *os.File) (info TerminalInfo) { 15 fd := file.Fd() 16 17 // Is this file descriptor a terminal? 18 if _, err := unix.IoctlGetTermios(int(fd), unix.TCGETS); err == nil { 19 info.IsTTY = true 20 info.UseColorEscapes = !hasNoColorEnvironmentVariable() 21 22 // Get the width of the window 23 if w, err := unix.IoctlGetWinsize(int(fd), unix.TIOCGWINSZ); err == nil { 24 info.Width = int(w.Col) 25 info.Height = int(w.Row) 26 } 27 } 28 29 return 30 } 31 32 func writeStringWithColor(file *os.File, text string) { 33 file.WriteString(text) 34 }