mirror of
https://github.com/charmbracelet/gum.git
synced 2024-09-11 06:16:03 +03:00
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:
parent
26178f8894
commit
2fe0291e02
@ -22,7 +22,7 @@ func (o Options) Run() error {
|
|||||||
if input == "" {
|
if input == "" {
|
||||||
return errors.New("no options provided, see `gum choose --help`")
|
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 {
|
if o.SelectIfOne && len(o.Options) == 1 {
|
||||||
|
@ -34,7 +34,7 @@ func (o Options) Run() error {
|
|||||||
|
|
||||||
if len(o.Options) == 0 {
|
if len(o.Options) == 0 {
|
||||||
if input, _ := stdin.Read(); input != "" {
|
if input, _ := stdin.Read(); input != "" {
|
||||||
o.Options = strings.Split(strings.TrimSuffix(input, "\n"), "\n")
|
o.Options = strings.Split(input, "\n")
|
||||||
} else {
|
} else {
|
||||||
o.Options = files.List()
|
o.Options = files.List()
|
||||||
}
|
}
|
||||||
|
@ -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.
|
// IsEmpty returns whether stdin is empty.
|
||||||
|
@ -24,7 +24,6 @@ func (o Options) Run() error {
|
|||||||
if text == "" {
|
if text == "" {
|
||||||
return errors.New("no input provided, see `gum style --help`")
|
return errors.New("no input provided, see `gum style --help`")
|
||||||
}
|
}
|
||||||
text = strings.TrimSuffix(text, "\n")
|
|
||||||
}
|
}
|
||||||
fmt.Println(o.Style.ToLipgloss().Render(text))
|
fmt.Println(o.Style.ToLipgloss().Render(text))
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user