summaryrefslogtreecommitdiff
path: root/pkg/cli/query.go
diff options
context:
space:
mode:
authorStefan Majewsky <majewsky@gmx.net>2017-07-07 11:30:47 +0200
committerStefan Majewsky <majewsky@gmx.net>2017-07-07 11:33:00 +0200
commit79933615f7988cb731baa0768a45b39008f18b20 (patch)
treeab2199aa7940fdbdca7c6e6e0faaf47854342ef5 /pkg/cli/query.go
parent58a4af83e0caf09744dd698b5be937205b81e733 (diff)
downloadgofu-79933615f7988cb731baa0768a45b39008f18b20.tar.gz
add first test
Diffstat (limited to 'pkg/cli/query.go')
-rw-r--r--pkg/cli/query.go12
1 files changed, 11 insertions, 1 deletions
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)