mirror of
https://github.com/charmbracelet/gum
synced 2024-06-07 00:02:35 +02:00
02e925ea57
This commit uses the embedded style struct for styling in all components. The most notable example is `gum write` where there are many styles that are used and composed for each component of the command.
47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
package choose
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/charmbracelet/bubbles/list"
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
"github.com/mattn/go-runewidth"
|
|
)
|
|
|
|
// Run provides a shell script interface for choosing between different through
|
|
// options.
|
|
func (o Options) Run() {
|
|
items := []list.Item{}
|
|
for _, option := range o.Options {
|
|
if option == "" {
|
|
continue
|
|
}
|
|
items = append(items, item(option))
|
|
}
|
|
|
|
const defaultWidth = 20
|
|
|
|
id := itemDelegate{
|
|
indicator: o.Indicator,
|
|
indicatorStyle: o.IndicatorStyle.ToLipgloss(),
|
|
selectedItemStyle: o.SelectedStyle.ToLipgloss(),
|
|
itemStyle: o.ItemStyle.ToLipgloss().MarginLeft(runewidth.StringWidth(o.Indicator)),
|
|
}
|
|
|
|
l := list.New(items, id, defaultWidth, o.Height)
|
|
l.SetShowTitle(false)
|
|
l.SetShowStatusBar(false)
|
|
l.SetFilteringEnabled(false)
|
|
l.SetShowHelp(false)
|
|
l.SetShowPagination(!o.HidePagination)
|
|
|
|
m, err := tea.NewProgram(model{list: l}, tea.WithOutput(os.Stderr)).StartReturningModel()
|
|
|
|
if err != nil {
|
|
fmt.Println("Error running program:", err)
|
|
os.Exit(1)
|
|
}
|
|
fmt.Println(m.(model).choice)
|
|
}
|