From 2e53efc0ec76a3c63c4e23c6636174daf206185d Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Wed, 11 Dec 2024 14:00:55 -0300 Subject: [PATCH] feat(style): trim line spaces (#767) 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 0000000..ba425ec --- /dev/null +++ b/style/ascii_a.txt @@ -0,0 +1,7 @@ + # + # # + # # +# # +####### +# # +# # diff --git a/style/command.go b/style/command.go index 80390fa..be04c84 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 906b551..cd2251d 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:""` }