restic/internal/terminal/stdio.go
2025-10-03 18:55:46 +02:00

26 lines
531 B
Go

package terminal
import (
"os"
"golang.org/x/term"
)
func StdinIsTerminal() bool {
return term.IsTerminal(int(os.Stdin.Fd()))
}
func OutputIsTerminal(fd uintptr) bool {
// mintty on windows can use pipes which behave like a posix terminal,
// but which are not a terminal handle. Thus also check `CanUpdateStatus`,
// which is able to detect such pipes.
return term.IsTerminal(int(fd)) || CanUpdateStatus(fd)
}
func Width(fd uintptr) int {
w, _, err := term.GetSize(int(fd))
if err != nil {
return 0
}
return w
}