fix(stdin): add trim of trailing newline (#577)

* stdin: add trim of trailing newline

* choose: remove trimsuffix

* filter: remove trimsuffix

* style: remove trimsuffix
This commit is contained in:
Mikael Fangel 2024-05-25 18:44:01 +00:00 committed by GitHub
parent 26178f8894
commit 2fe0291e02
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 3 additions and 4 deletions

View File

@ -22,7 +22,7 @@ func (o Options) Run() error {
if input == "" {
return errors.New("no options provided, see `gum choose --help`")
}
o.Options = strings.Split(strings.TrimSuffix(input, "\n"), "\n")
o.Options = strings.Split(input, "\n")
}
if o.SelectIfOne && len(o.Options) == 1 {

View File

@ -34,7 +34,7 @@ func (o Options) Run() error {
if len(o.Options) == 0 {
if input, _ := stdin.Read(); input != "" {
o.Options = strings.Split(strings.TrimSuffix(input, "\n"), "\n")
o.Options = strings.Split(input, "\n")
} else {
o.Options = files.List()
}

View File

@ -28,7 +28,7 @@ func Read() (string, error) {
}
}
return b.String(), nil
return strings.TrimSuffix(b.String(), "\n"), nil
}
// IsEmpty returns whether stdin is empty.

View File

@ -24,7 +24,6 @@ func (o Options) Run() error {
if text == "" {
return errors.New("no input provided, see `gum style --help`")
}
text = strings.TrimSuffix(text, "\n")
}
fmt.Println(o.Style.ToLipgloss().Render(text))
return nil