mirror of
https://github.com/charmbracelet/gum
synced 2024-06-27 01:30:06 +02:00
49 lines
962 B
Go
49 lines
962 B
Go
package spin
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/alecthomas/kong"
|
|
"github.com/charmbracelet/bubbles/spinner"
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
"github.com/charmbracelet/gum/internal/exit"
|
|
"github.com/charmbracelet/gum/style"
|
|
)
|
|
|
|
// Run provides a shell script interface for the spinner bubble.
|
|
// https://github.com/charmbracelet/bubbles/spinner
|
|
func (o Options) Run() error {
|
|
s := spinner.New()
|
|
s.Style = o.SpinnerStyle.ToLipgloss()
|
|
s.Spinner = spinnerMap[o.Spinner]
|
|
m := model{
|
|
spinner: s,
|
|
title: o.TitleStyle.ToLipgloss().Render(o.Title),
|
|
command: o.Command,
|
|
}
|
|
p := tea.NewProgram(m)
|
|
mm, err := p.StartReturningModel()
|
|
m = mm.(model)
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if o.ShowOutput {
|
|
fmt.Print(m.output)
|
|
}
|
|
|
|
if m.aborted {
|
|
return exit.ErrAborted
|
|
}
|
|
|
|
os.Exit(m.status)
|
|
return nil
|
|
}
|
|
|
|
// BeforeReset hook. Used to unclutter style flags.
|
|
func (o Options) BeforeReset(ctx *kong.Context) error {
|
|
return style.HideFlags(ctx)
|
|
}
|