mirror of
https://github.com/charmbracelet/gum
synced 2024-05-09 17:56:37 +02:00
feat(style): allow passing input over stdin
This commit is contained in:
parent
b0aba2261d
commit
614f0e8028
|
@ -6,16 +6,27 @@
|
|||
package style
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/alecthomas/kong"
|
||||
"github.com/charmbracelet/gum/internal/stdin"
|
||||
)
|
||||
|
||||
// Run provides a shell script interface for the Lip Gloss styling.
|
||||
// https://github.com/charmbracelet/lipgloss
|
||||
func (o Options) Run() error {
|
||||
text := strings.Join(o.Text, "\n")
|
||||
var text string
|
||||
if len(o.Text) > 0 {
|
||||
text = strings.Join(o.Text, "\n")
|
||||
} else {
|
||||
text, _ = stdin.Read()
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue