show shell commands as a single line

Mentioned in #91.
This commit is contained in:
Gokcehan 2017-11-04 18:50:31 +03:00
parent b3d2ddcc33
commit f1b5edfa0d

View File

@ -32,8 +32,10 @@ package main
// | Expr ListRest
import (
"bytes"
"fmt"
"io"
"strings"
)
type expr interface {
@ -83,7 +85,33 @@ type execExpr struct {
expr string
}
func (e *execExpr) String() string { return fmt.Sprintf("%s %s", e.pref, e.expr) }
func (e *execExpr) String() string {
var buf bytes.Buffer
buf.WriteString(e.pref)
buf.WriteString("{{ ")
lines := strings.Split(e.expr, "\n")
for _, line := range lines {
trimmed := strings.TrimSpace(line)
if trimmed == "" {
continue
}
buf.WriteString(trimmed)
if len(lines) > 1 {
buf.WriteString(" ...")
}
break
}
buf.WriteString(" }}")
return buf.String()
}
type listExpr struct {
exprs []expr