diff options
| author | Stefan Majewsky <majewsky@gmx.net> | 2017-05-09 20:52:58 +0200 |
|---|---|---|
| committer | Stefan Majewsky <majewsky@gmx.net> | 2017-05-09 20:52:58 +0200 |
| commit | a4dfbab3b06360245f6b2fce4b56d6caf2729f8f (patch) | |
| tree | 2ade7c6c25675b36aacaf45d2282e0ec5c158c34 /pkg/cli/interface.go | |
| parent | 0e56e63c833229ca02f2c62d4ee50cf371b6ac9a (diff) | |
| download | gofu-a4dfbab3b06360245f6b2fce4b56d6caf2729f8f.tar.gz | |
implement TUI instance for when stdin is not a tty
Diffstat (limited to 'pkg/cli/interface.go')
| -rw-r--r-- | pkg/cli/interface.go | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/pkg/cli/interface.go b/pkg/cli/interface.go index 3192d32..c188c77 100644 --- a/pkg/cli/interface.go +++ b/pkg/cli/interface.go @@ -26,18 +26,26 @@ import ( "os" "sort" "strings" + + "golang.org/x/crypto/ssh/terminal" ) //NewInterface creates an Interface instance. -func NewInterface(stdin, stdout, stderr *os.File) (*Interface, error) { - //TODO: check terminal.IsTerminal(int(stdin.Fd())) and choose the TUI instance accordingly - return &Interface{ +func NewInterface(stdin, stdout, stderr *os.File) *Interface { + i := &Interface{ stdin: stdin, stdout: stdout, stderr: stderr, stdinBuf: bufio.NewReader(stdin), - tui: &terminalTUI{}, - }, nil + } + + if terminal.IsTerminal(int(stdin.Fd())) { + i.tui = &terminalTUI{i} + } else { + i.tui = &pipeTUI{i} + } + + return i } //Interface wraps access to the CLI, including input, output and subprocesses. |
