gum/style/command.go

38 lines
917 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 (
"fmt"
"strings"
2022-07-20 19:39:22 +02:00
"github.com/alecthomas/kong"
)
// Run provides a shell script interface for the Lip Gloss styling.
// https://github.com/charmbracelet/lipgloss
func (o Options) Run() error {
2022-07-07 19:26:35 +02:00
text := strings.Join(o.Text, "\n")
fmt.Println(o.Style.ToLipgloss().Render(text))
return nil
}
2022-07-20 19:39:22 +02:00
// HideFlags hides the flags from the usage output. This is used in conjunction
// with BeforeReset hook.
2022-08-05 00:45:19 +02:00
func HideFlags(ctx *kong.Context) {
2022-07-20 19:39:22 +02:00
n := ctx.Selected()
if n == nil {
2022-08-05 00:45:19 +02:00
return
2022-07-20 19:39:22 +02:00
}
for _, f := range n.Flags {
if g := f.Group; g != nil && g.Key == groupName {
if !strings.HasSuffix(f.Name, ".foreground") {
2022-07-20 19:39:22 +02:00
f.Hidden = true
}
}
}
}