From fa9d64c4ef81e16e303dafdda05de24bdb9f3d47 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Wed, 25 Dec 2019 07:01:56 +0100 Subject: [PATCH] Trim unstyled padding spaces from output --- main.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index b113073..5d2ee3b 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,7 @@ import ( "net/url" "os" "path/filepath" + "strings" "github.com/mattn/go-isatty" "github.com/spf13/cobra" @@ -138,8 +139,21 @@ func execute(cmd *cobra.Command, args []string) error { } out, err := r.RenderBytes(b) - fmt.Printf("%s", string(out)) - return err + if err != nil { + return err + } + + lines := strings.Split(string(out), "\n") + for i, s := range lines { + fmt.Print(strings.TrimSpace(s)) + + // don't add an artifical newline after the last split + if i+1 < len(lines) { + fmt.Println() + } + } + + return nil } func main() {