mirror of
https://github.com/charmbracelet/gum
synced 2026-03-14 13:45:45 +01:00
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:
parent
6a37a14819
commit
2e53efc0ec
3 changed files with 15 additions and 0 deletions
7
style/ascii_a.txt
Normal file
7
style/ascii_a.txt
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#
|
||||
# #
|
||||
# #
|
||||
# #
|
||||
#######
|
||||
# #
|
||||
# #
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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:""`
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue