diff options
| author | Jeff Carr <[email protected]> | 2025-09-26 18:53:21 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-09-26 19:04:48 -0500 |
| commit | ecfdb58a48931389c5f27f465bf7478428cb385d (patch) | |
| tree | ab46ed23c419db2667fbb867111ba44bb00a1313 /termSize_windows.go | |
| parent | 2fb8dc546300f278255c0a5ee339b6a9c7e89d48 (diff) | |
Diffstat (limited to 'termSize_windows.go')
| -rw-r--r-- | termSize_windows.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/termSize_windows.go b/termSize_windows.go new file mode 100644 index 0000000..0702792 --- /dev/null +++ b/termSize_windows.go @@ -0,0 +1,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 +} |
