From f0b01b8d91b3d03c2799ff26afbf477ecffd12e7 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Wed, 11 Dec 2024 10:49:36 -0300 Subject: [PATCH] feat(style): trim line spaces Lipgloss applies aligning on the string as given to it, and ascii art usually contain left whitespaces to align things. This adds an option to trim space on all lines of the input, before giving it to lipgloss, so aligning use only non-whitespace content. --- style/ascii_a.txt | 7 +++++++ style/command.go | 7 +++++++ style/options.go | 1 + 3 files changed, 15 insertions(+) create mode 100644 style/ascii_a.txt diff --git a/style/ascii_a.txt b/style/ascii_a.txt new file mode 100644 index 000000000..ba425ecbe --- /dev/null +++ b/style/ascii_a.txt @@ -0,0 +1,7 @@ + # + # # + # # +# # +####### +# # +# # diff --git a/style/command.go b/style/command.go index 80390fa14..be04c8453 100644 --- a/style/command.go +++ b/style/command.go @@ -25,6 +25,13 @@ func (o Options) Run() error { return errors.New("no input provided, see `gum style --help`") } } + if o.Trim { + var lines []string + for _, line := range strings.Split(text, "\n") { + lines = append(lines, strings.TrimSpace(line)) + } + text = strings.Join(lines, "\n") + } fmt.Println(o.Style.ToLipgloss().Render(text)) return nil } diff --git a/style/options.go b/style/options.go index 906b551d5..cd2251d97 100644 --- a/style/options.go +++ b/style/options.go @@ -3,6 +3,7 @@ package style // Options is the customization options for the style command. type Options struct { Text []string `arg:"" optional:"" help:"Text to which to apply the style"` + Trim bool `help:"Trim whitespaces on every input line" default:"false"` Style StylesNotHidden `embed:""` }