From 240eb4f2f8157f32b3cc67d907e5db0a591af046 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Mon, 25 Nov 2019 06:42:34 +0100 Subject: [PATCH] Word-wrap text at 100 chars per default The default can be overwritten by the user: ./gold -w 80 --- main.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index eba0ce4..9b88cc6 100644 --- a/main.go +++ b/main.go @@ -10,6 +10,7 @@ import ( "os" "github.com/mattn/go-isatty" + "github.com/mitchellh/go-wordwrap" "github.com/spf13/cobra" "github.com/charmbracelet/gold" @@ -25,7 +26,9 @@ var ( SilenceUsage: false, RunE: execute, } + style string + width uint ) func readerFromArg(s string) (io.ReadCloser, error) { @@ -91,7 +94,7 @@ func execute(cmd *cobra.Command, args []string) error { } out := r.RenderBytes(b) - fmt.Printf("%s", string(out)) + fmt.Printf("%s", wordwrap.WrapString(string(out), width)) return nil } @@ -103,4 +106,5 @@ func main() { func init() { rootCmd.Flags().StringVarP(&style, "style", "s", "dark.json", "style JSON path") + rootCmd.Flags().UintVarP(&width, "width", "w", 100, "word-wrap at width") }