forked from Mirrors/bubbletea
chore: rename StartReturningModel to Run
Added aliases for the old functions, but deprecated them.
This commit is contained in:
parent
22d15efad7
commit
6b77c8fc10
|
@ -239,7 +239,7 @@ The last step is to simply run our program. We pass our initial model to
|
|||
```go
|
||||
func main() {
|
||||
p := tea.NewProgram(initialModel())
|
||||
if err := p.Start(); err != nil {
|
||||
if _, err := p.Run(); err != nil {
|
||||
fmt.Printf("Alas, there's been an error: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ func (m model) View() string {
|
|||
}
|
||||
|
||||
func main() {
|
||||
if err := tea.NewProgram(model{}).Start(); err != nil {
|
||||
if _, err := tea.NewProgram(model{}).Run(); err != nil {
|
||||
fmt.Println("Error running program:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ import (
|
|||
func main() {
|
||||
p := tea.NewProgram(initialModel())
|
||||
|
||||
if err := p.Start(); err != nil {
|
||||
if _, err := p.Run(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -156,7 +156,7 @@ func (m *mainModel) resetSpinner() {
|
|||
func main() {
|
||||
p := tea.NewProgram(newModel(defaultTime))
|
||||
|
||||
if err := p.Start(); err != nil {
|
||||
if _, err := p.Run(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
func main() {
|
||||
p := tea.NewProgram(initialModel())
|
||||
|
||||
if err := p.Start(); err != nil {
|
||||
if _, err := p.Run(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ func (m model) View() string {
|
|||
}
|
||||
|
||||
func main() {
|
||||
if err := tea.NewProgram(model{}).Start(); err != nil {
|
||||
if _, err := tea.NewProgram(model{}).Run(); err != nil {
|
||||
fmt.Println("uh oh:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ func (m model) View() string {
|
|||
|
||||
func main() {
|
||||
m := model{}
|
||||
if err := tea.NewProgram(m).Start(); err != nil {
|
||||
if _, err := tea.NewProgram(m).Run(); err != nil {
|
||||
fmt.Println("Error running program:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ type tickMsg time.Time
|
|||
|
||||
func main() {
|
||||
p := tea.NewProgram(model(5), tea.WithAltScreen())
|
||||
if err := p.Start(); err != nil {
|
||||
if _, err := p.Run(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -120,7 +120,7 @@ func main() {
|
|||
os.Exit(1)
|
||||
}
|
||||
|
||||
if err := tea.NewProgram(model).Start(); err != nil {
|
||||
if _, err := tea.NewProgram(model).Run(); err != nil {
|
||||
fmt.Println("Bummer, there's been an error:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
|
@ -140,7 +140,7 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
if err := tea.NewProgram(newModel()).Start(); err != nil {
|
||||
if _, err := tea.NewProgram(newModel()).Run(); err != nil {
|
||||
fmt.Printf("Could not start program :(\n%v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ func (e errMsg) Error() string { return e.error.Error() }
|
|||
|
||||
func main() {
|
||||
p := tea.NewProgram(model{})
|
||||
if err := p.Start(); err != nil {
|
||||
if _, err := p.Run(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ func main() {
|
|||
|
||||
p := tea.NewProgram(m, tea.WithAltScreen())
|
||||
|
||||
if err := p.Start(); err != nil {
|
||||
if _, err := p.Run(); err != nil {
|
||||
fmt.Println("Error running program:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
|
@ -183,7 +183,7 @@ func (m model) View() string {
|
|||
func main() {
|
||||
rand.Seed(time.Now().UTC().UnixNano())
|
||||
|
||||
if err := tea.NewProgram(newModel()).Start(); err != nil {
|
||||
if _, err := tea.NewProgram(newModel()).Run(); err != nil {
|
||||
fmt.Println("Error running program:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
|
@ -120,7 +120,7 @@ func main() {
|
|||
|
||||
m := model{list: l}
|
||||
|
||||
if err := tea.NewProgram(m).Start(); err != nil {
|
||||
if _, err := tea.NewProgram(m).Run(); err != nil {
|
||||
fmt.Println("Error running program:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import (
|
|||
|
||||
func main() {
|
||||
p := tea.NewProgram(model{}, tea.WithAltScreen(), tea.WithMouseAllMotion())
|
||||
if err := p.Start(); err != nil {
|
||||
if _, err := p.Run(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -131,7 +131,7 @@ func max(a, b int) int {
|
|||
func main() {
|
||||
rand.Seed(time.Now().Unix())
|
||||
|
||||
if err := tea.NewProgram(newModel()).Start(); err != nil {
|
||||
if _, err := tea.NewProgram(newModel()).Run(); err != nil {
|
||||
fmt.Println("Error running program:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
|
@ -141,7 +141,7 @@ func main() {
|
|||
tea.WithMouseCellMotion(), // turn on mouse support so we can track the mouse wheel
|
||||
)
|
||||
|
||||
if err := p.Start(); err != nil {
|
||||
if _, err := p.Run(); err != nil {
|
||||
fmt.Println("could not run program:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ func (m model) View() string {
|
|||
|
||||
func main() {
|
||||
p := tea.NewProgram(newModel())
|
||||
if err := p.Start(); err != nil {
|
||||
if _, err := p.Run(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ func main() {
|
|||
|
||||
model := newModel(strings.TrimSpace(b.String()))
|
||||
|
||||
if err := tea.NewProgram(model).Start(); err != nil {
|
||||
if _, err := tea.NewProgram(model).Run(); err != nil {
|
||||
fmt.Println("Couldn't start program:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ func main() {
|
|||
progress: progress.New(progress.WithDefaultGradient()),
|
||||
}
|
||||
|
||||
if err := tea.NewProgram(m).Start(); err != nil {
|
||||
if _, err := tea.NewProgram(m).Run(); err != nil {
|
||||
fmt.Println("Oh no!", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
|
@ -100,7 +100,7 @@ func main() {
|
|||
// Start the download
|
||||
go pw.Start()
|
||||
|
||||
if err := p.Start(); err != nil {
|
||||
if _, err := p.Run(); err != nil {
|
||||
fmt.Println("error running program:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ var helpStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#626262")).Render
|
|||
func main() {
|
||||
prog := progress.New(progress.WithScaledGradient("#FF7CCB", "#FDFF8C"))
|
||||
|
||||
if err := tea.NewProgram(model{progress: prog}).Start(); err != nil {
|
||||
if _, err := tea.NewProgram(model{progress: prog}).Run(); err != nil {
|
||||
fmt.Println("Oh no!", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
|
@ -85,8 +85,8 @@ func main() {
|
|||
spinner: spinner.New(),
|
||||
})
|
||||
|
||||
if p.Start() != nil {
|
||||
fmt.Println("could not start program")
|
||||
if _, err := p.Run(); err != nil {
|
||||
fmt.Println("could not start program:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,8 +72,8 @@ func (m model) View() string {
|
|||
func main() {
|
||||
p := tea.NewProgram(model{})
|
||||
|
||||
// StartReturningModel returns the model as a tea.Model.
|
||||
m, err := p.StartReturningModel()
|
||||
// Run returns the model as a tea.Model.
|
||||
m, err := p.Run()
|
||||
if err != nil {
|
||||
fmt.Println("Oh no:", err)
|
||||
os.Exit(1)
|
||||
|
|
|
@ -117,7 +117,7 @@ func main() {
|
|||
}
|
||||
}()
|
||||
|
||||
if err := p.Start(); err != nil {
|
||||
if _, err := p.Run(); err != nil {
|
||||
fmt.Println("Error running program:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ func (m model) View() string {
|
|||
}
|
||||
|
||||
func main() {
|
||||
if err := tea.NewProgram(model{}).Start(); err != nil {
|
||||
if _, err := tea.NewProgram(model{}).Run(); err != nil {
|
||||
fmt.Println("Uh oh:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ func main() {
|
|||
|
||||
// Initialize our program
|
||||
p := tea.NewProgram(model(5))
|
||||
if err := p.Start(); err != nil {
|
||||
if _, err := p.Run(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ func (m model) View() string {
|
|||
|
||||
func main() {
|
||||
p := tea.NewProgram(initialModel())
|
||||
if err := p.Start(); err != nil {
|
||||
if _, err := p.Run(); err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ func main() {
|
|||
m := model{}
|
||||
m.resetSpinner()
|
||||
|
||||
if err := tea.NewProgram(m).Start(); err != nil {
|
||||
if _, err := tea.NewProgram(m).Run(); err != nil {
|
||||
fmt.Println("could not run program:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
|
@ -197,7 +197,7 @@ func (m model) View() string {
|
|||
}
|
||||
|
||||
func main() {
|
||||
if err := tea.NewProgram(newModel(), tea.WithAltScreen()).Start(); err != nil {
|
||||
if _, err := tea.NewProgram(newModel(), tea.WithAltScreen()).Run(); err != nil {
|
||||
fmt.Println("Error while running program:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
|
@ -96,7 +96,7 @@ func main() {
|
|||
|
||||
m.keymap.start.SetEnabled(false)
|
||||
|
||||
if err := tea.NewProgram(m).Start(); err != nil {
|
||||
if _, err := tea.NewProgram(m).Run(); err != nil {
|
||||
fmt.Println("Oh no, it didn't work:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
|
@ -177,7 +177,7 @@ func main() {
|
|||
t.SetStyles(s)
|
||||
|
||||
m := model{t}
|
||||
if err := tea.NewProgram(m).Start(); err != nil {
|
||||
if _, err := tea.NewProgram(m).Run(); err != nil {
|
||||
fmt.Println("Error running program:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@ func main() {
|
|||
tabs := []string{"Lip Gloss", "Blush", "Eye Shadow", "Mascara", "Foundation"}
|
||||
tabContent := []string{"Lip Gloss Tab", "Blush Tab", "Eye Shadow Tab", "Mascara Tab", "Foundation Tab"}
|
||||
m := model{Tabs: tabs, TabContent: tabContent}
|
||||
if err := tea.NewProgram(m).Start(); err != nil {
|
||||
if _, err := tea.NewProgram(m).Run(); err != nil {
|
||||
fmt.Println("Error running program:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
func main() {
|
||||
p := tea.NewProgram(initialModel())
|
||||
|
||||
if err := p.Start(); err != nil {
|
||||
if _, err := p.Run(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,8 +13,7 @@ import (
|
|||
|
||||
func main() {
|
||||
p := tea.NewProgram(initialModel())
|
||||
|
||||
if err := p.Start(); err != nil {
|
||||
if _, err := p.Run(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -170,7 +170,7 @@ func (m model) View() string {
|
|||
}
|
||||
|
||||
func main() {
|
||||
if err := tea.NewProgram(initialModel()).Start(); err != nil {
|
||||
if _, err := tea.NewProgram(initialModel()).Run(); err != nil {
|
||||
fmt.Printf("could not start program: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
|
@ -115,7 +115,7 @@ func main() {
|
|||
}
|
||||
m.keymap.start.SetEnabled(false)
|
||||
|
||||
if err := tea.NewProgram(m).Start(); err != nil {
|
||||
if _, err := tea.NewProgram(m).Run(); err != nil {
|
||||
fmt.Println("Uh oh, we encountered an error:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ func main() {
|
|||
}
|
||||
|
||||
p := tea.NewProgram(newModel(), opts...)
|
||||
if err := p.Start(); err != nil {
|
||||
if _, err := p.Run(); err != nil {
|
||||
fmt.Println("Error starting Bubble Tea program:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ var (
|
|||
func main() {
|
||||
initialModel := model{0, false, 10, 0, 0, false, false}
|
||||
p := tea.NewProgram(initialModel)
|
||||
if err := p.Start(); err != nil {
|
||||
if _, err := p.Run(); err != nil {
|
||||
fmt.Println("could not start program:", err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ func TestTeaExec(t *testing.T) {
|
|||
|
||||
m := &testExecModel{}
|
||||
p := NewProgram(m, WithInput(&in), WithOutput(&buf))
|
||||
if err := p.Start(); err != nil {
|
||||
if _, err := p.Run(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ func WithoutCatchPanics() ProgramOption {
|
|||
// Example:
|
||||
//
|
||||
// p := tea.NewProgram(Model{}, tea.WithAltScreen())
|
||||
// if err := p.Start(); err != nil {
|
||||
// if _, err := p.Run(); err != nil {
|
||||
// fmt.Println("Error running program:", err)
|
||||
// os.Exit(1)
|
||||
// }
|
||||
|
|
21
tea.go
21
tea.go
|
@ -335,10 +335,10 @@ func (p *Program) eventLoop(model Model, cmds chan Cmd) (Model, error) {
|
|||
}
|
||||
}
|
||||
|
||||
// StartReturningModel initializes the program and runs its event loops,
|
||||
// blocking until it gets terminated by either [Program.Quit], [Program.Kill],
|
||||
// or its signal handler. Returns the final model.
|
||||
func (p *Program) StartReturningModel() (Model, error) {
|
||||
// Run initializes the program and runs its event loops, blocking until it gets
|
||||
// terminated by either [Program.Quit], [Program.Kill], or its signal handler.
|
||||
// Returns the final model.
|
||||
func (p *Program) Run() (Model, error) {
|
||||
handlers := handlers{}
|
||||
cmds := make(chan Cmd)
|
||||
p.errs = make(chan error)
|
||||
|
@ -475,11 +475,22 @@ func (p *Program) StartReturningModel() (Model, error) {
|
|||
return model, err
|
||||
}
|
||||
|
||||
// StartReturningModel initializes the program and runs its event loops,
|
||||
// blocking until it gets terminated by either [Program.Quit], [Program.Kill],
|
||||
// or its signal handler. Returns the final model.
|
||||
//
|
||||
// Deprecated: please use [Program.Run] instead.
|
||||
func (p *Program) StartReturningModel() (Model, error) {
|
||||
return p.Run()
|
||||
}
|
||||
|
||||
// Start initializes the program and runs its event loops, blocking until it
|
||||
// gets terminated by either [Program.Quit], [Program.Kill], or its signal
|
||||
// handler.
|
||||
//
|
||||
// Deprecated: please use [Program.Run] instead.
|
||||
func (p *Program) Start() error {
|
||||
_, err := p.StartReturningModel()
|
||||
_, err := p.Run()
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ func TestTeaModel(t *testing.T) {
|
|||
in.Write([]byte("q"))
|
||||
|
||||
p := NewProgram(&testModel{}, WithInput(&in), WithOutput(&buf))
|
||||
if err := p.Start(); err != nil {
|
||||
if _, err := p.Run(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ func TestTeaQuit(t *testing.T) {
|
|||
}
|
||||
}()
|
||||
|
||||
if err := p.Start(); err != nil {
|
||||
if _, err := p.Run(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ func TestTeaKill(t *testing.T) {
|
|||
}
|
||||
}()
|
||||
|
||||
if err := p.Start(); err != nil {
|
||||
if _, err := p.Run(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -200,7 +200,7 @@ The last step is to simply run our program. We pass our initial model to
|
|||
```go
|
||||
func main() {
|
||||
p := tea.NewProgram(initialModel())
|
||||
if err := p.Start(); err != nil {
|
||||
if _, err := p.Run(); err != nil {
|
||||
fmt.Printf("Alas, there's been an error: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ func (m model) View() string {
|
|||
|
||||
func main() {
|
||||
p := tea.NewProgram(initialModel())
|
||||
if err := p.Start(); err != nil {
|
||||
if _, err := p.Run(); err != nil {
|
||||
fmt.Printf("Alas, there's been an error: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
|
@ -169,7 +169,7 @@ as a `struct` with defaults.
|
|||
|
||||
```go
|
||||
func main() {
|
||||
if err := tea.NewProgram(model{}).Start(); err != nil {
|
||||
if _, err := tea.NewProgram(model{}).Run(); err != nil {
|
||||
fmt.Printf("Uh oh, there was an error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ func (m model) View() string {
|
|||
}
|
||||
|
||||
func main() {
|
||||
if err := tea.NewProgram(model{}).Start(); err != nil {
|
||||
if _, err := tea.NewProgram(model{}).Run(); err != nil {
|
||||
fmt.Printf("Uh oh, there was an error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue