forked from cli/cli
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathterminal.go
More file actions
36 lines (27 loc) · 720 Bytes
/
terminal.go
File metadata and controls
36 lines (27 loc) · 720 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package utils
import (
"fmt"
"os"
"github.com/mattn/go-isatty"
"golang.org/x/crypto/ssh/terminal"
)
// TODO I don't like this use of interface{} but we need to accept both io.Writer and io.Reader
// interfaces.
var IsTerminal = func(w interface{}) bool {
if f, isFile := w.(*os.File); isFile {
return isatty.IsTerminal(f.Fd()) || IsCygwinTerminal(f)
}
return false
}
func IsCygwinTerminal(w interface{}) bool {
if f, isFile := w.(*os.File); isFile {
return isatty.IsCygwinTerminal(f.Fd())
}
return false
}
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)
}