Skip to content

Commit

Permalink
Avoid interface for collecting file descriptors
Browse files Browse the repository at this point in the history
Avoid using interface{} as a catch-all in IsTerminal and
IsCygwinTerminal functions.
The use of *os.File allows for static type error checks.
  • Loading branch information
Faithfulness Alamu committed Sep 25, 2020
1 parent f17d967 commit 0206648
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions utils/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,12 @@ import (
"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
var IsTerminal = func(f *os.File) bool {
return isatty.IsTerminal(f.Fd()) || IsCygwinTerminal(f)
}

func IsCygwinTerminal(w interface{}) bool {
if f, isFile := w.(*os.File); isFile {
return isatty.IsCygwinTerminal(f.Fd())
}

return false
func IsCygwinTerminal(f *os.File) bool {
return isatty.IsCygwinTerminal(f.Fd())
}

var TerminalSize = func(w interface{}) (int, int, error) {
Expand Down

0 comments on commit 0206648

Please sign in to comment.