mirror of
https://github.com/charmbracelet/gum
synced 2024-05-17 05:36:42 +02:00
feat: Add gum join
command
This commit is contained in:
parent
fa4f09a413
commit
53aa5c6a90
|
@ -1 +0,0 @@
|
|||
I love Bubble Gum <3
|
6
gum.go
6
gum.go
|
@ -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"`
|
||||
}
|
||||
|
|
|
@ -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
17
join/command.go
Normal 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
10
join/options.go
Normal 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"`
|
||||
}
|
3
main.go
3
main.go
|
@ -35,6 +35,7 @@ func main() {
|
|||
gum.Style.Run()
|
||||
case "style <text>":
|
||||
gum.Style.Run()
|
||||
case "layout":
|
||||
case "join <text>":
|
||||
gum.Join.Run()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)).
|
Loading…
Reference in a new issue