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.
This commit is contained in:
Carlos Alexandro Becker 2024-12-11 14:00:55 -03:00 committed by GitHub
commit 2e53efc0ec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 15 additions and 0 deletions

7
style/ascii_a.txt Normal file
View file

@ -0,0 +1,7 @@
#
# #
# #
# #
#######
# #
# #

View file

@ -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
}

View file

@ -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:""`
}