Skip to content
Myr

command.go

This file

Path

style/command.go

37 lines · 974 bytes · Go

Last changed by

chore: prepare v2 (#1116)Drew Smirnoffbefore adoption02d6f06

History of this file

Take it

1// Package style provides a shell script interface for Lip Gloss.2// https://github.com/charmbracelet/lipgloss3//4// It allows you to use Lip Gloss to style text without needing to use Go. All5// of the styling options are available as flags.6package style78import (9	"errors"10	"strings"1112	"charm.land/gum/v2/internal/stdin"13	"charm.land/gum/v2/internal/tty"14)1516// Run provides a shell script interface for the Lip Gloss styling.17// https://github.com/charmbracelet/lipgloss18func (o Options) Run() error {19	var text string20	if len(o.Text) > 0 {21		text = strings.Join(o.Text, "\n")22	} else {23		text, _ = stdin.Read(stdin.StripANSI(o.StripANSI))24		if text == "" {25			return errors.New("no input provided, see `gum style --help`")26		}27	}28	if o.Trim {29		var lines []string30		for _, line := range strings.Split(text, "\n") {31			lines = append(lines, strings.TrimSpace(line))32		}33		text = strings.Join(lines, "\n")34	}35	tty.Println(o.Style.ToLipgloss().Render(text))36	return nil37}