2022-07-13 15:55:36 +02:00
|
|
|
// 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.
|
2022-07-06 18:09:35 +02:00
|
|
|
package style
|
2022-07-06 19:54:32 +02:00
|
|
|
|
|
|
|
import (
|
2022-11-10 05:13:21 +01:00
|
|
|
"errors"
|
2022-07-06 19:54:32 +02:00
|
|
|
"fmt"
|
|
|
|
"strings"
|
2022-07-20 19:39:22 +02:00
|
|
|
|
2022-11-10 05:13:21 +01:00
|
|
|
"github.com/charmbracelet/gum/internal/stdin"
|
2022-07-06 19:54:32 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// Run provides a shell script interface for the Lip Gloss styling.
|
|
|
|
// https://github.com/charmbracelet/lipgloss
|
2022-07-13 04:12:02 +02:00
|
|
|
func (o Options) Run() error {
|
2022-11-10 05:13:21 +01:00
|
|
|
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")
|
|
|
|
}
|
2022-07-12 22:05:40 +02:00
|
|
|
fmt.Println(o.Style.ToLipgloss().Render(text))
|
2022-07-13 04:12:02 +02:00
|
|
|
return nil
|
2022-07-06 19:54:32 +02:00
|
|
|
}
|