mirror of
https://github.com/charmbracelet/gum
synced 2024-06-01 21:32:15 +02:00
Fixed spinner alignment. Updated Readme
This commit is contained in:
parent
6d175acd69
commit
f6dcdbc4c0
|
@ -294,13 +294,12 @@ gum pager < README.md
|
|||
Display a spinner while running a script or command. The spinner will
|
||||
automatically stop after the given command exits.
|
||||
|
||||
To view the command's output during execution, use the `--show-output` flag.
|
||||
To view or pipe the command's output, use the `--show-output` flag.
|
||||
|
||||
```bash
|
||||
gum spin --spinner dot --title "Buying Bubble Gum..." -- sleep 5
|
||||
```
|
||||
|
||||
|
||||
<img src="https://stuff.charm.sh/gum/spin.gif" width="600" alt="Shell running gum spin while sleeping for 5 seconds" />
|
||||
|
||||
Available spinner types include: `line`, `dot`, `minidot`, `jump`, `pulse`, `points`, `globe`, `moon`, `monkey`, `meter`, `hamburger`.
|
||||
|
|
|
@ -6,7 +6,7 @@ import "github.com/charmbracelet/gum/style"
|
|||
type Options struct {
|
||||
Command []string `arg:"" help:"Command to run"`
|
||||
|
||||
ShowOutput bool `help:"Show output of command during execution" default:"false" env:"GUM_SPIN_SHOW_OUTPUT"`
|
||||
ShowOutput bool `help:"Show or pipe output of command during execution" default:"false" env:"GUM_SPIN_SHOW_OUTPUT"`
|
||||
Spinner string `help:"Spinner type" short:"s" type:"spinner" enum:"line,dot,minidot,jump,pulse,points,globe,moon,monkey,meter,hamburger" default:"dot" env:"GUM_SPIN_SPINNER"`
|
||||
SpinnerStyle style.Styles `embed:"" prefix:"spinner." set:"defaultForeground=212" envprefix:"GUM_SPIN_SPINNER_"`
|
||||
Title string `help:"Text to display to user while spinning" default:"Loading..." env:"GUM_SPIN_TITLE"`
|
||||
|
|
24
spin/spin.go
24
spin/spin.go
|
@ -23,20 +23,20 @@ import (
|
|||
"github.com/charmbracelet/lipgloss"
|
||||
)
|
||||
|
||||
var outbuf strings.Builder
|
||||
var errbuf strings.Builder
|
||||
|
||||
type model struct {
|
||||
spinner spinner.Model
|
||||
title string
|
||||
align string
|
||||
command []string
|
||||
aborted bool
|
||||
showOutput bool
|
||||
status int
|
||||
stdout string
|
||||
showOutput bool
|
||||
}
|
||||
|
||||
var outbuf strings.Builder
|
||||
var errbuf strings.Builder
|
||||
|
||||
type finishCommandMsg struct {
|
||||
stdout string
|
||||
status int
|
||||
|
@ -75,16 +75,14 @@ func (m model) Init() tea.Cmd {
|
|||
)
|
||||
}
|
||||
func (m model) View() string {
|
||||
var header string = m.spinner.View() + " " + m.title
|
||||
var leftHeader string = m.title + " " + m.spinner.View()
|
||||
if !m.showOutput {
|
||||
if m.align == "left" {
|
||||
return leftHeader
|
||||
}
|
||||
return header
|
||||
}
|
||||
var header string
|
||||
if m.align == "left" {
|
||||
return lipgloss.JoinVertical(lipgloss.Top, leftHeader, errbuf.String(), outbuf.String())
|
||||
header = m.spinner.View() + " " + m.title
|
||||
} else {
|
||||
header = m.title + " " + m.spinner.View()
|
||||
}
|
||||
if !m.showOutput {
|
||||
return header
|
||||
}
|
||||
return lipgloss.JoinVertical(lipgloss.Top, header, errbuf.String(), outbuf.String())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue