mirror of
https://github.com/restic/restic.git
synced 2025-11-01 22:00:59 +00:00
termstatus: centralize OutputIsTerminal checks
This commit is contained in:
parent
c745e4221e
commit
1ae2d08d1b
14 changed files with 85 additions and 68 deletions
|
|
@ -10,18 +10,11 @@ func StdinIsTerminal() bool {
|
|||
return term.IsTerminal(int(os.Stdin.Fd()))
|
||||
}
|
||||
|
||||
func StdoutIsTerminal() bool {
|
||||
func OutputIsTerminal(fd uintptr) 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())
|
||||
}
|
||||
|
||||
func StdoutWidth() int {
|
||||
return Width(os.Stdout.Fd())
|
||||
// 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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue