From 25a12fbbc6cf2a9f376bd6de1d084e31c8f4fd50 Mon Sep 17 00:00:00 2001 From: Maas Lalani Date: Wed, 6 Jul 2022 13:54:32 -0400 Subject: [PATCH] feat: `gum style` can take multiple arguments --- examples/demo.sh | 3 ++- main.go | 3 ++- style/command.go | 28 ---------------------------- style/options.go | 2 +- style/style.go | 30 ++++++++++++++++++++++++++++++ 5 files changed, 35 insertions(+), 31 deletions(-) delete mode 100644 style/command.go diff --git a/examples/demo.sh b/examples/demo.sh index a1db2d3..6f14b1e 100755 --- a/examples/demo.sh +++ b/examples/demo.sh @@ -36,4 +36,5 @@ echo "One sec, while I finish my drink." pop spin --title "Drinking some $POP soda pop..." --color 212 -- sleep 5 pop style --width 50 --padding "1 5" --margin "1 2" --border double --border-foreground 212 \ - "Well, it was nice meeting you, $(pop style --foreground 212 "$NAME"). Hope to see you soon! Don't forget to drink some $(pop style --foreground 212 $POP) soda pop." + "Well, it was nice meeting you, $(pop style --foreground 212 "$NAME"). Hope to see you soon!"\ + "Don't forget to drink some $(pop style --foreground 212 $POP) soda pop." diff --git a/main.go b/main.go index bd9779e..7e007bd 100644 --- a/main.go +++ b/main.go @@ -26,7 +26,8 @@ func main() { case "spin ": pop.Spin.Run() case "style": - pop.Style.Text, _ = stdin.Read() + input, _ := stdin.Read() + pop.Style.Text = []string{input} pop.Style.Run() case "style ": pop.Style.Run() diff --git a/style/command.go b/style/command.go deleted file mode 100644 index 8944fd4..0000000 --- a/style/command.go +++ /dev/null @@ -1,28 +0,0 @@ -package style - -import ( - "fmt" - - "github.com/charmbracelet/lipgloss" -) - -// Run provides a shell script interface for the Lip Gloss styling. -// https://github.com/charmbracelet/lipgloss -func (o Options) Run() { - fmt.Println(lipgloss.NewStyle(). - Foreground(lipgloss.Color(o.Foreground)). - Background(lipgloss.Color(o.Background)). - BorderBackground(lipgloss.Color(o.BorderBackground)). - BorderForeground(lipgloss.Color(o.BorderForeground)). - Align(align[o.Align]). - Bold(o.Bold). - Border(border[o.Border]). - Margin(parseMargin(o.Margin)). - Padding(parsePadding(o.Padding)). - Height(o.Height). - Width(o.Width). - Faint(o.Faint). - Italic(o.Italic). - Strikethrough(o.Strikethrough). - Render(o.Text)) -} diff --git a/style/options.go b/style/options.go index 14c14fc..37089d5 100644 --- a/style/options.go +++ b/style/options.go @@ -2,7 +2,7 @@ package style // Options is the customization options for the style command. type Options struct { - Text string `arg:"" optional:"" help:"Text to style"` + Text []string `arg:"" optional:"" help:"Text to style"` Background string `help:"Background color"` Foreground string `help:"Foreground color"` diff --git a/style/style.go b/style/style.go index 0b97628..e819d1d 100644 --- a/style/style.go +++ b/style/style.go @@ -1 +1,31 @@ package style + +import ( + "fmt" + "strings" + + "github.com/charmbracelet/lipgloss" +) + +// Run provides a shell script interface for the Lip Gloss styling. +// https://github.com/charmbracelet/lipgloss +func (o Options) Run() { + text := strings.Join(o.Text, " ") + + fmt.Println(lipgloss.NewStyle(). + Foreground(lipgloss.Color(o.Foreground)). + Background(lipgloss.Color(o.Background)). + BorderBackground(lipgloss.Color(o.BorderBackground)). + BorderForeground(lipgloss.Color(o.BorderForeground)). + Align(align[o.Align]). + Bold(o.Bold). + Border(border[o.Border]). + Margin(parseMargin(o.Margin)). + Padding(parsePadding(o.Padding)). + Height(o.Height). + Width(o.Width). + Faint(o.Faint). + Italic(o.Italic). + Strikethrough(o.Strikethrough). + Render(text)) +}