From 79933615f7988cb731baa0768a45b39008f18b20 Mon Sep 17 00:00:00 2001 From: Stefan Majewsky Date: Fri, 7 Jul 2017 11:30:47 +0200 Subject: add first test --- pkg/cli/query.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'pkg/cli/query.go') diff --git a/pkg/cli/query.go b/pkg/cli/query.go index d9aa9a2..aa8fa50 100644 --- a/pkg/cli/query.go +++ b/pkg/cli/query.go @@ -44,6 +44,10 @@ type terminalTUI struct { i *Implementation } +func (t terminalTUI) Print(w io.Writer, msg string) { + w.Write([]byte(msg)) +} + func (t terminalTUI) ReadLine(prompt string) (string, error) { if prompt != "" { t.i.safeStdout().Write([]byte(strings.TrimSpace(prompt) + " ")) @@ -225,12 +229,18 @@ func (b *buffer) getNextInput() []byte { } //////////////////////////////////////////////////////////////////////////////// -// TUI implementation for when stdin is a pipe +// TUI implementation for when stdin is a pipe (also used in unit tests) type pipeTUI struct { i *Implementation } +var ansiColorCodeRx = regexp.MustCompile("\x1B" + `\[[0-9;]*m`) + +func (t *pipeTUI) Print(w io.Writer, msg string) { + w.Write([]byte(ansiColorCodeRx.ReplaceAllString(msg, ""))) +} + func (t *pipeTUI) ReadLine(prompt string) (string, error) { str, err := t.i.stdinBuf.ReadString('\n') str = strings.TrimSpace(str) -- cgit v1.3.1