cli/utils/terminal.go
Faithfulness Alamu 0206648175 Avoid interface for collecting file descriptors
Avoid using interface{} as a catch-all in IsTerminal and
IsCygwinTerminal functions.
The use of *os.File allows for static type error checks.
2020-09-25 11:31:22 +01:00

25 lines
484 B
Go

package utils
import (
"fmt"
"os"
"github.com/mattn/go-isatty"
"golang.org/x/crypto/ssh/terminal"
)
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 terminal.GetSize(int(f.Fd()))
}
return 0, 0, fmt.Errorf("%v is not a file", w)
}