cli/utils/terminal.go
Tobias Klauser b586d51778 Use golang.org/x/term
The golang.org/x/crypto/ssh/terminal package is deprecated and merely a
wrapper around golang.org/x/term. Use the latter directly.
2021-04-28 18:44:36 +02:00

25 lines
465 B
Go

package utils
import (
"fmt"
"os"
"github.com/mattn/go-isatty"
"golang.org/x/term"
)
var IsTerminal = func(f *os.File) bool {
return isatty.IsTerminal(f.Fd()) || IsCygwinTerminal(f)
}
func IsCygwinTerminal(f *os.File) bool {
return isatty.IsCygwinTerminal(f.Fd())
}
var TerminalSize = func(w interface{}) (int, int, error) {
if f, isFile := w.(*os.File); isFile {
return term.GetSize(int(f.Fd()))
}
return 0, 0, fmt.Errorf("%v is not a file", w)
}