2025-09-07 14:19:29 +02:00
|
|
|
package terminal
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"golang.org/x/term"
|
|
|
|
)
|
|
|
|
|
|
|
|
func StdinIsTerminal() bool {
|
|
|
|
return term.IsTerminal(int(os.Stdin.Fd()))
|
|
|
|
}
|
|
|
|
|
|
|
|
func StdoutIsTerminal() bool {
|
|
|
|
// mintty on windows can use pipes which behave like a posix terminal,
|
|
|
|
// but which are not a terminal handle
|
|
|
|
return term.IsTerminal(int(os.Stdout.Fd())) || StdoutCanUpdateStatus()
|
|
|
|
}
|
|
|
|
|
|
|
|
func StdoutCanUpdateStatus() bool {
|
|
|
|
return CanUpdateStatus(os.Stdout.Fd())
|
|
|
|
}
|
|
|
|
|
2025-09-07 14:26:42 +02:00
|
|
|
func StdoutWidth() int {
|
|
|
|
return Width(os.Stdout.Fd())
|
|
|
|
}
|
|
|
|
|
|
|
|
func Width(fd uintptr) int {
|
|
|
|
w, _, err := term.GetSize(int(fd))
|
2025-09-07 14:19:29 +02:00
|
|
|
if err != nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
return w
|
|
|
|
}
|