Skip to content

Commit

Permalink
Fixed spinner alignment. Updated Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
hopefulTex committed Jun 23, 2023
1 parent 6d175ac commit f6dcdbc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
2 changes: 1 addition & 1 deletion spin/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
22 changes: 10 additions & 12 deletions spin/spin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -75,17 +75,15 @@ 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()
var header string
if m.align == "left" {
header = m.spinner.View() + " " + m.title
} else {
header = m.title + " " + m.spinner.View()
}
if !m.showOutput {
if m.align == "left" {
return leftHeader
}
return header
}
if m.align == "left" {
return lipgloss.JoinVertical(lipgloss.Top, leftHeader, errbuf.String(), outbuf.String())
}
return lipgloss.JoinVertical(lipgloss.Top, header, errbuf.String(), outbuf.String())
}

Expand Down

0 comments on commit f6dcdbc

Please sign in to comment.