feat: Add gum join command

This commit is contained in:
Maas Lalani 2022-07-07 19:28:44 -04:00
parent fa4f09a413
commit 53aa5c6a90
No known key found for this signature in database
GPG key ID: 5A6ED5CBF1A0A000
7 changed files with 40 additions and 6 deletions

View file

@ -1 +0,0 @@
I love Bubble Gum <3

6
gum.go
View file

@ -2,6 +2,7 @@ package main
import (
"github.com/charmbracelet/gum/input"
"github.com/charmbracelet/gum/join"
"github.com/charmbracelet/gum/progress"
"github.com/charmbracelet/gum/search"
"github.com/charmbracelet/gum/spin"
@ -93,4 +94,9 @@ type Gum struct {
// ╚══════════════════════════════════════════════════╝
//
Style style.Options `cmd:"" help:"Style some text."`
// Join provides a shell script interface for the lipgloss JoinHorizontal
// and JoinVertical commands.
//
Join join.Options `cmd:"" help:"Join text horizontally or vertically"`
}

View file

@ -1,9 +1,9 @@
package style
package decode
import "github.com/charmbracelet/lipgloss"
// align maps strings to `lipgloss.Position`s
var align = map[string]lipgloss.Position{
// Align maps strings to `lipgloss.Position`s
var Align = map[string]lipgloss.Position{
"center": lipgloss.Center,
"left": lipgloss.Left,
"top": lipgloss.Top,

17
join/command.go Normal file
View file

@ -0,0 +1,17 @@
package join
import (
"fmt"
"github.com/charmbracelet/gum/internal/decode"
"github.com/charmbracelet/lipgloss"
)
// Run is the command-line interface for the joining strings through lipgloss.
func (o Options) Run() {
join := lipgloss.JoinHorizontal
if o.Vertical {
join = lipgloss.JoinVertical
}
fmt.Println(join(decode.Align[o.Align], o.Text...))
}

10
join/options.go Normal file
View file

@ -0,0 +1,10 @@
package join
// Options is the set
type Options struct {
Text []string `arg:"" help:"Text to join."`
Align string `help:"Text alignment" enum:"left,center,right,bottom,middle,top" default:"left"`
Horizontal bool `help:"Join (potentially multi-line) strings horizontally"`
Vertical bool `help:"Join (potentially multi-line) strings vertically"`
}

View file

@ -35,6 +35,7 @@ func main() {
gum.Style.Run()
case "style <text>":
gum.Style.Run()
case "layout":
case "join <text>":
gum.Join.Run()
}
}

View file

@ -4,6 +4,7 @@ import (
"fmt"
"strings"
"github.com/charmbracelet/gum/internal/decode"
"github.com/charmbracelet/lipgloss"
)
@ -17,7 +18,7 @@ func (o Options) Run() {
Background(lipgloss.Color(o.Background)).
BorderBackground(lipgloss.Color(o.BorderBackground)).
BorderForeground(lipgloss.Color(o.BorderForeground)).
Align(align[o.Align]).
Align(decode.Align[o.Align]).
Bold(o.Bold).
Border(border[o.Border]).
Margin(parseMargin(o.Margin)).