mirror of
https://github.com/charmbracelet/gum
synced 2024-05-23 16:42:22 +02:00
feat: add alignment for spinner title
Sometimes it is nice to spin to the right side of the title, not the left, so add a --align option to pick the left or right side. The default remains "left". New option is: --align="left|right" and the environment variable GUM_SPIN_ALIGN can also be used.
This commit is contained in:
parent
fa533691c4
commit
6677920319
|
@ -22,6 +22,7 @@ func (o Options) Run() error {
|
|||
spinner: s,
|
||||
title: o.TitleStyle.ToLipgloss().Render(o.Title),
|
||||
command: o.Command,
|
||||
align: o.Align,
|
||||
}
|
||||
p := tea.NewProgram(m, tea.WithOutput(os.Stderr))
|
||||
mm, err := p.StartReturningModel()
|
||||
|
|
|
@ -11,4 +11,5 @@ type Options struct {
|
|||
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"`
|
||||
TitleStyle style.Styles `embed:"" prefix:"title." envprefix:"GUM_SPIN_TITLE_"`
|
||||
Align string `help:"Alignment of spinner with regard to the title" short:"a" type:"align" enum:"left,right" default:"left" env:"GUM_SPIN_ALIGN"`
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import (
|
|||
type model struct {
|
||||
spinner spinner.Model
|
||||
title string
|
||||
align string
|
||||
command []string
|
||||
aborted bool
|
||||
|
||||
|
@ -73,7 +74,13 @@ func (m model) Init() tea.Cmd {
|
|||
commandStart(m.command),
|
||||
)
|
||||
}
|
||||
func (m model) View() string { return m.spinner.View() + " " + m.title }
|
||||
func (m model) View() string {
|
||||
if m.align == "left" {
|
||||
return m.spinner.View() + " " + m.title
|
||||
}
|
||||
|
||||
return m.title + " " + m.spinner.View()
|
||||
}
|
||||
|
||||
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
var cmd tea.Cmd
|
||||
|
|
Loading…
Reference in a new issue