File: logger_darwin.go

package info (click to toggle)
golang-github-evanw-esbuild 0.25.10-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,184 kB
  • sloc: javascript: 28,602; makefile: 856; sh: 17
file content (34 lines) | stat: -rw-r--r-- 664 bytes parent folder | download | duplicates (3)
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)
}