diff options
Diffstat (limited to 'pkg/cli/query.go')
| -rw-r--r-- | pkg/cli/query.go | 12 |
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) |
