summaryrefslogtreecommitdiff
path: root/termSize_darwin.go
blob: 0702792bef20dc42524578d6cc49390bf9df1544 (plain)
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
package cobol

import (
	"os"

	"go.wit.com/log"
	"golang.org/x/term"
)

func osTerminalWidth() (int, bool) {
	// term.IsTerminal checks if the given file descriptor is connected to a terminal.
	// We use os.Stdout.Fd() to check the standard output.
	if term.IsTerminal(int(os.Stdout.Fd())) {
		var err error
		// term.GetSize returns the dimensions of the given terminal.
		WIDTH, _, err = term.GetSize(int(os.Stdout.Fd()))
		if err != nil {
			// If we can't get the size for some reason, fall back to the default.
			log.Printf("could not get terminal size: %v", err)
			return WIDTH, false
		}
		return WIDTH, true
	}

	// If it's not a terminal, return the default width.
	return WIDTH, false
}