gum/style/command.go

32 lines
793 B
Go
Raw Normal View History

// Package style provides a shell script interface for Lip Gloss.
// https://github.com/charmbracelet/lipgloss
//
// It allows you to use Lip Gloss to style text without needing to use Go. All
// of the styling options are available as flags.
package style
import (
"errors"
"fmt"
"strings"
2022-07-20 19:39:22 +02:00
"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 {
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
}