Skip to content

Commit

Permalink
fix(stdin): add trim of trailing newline (#577)
Browse files Browse the repository at this point in the history
* stdin: add trim of trailing newline

* choose: remove trimsuffix

* filter: remove trimsuffix

* style: remove trimsuffix
  • Loading branch information
MikaelFangel authored May 25, 2024
1 parent 26178f8 commit 2fe0291
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion choose/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion filter/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
2 changes: 1 addition & 1 deletion internal/stdin/stdin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion style/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2fe0291

Please sign in to comment.