From a4dfbab3b06360245f6b2fce4b56d6caf2729f8f Mon Sep 17 00:00:00 2001 From: Stefan Majewsky Date: Tue, 9 May 2017 20:52:58 +0200 Subject: implement TUI instance for when stdin is not a tty --- pkg/cli/interface.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'pkg/cli/interface.go') 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. -- cgit v1.3.1