diff --git a/README.md b/README.md index 031f170..490e252 100644 --- a/README.md +++ b/README.md @@ -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) } diff --git a/examples/altscreen-toggle/main.go b/examples/altscreen-toggle/main.go index 539ee52..54a3f09 100644 --- a/examples/altscreen-toggle/main.go +++ b/examples/altscreen-toggle/main.go @@ -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) } diff --git a/examples/chat/main.go b/examples/chat/main.go index b9994f3..4a573d5 100644 --- a/examples/chat/main.go +++ b/examples/chat/main.go @@ -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) } } diff --git a/examples/composable-views/main.go b/examples/composable-views/main.go index 1dbe4f9..f81ce6a 100644 --- a/examples/composable-views/main.go +++ b/examples/composable-views/main.go @@ -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) } } diff --git a/examples/credit-card-form/main.go b/examples/credit-card-form/main.go index 3eae556..5ac6854 100644 --- a/examples/credit-card-form/main.go +++ b/examples/credit-card-form/main.go @@ -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) } } diff --git a/examples/debounce/main.go b/examples/debounce/main.go index 834f521..d22fe4d 100644 --- a/examples/debounce/main.go +++ b/examples/debounce/main.go @@ -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) } diff --git a/examples/exec/main.go b/examples/exec/main.go index 709efe8..0c8965b 100644 --- a/examples/exec/main.go +++ b/examples/exec/main.go @@ -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) } diff --git a/examples/fullscreen/main.go b/examples/fullscreen/main.go index de8cf0f..1c56be0 100644 --- a/examples/fullscreen/main.go +++ b/examples/fullscreen/main.go @@ -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) } } diff --git a/examples/glamour/main.go b/examples/glamour/main.go index 3b38911..976ee3b 100644 --- a/examples/glamour/main.go +++ b/examples/glamour/main.go @@ -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) } diff --git a/examples/help/main.go b/examples/help/main.go index e1ecc01..caedc9e 100644 --- a/examples/help/main.go +++ b/examples/help/main.go @@ -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) } diff --git a/examples/http/main.go b/examples/http/main.go index b1ef0f3..1b6a1e6 100644 --- a/examples/http/main.go +++ b/examples/http/main.go @@ -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) } } diff --git a/examples/list-default/main.go b/examples/list-default/main.go index 5c5fcc8..91be1df 100644 --- a/examples/list-default/main.go +++ b/examples/list-default/main.go @@ -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) } diff --git a/examples/list-fancy/main.go b/examples/list-fancy/main.go index 69617cb..3646ceb 100644 --- a/examples/list-fancy/main.go +++ b/examples/list-fancy/main.go @@ -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) } diff --git a/examples/list-simple/main.go b/examples/list-simple/main.go index 3400e71..9208d05 100644 --- a/examples/list-simple/main.go +++ b/examples/list-simple/main.go @@ -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) } diff --git a/examples/mouse/main.go b/examples/mouse/main.go index f3ba0bd..ea5c11d 100644 --- a/examples/mouse/main.go +++ b/examples/mouse/main.go @@ -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) } } diff --git a/examples/package-manager/main.go b/examples/package-manager/main.go index 5fcae51..ced7c77 100644 --- a/examples/package-manager/main.go +++ b/examples/package-manager/main.go @@ -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) } diff --git a/examples/pager/main.go b/examples/pager/main.go index 67b6a48..a98a9ec 100644 --- a/examples/pager/main.go +++ b/examples/pager/main.go @@ -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) } diff --git a/examples/paginator/main.go b/examples/paginator/main.go index 35356d5..6eb1190 100644 --- a/examples/paginator/main.go +++ b/examples/paginator/main.go @@ -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) } } diff --git a/examples/pipe/main.go b/examples/pipe/main.go index b138f9e..5d7e0ac 100644 --- a/examples/pipe/main.go +++ b/examples/pipe/main.go @@ -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) } diff --git a/examples/progress-animated/main.go b/examples/progress-animated/main.go index ad8f282..be75bb1 100644 --- a/examples/progress-animated/main.go +++ b/examples/progress-animated/main.go @@ -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) } diff --git a/examples/progress-download/main.go b/examples/progress-download/main.go index 9da62fc..4639aa1 100644 --- a/examples/progress-download/main.go +++ b/examples/progress-download/main.go @@ -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) } diff --git a/examples/progress-static/main.go b/examples/progress-static/main.go index 9ea4105..a96a731 100644 --- a/examples/progress-static/main.go +++ b/examples/progress-static/main.go @@ -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) } diff --git a/examples/realtime/main.go b/examples/realtime/main.go index 3390d81..516fcd6 100644 --- a/examples/realtime/main.go +++ b/examples/realtime/main.go @@ -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) } } diff --git a/examples/result/main.go b/examples/result/main.go index 60d55a3..e0d7265 100644 --- a/examples/result/main.go +++ b/examples/result/main.go @@ -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) diff --git a/examples/send-msg/main.go b/examples/send-msg/main.go index d1cf552..7badf6a 100644 --- a/examples/send-msg/main.go +++ b/examples/send-msg/main.go @@ -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) } diff --git a/examples/sequence/main.go b/examples/sequence/main.go index 79f7e23..200b738 100644 --- a/examples/sequence/main.go +++ b/examples/sequence/main.go @@ -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) } diff --git a/examples/simple/main.go b/examples/simple/main.go index 1ba8d10..478f95a 100644 --- a/examples/simple/main.go +++ b/examples/simple/main.go @@ -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) } } diff --git a/examples/spinner/main.go b/examples/spinner/main.go index cad4549..de67b40 100644 --- a/examples/spinner/main.go +++ b/examples/spinner/main.go @@ -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) } diff --git a/examples/spinners/main.go b/examples/spinners/main.go index 53e5853..84e437f 100644 --- a/examples/spinners/main.go +++ b/examples/spinners/main.go @@ -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) } diff --git a/examples/split-editors/main.go b/examples/split-editors/main.go index 5e7f404..9009bb7 100644 --- a/examples/split-editors/main.go +++ b/examples/split-editors/main.go @@ -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) } diff --git a/examples/stopwatch/main.go b/examples/stopwatch/main.go index e203327..69884b1 100644 --- a/examples/stopwatch/main.go +++ b/examples/stopwatch/main.go @@ -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) } diff --git a/examples/table/main.go b/examples/table/main.go index b0f529f..76736f3 100644 --- a/examples/table/main.go +++ b/examples/table/main.go @@ -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) } diff --git a/examples/tabs/main.go b/examples/tabs/main.go index 4f8f774..463c5c4 100644 --- a/examples/tabs/main.go +++ b/examples/tabs/main.go @@ -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) } diff --git a/examples/textarea/main.go b/examples/textarea/main.go index 48ad44d..109059c 100644 --- a/examples/textarea/main.go +++ b/examples/textarea/main.go @@ -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) } } diff --git a/examples/textinput/main.go b/examples/textinput/main.go index b9c259c..7c25344 100644 --- a/examples/textinput/main.go +++ b/examples/textinput/main.go @@ -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) } } diff --git a/examples/textinputs/main.go b/examples/textinputs/main.go index 587b8df..2620bfc 100644 --- a/examples/textinputs/main.go +++ b/examples/textinputs/main.go @@ -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) } diff --git a/examples/timer/main.go b/examples/timer/main.go index bf3a2c9..7ee4f7d 100644 --- a/examples/timer/main.go +++ b/examples/timer/main.go @@ -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) } diff --git a/examples/tui-daemon-combo/main.go b/examples/tui-daemon-combo/main.go index de2d61c..cbe7799 100644 --- a/examples/tui-daemon-combo/main.go +++ b/examples/tui-daemon-combo/main.go @@ -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) } diff --git a/examples/views/main.go b/examples/views/main.go index 2124f73..a06b592 100644 --- a/examples/views/main.go +++ b/examples/views/main.go @@ -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) } } diff --git a/exec_test.go b/exec_test.go index 37de3f5..4416cbc 100644 --- a/exec_test.go +++ b/exec_test.go @@ -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) } diff --git a/options.go b/options.go index 8b4b4d4..59d0685 100644 --- a/options.go +++ b/options.go @@ -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) // } diff --git a/tea.go b/tea.go index 8669893..bf4779f 100644 --- a/tea.go +++ b/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 } diff --git a/tea_test.go b/tea_test.go index 7a3d315..1f6bb53 100644 --- a/tea_test.go +++ b/tea_test.go @@ -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) } } diff --git a/tutorials/basics/README.md b/tutorials/basics/README.md index adec6aa..1b40823 100644 --- a/tutorials/basics/README.md +++ b/tutorials/basics/README.md @@ -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) } diff --git a/tutorials/basics/main.go b/tutorials/basics/main.go index 05d40b4..0c5b573 100644 --- a/tutorials/basics/main.go +++ b/tutorials/basics/main.go @@ -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) } diff --git a/tutorials/commands/README.md b/tutorials/commands/README.md index 2492058..3c43bc7 100644 --- a/tutorials/commands/README.md +++ b/tutorials/commands/README.md @@ -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) } diff --git a/tutorials/commands/main.go b/tutorials/commands/main.go index ef63479..8ed68b7 100644 --- a/tutorials/commands/main.go +++ b/tutorials/commands/main.go @@ -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) }