diff --git a/examples/autocomplete/main.go b/examples/autocomplete/main.go index 161efa7801..bd6fc9356f 100644 --- a/examples/autocomplete/main.go +++ b/examples/autocomplete/main.go @@ -16,7 +16,7 @@ import ( func main() { p := tea.NewProgram(initialModel()) - if _, err := p.Run(); err != nil { + if err := p.Run(); err != nil { log.Fatal(err) } } @@ -101,11 +101,11 @@ func initialModel() model { return model{textInput: ti, help: h, keymap: km} } -func (m model) Init() (tea.Model, tea.Cmd) { +func (m model) Init() (model, tea.Cmd) { return m, tea.Batch(getRepos, textinput.Blink) } -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyPressMsg: switch msg.String() { diff --git a/examples/capability/main.go b/examples/capability/main.go index 56476293e6..321f78a669 100644 --- a/examples/capability/main.go +++ b/examples/capability/main.go @@ -14,17 +14,15 @@ type model struct { width int } -var _ tea.Model = model{} - // Init implements tea.Model. -func (m model) Init() (tea.Model, tea.Cmd) { +func (m model) Init() (model, tea.Cmd) { m.input = textinput.New() m.input.Placeholder = "Enter capability name to request" return m, m.input.Focus() } // Update implements tea.Model. -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { var cmd tea.Cmd switch msg := msg.(type) { case tea.WindowSizeMsg: @@ -59,7 +57,7 @@ func (m model) View() fmt.Stringer { } func main() { - if _, err := tea.NewProgram(model{}).Run(); err != nil { + if err := tea.NewProgram(model{}).Run(); err != nil { log.Fatal(err) } } diff --git a/examples/cellbuffer/main.go b/examples/cellbuffer/main.go index d1ac812841..5c2514950a 100644 --- a/examples/cellbuffer/main.go +++ b/examples/cellbuffer/main.go @@ -143,7 +143,11 @@ type model struct { } func (m model) Init() (model, tea.Cmd) { - return m, animate() + return m, tea.Batch( + animate(), + tea.EnableMouseCellMotion, + tea.EnterAltScreen, + ) } func (m model) Update(msg tea.Msg) (model, tea.Cmd) { @@ -193,7 +197,7 @@ func main() { spring: harmonica.NewSpring(harmonica.FPS(fps), frequency, damping), } - p := tea.NewProgram(m, tea.WithAltScreen[model](), tea.WithMouseCellMotion[model]()) + p := tea.NewProgram(m) if err := p.Run(); err != nil { fmt.Println("Uh oh:", err) os.Exit(1) diff --git a/examples/chat/main.go b/examples/chat/main.go index 6377c46421..83c432a448 100644 --- a/examples/chat/main.go +++ b/examples/chat/main.go @@ -19,7 +19,7 @@ const gap = "\n\n" func main() { p := tea.NewProgram(initialModel()) - if _, err := p.Run(); err != nil { + if err := p.Run(); err != nil { fmt.Fprintf(os.Stderr, "Oof: %v\n", err) } } @@ -63,11 +63,11 @@ Type a message and press Enter to send.`) } } -func (m model) Init() (tea.Model, tea.Cmd) { +func (m model) Init() (model, tea.Cmd) { return m, textarea.Blink } -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { switch msg := msg.(type) { case tea.WindowSizeMsg: m.viewport.SetWidth(msg.Width) diff --git a/examples/colorprofile/main.go b/examples/colorprofile/main.go index 68a6ac507d..08af1e2989 100644 --- a/examples/colorprofile/main.go +++ b/examples/colorprofile/main.go @@ -15,10 +15,8 @@ var myFancyColor color.Color type model struct{} -var _ tea.Model = model{} - // Init implements tea.Model. -func (m model) Init() (tea.Model, tea.Cmd) { +func (m model) Init() (model, tea.Cmd) { return m, tea.Batch( tea.RequestCapability("RGB"), tea.RequestCapability("Tc"), @@ -26,7 +24,7 @@ func (m model) Init() (tea.Model, tea.Cmd) { } // Update implements tea.Model. -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyMsg: return m, tea.Quit @@ -47,8 +45,9 @@ func (m model) View() fmt.Stringer { func main() { myFancyColor, _ = colorful.Hex("#6b50ff") - p := tea.NewProgram(model{}, tea.WithColorProfile(colorprofile.TrueColor)) - if _, err := p.Run(); err != nil { + p := tea.NewProgram(model{}) + p.Profile = colorprofile.TrueColor + if err := p.Run(); err != nil { log.Fatal(err) } } diff --git a/examples/composable-views/main.go b/examples/composable-views/main.go index 443744816e..6b82bd7cc8 100644 --- a/examples/composable-views/main.go +++ b/examples/composable-views/main.go @@ -73,14 +73,14 @@ func newModel(timeout time.Duration) mainModel { return m } -func (m mainModel) Init() (tea.Model, tea.Cmd) { +func (m mainModel) Init() (mainModel, tea.Cmd) { // start the timer and spinner on program start timer, cmd := m.timer.Init() m.timer = timer return m, tea.Batch(cmd, m.spinner.Tick) } -func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m mainModel) Update(msg tea.Msg) (mainModel, tea.Cmd) { var cmd tea.Cmd var cmds []tea.Cmd switch msg := msg.(type) { @@ -160,7 +160,7 @@ func (m *mainModel) resetSpinner() { func main() { p := tea.NewProgram(newModel(defaultTime)) - if _, err := p.Run(); 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 5d75955a3a..fc77080b01 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.Run(); err != nil { + if err := p.Run(); err != nil { log.Fatal(err) } } @@ -124,11 +124,11 @@ func initialModel() model { } } -func (m model) Init() (tea.Model, tea.Cmd) { +func (m model) Init() (model, tea.Cmd) { return m, textinput.Blink } -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { var cmds []tea.Cmd = make([]tea.Cmd, len(m.inputs)) switch msg := msg.(type) { diff --git a/examples/cursor-style/main.go b/examples/cursor-style/main.go index e1992702f7..f4e08cf0ac 100644 --- a/examples/cursor-style/main.go +++ b/examples/cursor-style/main.go @@ -8,35 +8,35 @@ import ( ) type model struct { - style tea.CursorStyle + shape tea.CursorShape blink bool } -func (m model) Init() (tea.Model, tea.Cmd) { +func (m model) Init() (model, tea.Cmd) { m.blink = true return m, nil } -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyPressMsg: switch msg.String() { case "ctrl+q", "q": return m, tea.Quit case "h", "left": - if m.style == tea.CursorBlock && m.blink { + if m.shape == tea.CursorBlock && m.blink { break } if m.blink { - m.style-- + m.shape-- } m.blink = !m.blink case "l", "right": - if m.style == tea.CursorBar && !m.blink { + if m.shape == tea.CursorBar && !m.blink { break } if !m.blink { - m.style++ + m.shape++ } m.blink = !m.blink } @@ -49,7 +49,7 @@ func (m model) View() fmt.Stringer { "\n\n" + " <- This is the cursor (a " + m.describeCursor() + ")") f.Cursor = tea.NewCursor(0, 2) - f.Cursor.Style = m.style + f.Cursor.Shape = m.shape f.Cursor.Blink = m.blink return f } @@ -63,7 +63,7 @@ func (m model) describeCursor() string { adj = "steady" } - switch m.style { + switch m.shape { case tea.CursorBlock: noun = "block" case tea.CursorUnderline: @@ -77,7 +77,7 @@ func (m model) describeCursor() string { func main() { p := tea.NewProgram(model{}) - if _, err := p.Run(); err != nil { + if err := p.Run(); err != nil { fmt.Fprintf(os.Stderr, "Error: %v", err) os.Exit(1) } diff --git a/examples/debounce/main.go b/examples/debounce/main.go index 2e1187be1c..bf2bb592ec 100644 --- a/examples/debounce/main.go +++ b/examples/debounce/main.go @@ -26,11 +26,11 @@ type model struct { tag int } -func (m model) Init() (tea.Model, tea.Cmd) { +func (m model) Init() (model, tea.Cmd) { return m, nil } -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyPressMsg: // Increment the tag on the model... @@ -59,7 +59,7 @@ func (m model) View() fmt.Stringer { } func main() { - if _, err := tea.NewProgram(model{}).Run(); err != nil { + if err := tea.NewProgram(model{}).Run(); err != nil { fmt.Println("uh oh:", err) os.Exit(1) } diff --git a/examples/doom-fire/main.go b/examples/doom-fire/main.go index 7ec28ee3f5..89ed2af766 100644 --- a/examples/doom-fire/main.go +++ b/examples/doom-fire/main.go @@ -23,11 +23,14 @@ type model struct { startTime time.Time } -func (m model) Init() (tea.Model, tea.Cmd) { - return m, tick +func (m model) Init() (model, tea.Cmd) { + return m, tea.Batch( + tick, + tea.EnterAltScreen, + ) } -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyPressMsg: if msg.String() == "q" || msg.String() == "ctrl+c" { @@ -128,8 +131,8 @@ func initialModel() model { } func main() { - p := tea.NewProgram(initialModel(), tea.WithAltScreen()) - if _, err := p.Run(); err != nil { + p := tea.NewProgram(initialModel()) + if err := p.Run(); err != nil { fmt.Printf("Error running program: %v", err) } } diff --git a/examples/exec/main.go b/examples/exec/main.go index 026f4a880e..e133ab44ce 100644 --- a/examples/exec/main.go +++ b/examples/exec/main.go @@ -26,11 +26,11 @@ type model struct { err error } -func (m model) Init() (tea.Model, tea.Cmd) { +func (m model) Init() (model, tea.Cmd) { return m, nil } -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyPressMsg: switch msg.String() { @@ -64,7 +64,7 @@ func (m model) View() fmt.Stringer { func main() { m := model{} - if _, err := tea.NewProgram(m).Run(); err != nil { + if err := tea.NewProgram(m).Run(); err != nil { fmt.Println("Error running program:", err) os.Exit(1) } diff --git a/examples/file-picker/main.go b/examples/file-picker/main.go index a1421a99a7..87d18edf2e 100644 --- a/examples/file-picker/main.go +++ b/examples/file-picker/main.go @@ -26,13 +26,16 @@ func clearErrorAfter(t time.Duration) tea.Cmd { }) } -func (m model) Init() (tea.Model, tea.Cmd) { +func (m model) Init() (model, tea.Cmd) { fp, cmd := m.filepicker.Init() m.filepicker = fp - return m, cmd + return m, tea.Batch( + tea.EnterAltScreen, + cmd, + ) } -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyPressMsg: switch msg.String() { @@ -90,7 +93,10 @@ func main() { m := model{ filepicker: fp, } - tm, _ := tea.NewProgram(&m, tea.WithAltScreen()).Run() - mm := tm.(model) - fmt.Println("\n You selected: " + m.filepicker.Styles.Selected.Render(mm.selectedFile) + "\n") + tm := tea.NewProgram(&m) + if err := tm.Run(); err != nil { + fmt.Println("Error running program:", err) + os.Exit(1) + } + fmt.Println("\n You selected: " + m.filepicker.Styles.Selected.Render(tm.Model.selectedFile) + "\n") } diff --git a/examples/focus-blur/main.go b/examples/focus-blur/main.go index 0690def1dd..28a1b98e09 100644 --- a/examples/focus-blur/main.go +++ b/examples/focus-blur/main.go @@ -14,8 +14,8 @@ func main() { // assume we start focused... focused: true, reporting: true, - }, tea.WithReportFocus()) - if _, err := p.Run(); err != nil { + }) + if err := p.Run(); err != nil { log.Fatal(err) } } @@ -25,11 +25,11 @@ type model struct { reporting bool } -func (m model) Init() (tea.Model, tea.Cmd) { - return m, nil +func (m model) Init() (model, tea.Cmd) { + return m, tea.EnabledReportFocus } -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { switch msg := msg.(type) { case tea.FocusMsg: m.focused = true diff --git a/examples/fullscreen/main.go b/examples/fullscreen/main.go index 4dff5fe23d..57bffc3646 100644 --- a/examples/fullscreen/main.go +++ b/examples/fullscreen/main.go @@ -16,17 +16,20 @@ type model int type tickMsg time.Time func main() { - p := tea.NewProgram(model(5), tea.WithAltScreen()) - if _, err := p.Run(); err != nil { + p := tea.NewProgram(model(5)) + if err := p.Run(); err != nil { log.Fatal(err) } } -func (m model) Init() (tea.Model, tea.Cmd) { - return m, tick() +func (m model) Init() (model, tea.Cmd) { + return m, tea.Batch( + tea.EnterAltScreen, + tick(), + ) } -func (m model) Update(message tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(message tea.Msg) (model, tea.Cmd) { switch msg := message.(type) { case tea.KeyPressMsg: switch msg.String() { diff --git a/examples/glamour/main.go b/examples/glamour/main.go index 1873964a25..81c1603112 100644 --- a/examples/glamour/main.go +++ b/examples/glamour/main.go @@ -101,11 +101,11 @@ func newExample() (*example, error) { }, nil } -func (e example) Init() (tea.Model, tea.Cmd) { +func (e example) Init() (example, tea.Cmd) { return e, nil } -func (e example) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (e example) Update(msg tea.Msg) (example, tea.Cmd) { switch msg := msg.(type) { case tea.KeyPressMsg: switch msg.String() { @@ -136,7 +136,7 @@ func main() { os.Exit(1) } - if _, err := tea.NewProgram(model).Run(); 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 4e3a17795c..e99cde2a87 100644 --- a/examples/help/main.go +++ b/examples/help/main.go @@ -80,11 +80,11 @@ func newModel() model { } } -func (m model) Init() (tea.Model, tea.Cmd) { +func (m model) Init() (model, tea.Cmd) { return m, nil } -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { switch msg := msg.(type) { case tea.WindowSizeMsg: // If we set a width on the help menu it can gracefully truncate @@ -140,7 +140,7 @@ func main() { defer f.Close() // nolint:errcheck } - if _, err := tea.NewProgram(newModel()).Run(); 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 b5a2137bad..6ebc627224 100644 --- a/examples/http/main.go +++ b/examples/http/main.go @@ -26,16 +26,16 @@ func (e errMsg) Error() string { return e.error.Error() } func main() { p := tea.NewProgram(model{}) - if _, err := p.Run(); err != nil { + if err := p.Run(); err != nil { log.Fatal(err) } } -func (m model) Init() (tea.Model, tea.Cmd) { +func (m model) Init() (model, tea.Cmd) { return m, checkServer } -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyPressMsg: switch msg.String() { diff --git a/examples/list-default/main.go b/examples/list-default/main.go index 487c0bed19..99c356d4e0 100644 --- a/examples/list-default/main.go +++ b/examples/list-default/main.go @@ -23,11 +23,11 @@ type model struct { list list.Model } -func (m model) Init() (tea.Model, tea.Cmd) { - return m, nil +func (m model) Init() (model, tea.Cmd) { + return m, tea.EnterAltScreen } -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyPressMsg: if msg.String() == "ctrl+c" { @@ -77,9 +77,9 @@ func main() { m := model{list: list.New(items, list.NewDefaultDelegate(), 0, 0)} m.list.Title = "My Fave Things" - p := tea.NewProgram(m, tea.WithAltScreen()) + p := tea.NewProgram(m) - if _, err := p.Run(); err != nil { + if err := p.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 e7da9ab43c..c3d7701f2e 100644 --- a/examples/list-simple/main.go +++ b/examples/list-simple/main.go @@ -70,7 +70,7 @@ type model struct { quitting bool } -func (m model) Init() (tea.Model, tea.Cmd) { +func (m model) Init() (model, tea.Cmd) { items := []list.Item{ item("Ramen"), item("Tomato Soup"), @@ -95,7 +95,7 @@ func (m model) Init() (tea.Model, tea.Cmd) { return m, tea.RequestBackgroundColor } -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { switch msg := msg.(type) { case tea.BackgroundColorMsg: // Wait until we know the background color to initialize our styles. @@ -147,7 +147,7 @@ func (m model) View() fmt.Stringer { } func main() { - if _, err := tea.NewProgram(model{}).Run(); err != nil { + if err := tea.NewProgram(model{}).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 857fb3b41d..9588afefc3 100644 --- a/examples/mouse/main.go +++ b/examples/mouse/main.go @@ -11,19 +11,19 @@ import ( ) func main() { - p := tea.NewProgram(model{}, tea.WithMouseAllMotion()) - if _, err := p.Run(); err != nil { + p := tea.NewProgram(model{}) + if err := p.Run(); err != nil { log.Fatal(err) } } type model struct{} -func (m model) Init() (tea.Model, tea.Cmd) { - return m, nil +func (m model) Init() (model, tea.Cmd) { + return m, tea.EnableMouseAllMotion } -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyPressMsg: if s := msg.String(); s == "ctrl+c" || s == "q" || s == "esc" { diff --git a/examples/package-manager/main.go b/examples/package-manager/main.go index 7f39b1b5a2..eeb1857db7 100644 --- a/examples/package-manager/main.go +++ b/examples/package-manager/main.go @@ -44,11 +44,11 @@ func newModel() model { } } -func (m model) Init() (tea.Model, tea.Cmd) { +func (m model) Init() (model, tea.Cmd) { return m, tea.Batch(downloadAndInstall(m.packages[m.index]), m.spinner.Tick) } -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { switch msg := msg.(type) { case tea.WindowSizeMsg: m.width, m.height = msg.Width, msg.Height @@ -133,7 +133,7 @@ func max(a, b int) int { } func main() { - if _, err := tea.NewProgram(newModel()).Run(); 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 11114f285c..e0146fc144 100644 --- a/examples/pager/main.go +++ b/examples/pager/main.go @@ -33,11 +33,14 @@ type model struct { viewport viewport.Model } -func (m model) Init() (tea.Model, tea.Cmd) { - return m, nil +func (m model) Init() (model, tea.Cmd) { + return m, tea.Batch( + tea.EnterAltScreen, + tea.EnableMouseCellMotion, + ) } -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { var ( cmd tea.Cmd cmds []tea.Cmd @@ -112,11 +115,9 @@ func main() { p := tea.NewProgram( model{content: string(content)}, - tea.WithAltScreen(), // use the full size of the terminal in its "alternate screen buffer" - tea.WithMouseCellMotion(), // turn on mouse support so we can track the mouse wheel ) - if _, err := p.Run(); 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 e466e566e2..4da1721c8d 100644 --- a/examples/paginator/main.go +++ b/examples/paginator/main.go @@ -33,7 +33,7 @@ type model struct { ready bool } -func (m model) Init() (tea.Model, tea.Cmd) { +func (m model) Init() (model, tea.Cmd) { var items []string for i := 1; i < 101; i++ { text := fmt.Sprintf("Item %d", i) @@ -51,7 +51,7 @@ func (m model) Init() (tea.Model, tea.Cmd) { return m, tea.RequestBackgroundColor } -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { var cmd tea.Cmd switch msg := msg.(type) { case tea.BackgroundColorMsg: @@ -88,7 +88,7 @@ func (m model) View() fmt.Stringer { func main() { p := tea.NewProgram(model{}) - if _, err := p.Run(); err != nil { + if err := p.Run(); err != nil { log.Fatal(err) } } diff --git a/examples/prevent-quit/main.go b/examples/prevent-quit/main.go index 91674acf92..1cf2a77642 100644 --- a/examples/prevent-quit/main.go +++ b/examples/prevent-quit/main.go @@ -20,19 +20,19 @@ var ( ) func main() { - p := tea.NewProgram(initialModel(), tea.WithFilter(filter)) + p := tea.NewProgram(initialModel()) + p.Filter = filter - if _, err := p.Run(); err != nil { + if err := p.Run(); err != nil { log.Fatal(err) } } -func filter(teaModel tea.Model, msg tea.Msg) tea.Msg { +func filter(m model, msg tea.Msg) tea.Msg { if _, ok := msg.(tea.QuitMsg); !ok { return msg } - m := teaModel.(model) if m.hasChanges { return nil } @@ -75,11 +75,11 @@ func initialModel() model { } } -func (m model) Init() (tea.Model, tea.Cmd) { +func (m model) Init() (model, tea.Cmd) { return m, textarea.Blink } -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { if m.quitting { return m.updatePromptView(msg) } @@ -87,7 +87,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m.updateTextView(msg) } -func (m model) updateTextView(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) updateTextView(msg tea.Msg) (model, tea.Cmd) { var cmds []tea.Cmd var cmd tea.Cmd @@ -117,7 +117,7 @@ func (m model) updateTextView(msg tea.Msg) (tea.Model, tea.Cmd) { return m, tea.Batch(cmds...) } -func (m model) updatePromptView(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) updatePromptView(msg tea.Msg) (model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyPressMsg: // For simplicity's sake, we'll treat any key besides "y" as "no" diff --git a/examples/print-key/main.go b/examples/print-key/main.go index ab726bee38..94f1e75c44 100644 --- a/examples/print-key/main.go +++ b/examples/print-key/main.go @@ -9,11 +9,14 @@ import ( type model struct{} -func (m model) Init() (tea.Model, tea.Cmd) { - return m, nil +func (m model) Init() (model, tea.Cmd) { + return m, tea.RequestKeyboardEnhancements( + tea.WithKeyReleases, + tea.WithUniformKeyLayout, + ) } -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyboardEnhancementsMsg: return m, tea.Printf("Keyboard enhancements: Disambiguation: %v, ReleaseKeys: %v, Uniform keys: %v\n", @@ -45,8 +48,8 @@ func (m model) View() fmt.Stringer { } func main() { - p := tea.NewProgram(model{}, tea.WithKeyboardEnhancements(tea.WithKeyReleases, tea.WithUniformKeyLayout)) - if _, err := p.Run(); err != nil { + p := tea.NewProgram(model{}) + if err := p.Run(); err != nil { log.Printf("Error running program: %v", err) } } diff --git a/examples/progress-animated/main.go b/examples/progress-animated/main.go index efdc52c9ff..049db890b8 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).Run(); err != nil { + if err := tea.NewProgram(m).Run(); err != nil { fmt.Println("Oh no!", err) os.Exit(1) } @@ -42,11 +42,11 @@ type model struct { progress progress.Model } -func (m model) Init() (tea.Model, tea.Cmd) { +func (m model) Init() (model, tea.Cmd) { return m, tickCmd() } -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyPressMsg: return m, tea.Quit diff --git a/examples/progress-download/main.go b/examples/progress-download/main.go index c61897eb0b..3831228981 100644 --- a/examples/progress-download/main.go +++ b/examples/progress-download/main.go @@ -13,7 +13,7 @@ import ( tea "github.com/charmbracelet/bubbletea/v2" ) -var p *tea.Program +var p *tea.Program[model] type progressWriter struct { total int @@ -100,7 +100,7 @@ func main() { // Start the download go pw.Start() - if _, err := p.Run(); err != nil { + if err := p.Run(); err != nil { fmt.Println("error running program:", err) os.Exit(1) } diff --git a/examples/progress-download/tui.go b/examples/progress-download/tui.go index 6e6139f72c..fe0f9a87b6 100644 --- a/examples/progress-download/tui.go +++ b/examples/progress-download/tui.go @@ -33,11 +33,11 @@ type model struct { err error } -func (m model) Init() (tea.Model, tea.Cmd) { +func (m model) Init() (model, tea.Cmd) { return m, nil } -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyPressMsg: return m, tea.Quit diff --git a/examples/progress-static/main.go b/examples/progress-static/main.go index 58d78bf39c..ce9d16800e 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}).Run(); err != nil { + if err := tea.NewProgram(model{progress: prog}).Run(); err != nil { fmt.Println("Oh no!", err) os.Exit(1) } @@ -50,11 +50,11 @@ type model struct { progress progress.Model } -func (m model) Init() (tea.Model, tea.Cmd) { +func (m model) Init() (model, tea.Cmd) { return m, tickCmd() } -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyPressMsg: return m, tea.Quit diff --git a/examples/query-term/main.go b/examples/query-term/main.go index e377f31886..340688d528 100644 --- a/examples/query-term/main.go +++ b/examples/query-term/main.go @@ -28,11 +28,11 @@ type model struct { err error } -func (m model) Init() (tea.Model, tea.Cmd) { +func (m model) Init() (model, tea.Cmd) { return m, textinput.Blink } -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { var cmds []tea.Cmd switch msg := msg.(type) { @@ -91,7 +91,7 @@ func (m model) View() fmt.Stringer { func main() { p := tea.NewProgram(newModel()) - if _, err := p.Run(); err != nil { + if err := p.Run(); err != nil { log.Fatal(err) } } diff --git a/examples/realtime/main.go b/examples/realtime/main.go index 98a601701e..cc035c0afc 100644 --- a/examples/realtime/main.go +++ b/examples/realtime/main.go @@ -44,7 +44,7 @@ type model struct { quitting bool } -func (m model) Init() (tea.Model, tea.Cmd) { +func (m model) Init() (model, tea.Cmd) { return m, tea.Batch( m.spinner.Tick, listenForActivity(m.sub), // generate activity @@ -52,7 +52,7 @@ func (m model) Init() (tea.Model, tea.Cmd) { ) } -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { switch msg.(type) { case tea.KeyPressMsg: m.quitting = true @@ -83,7 +83,7 @@ func main() { spinner: spinner.New(), }) - if _, err := p.Run(); err != nil { + 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 8efc963e8d..bcc55e9893 100644 --- a/examples/result/main.go +++ b/examples/result/main.go @@ -18,11 +18,11 @@ type model struct { choice string } -func (m model) Init() (tea.Model, tea.Cmd) { +func (m model) Init() (model, tea.Cmd) { return m, nil } -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyPressMsg: switch msg.String() { @@ -73,14 +73,14 @@ func main() { p := tea.NewProgram(model{}) // Run returns the model as a tea.Model. - m, err := p.Run() + err := p.Run() if err != nil { fmt.Println("Oh no:", err) os.Exit(1) } // Assert the final tea.Model to our local model and print the choice. - if m, ok := m.(model); ok && m.choice != "" { + if m := p.Model; m.choice != "" { fmt.Printf("\n---\nYou chose %s!\n", m.choice) } } diff --git a/examples/send-msg/main.go b/examples/send-msg/main.go index 37af6e64ef..f7c8c15012 100644 --- a/examples/send-msg/main.go +++ b/examples/send-msg/main.go @@ -52,11 +52,11 @@ func newModel() model { } } -func (m model) Init() (tea.Model, tea.Cmd) { +func (m model) Init() (model, tea.Cmd) { return m, m.spinner.Tick } -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyPressMsg: m.quitting = true @@ -115,7 +115,7 @@ func main() { } }() - if _, err := p.Run(); 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 0dc6392899..0791797f28 100644 --- a/examples/sequence/main.go +++ b/examples/sequence/main.go @@ -11,7 +11,7 @@ import ( type model struct{} -func (m model) Init() (tea.Model, tea.Cmd) { +func (m model) Init() (model, tea.Cmd) { // A tea.Sequence is a command that runs a series of commands in // order. Contrast this with tea.Batch, which runs a series of commands // concurrently, with no order guarantees. @@ -28,7 +28,7 @@ func (m model) Init() (tea.Model, tea.Cmd) { ) } -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { switch msg.(type) { case tea.KeyPressMsg: return m, tea.Quit @@ -41,7 +41,7 @@ func (m model) View() fmt.Stringer { } func main() { - if _, err := tea.NewProgram(model{}).Run(); err != nil { + if err := tea.NewProgram(model{}).Run(); err != nil { fmt.Println("Uh oh:", err) os.Exit(1) } diff --git a/examples/set-terminal-color/main.go b/examples/set-terminal-color/main.go index 8293ce380a..9e44433390 100644 --- a/examples/set-terminal-color/main.go +++ b/examples/set-terminal-color/main.go @@ -47,11 +47,11 @@ type model struct { err error } -func (m model) Init() (tea.Model, tea.Cmd) { +func (m model) Init() (model, tea.Cmd) { return m, textinput.Blink } -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyPressMsg: switch msg.String() { @@ -178,7 +178,7 @@ func main() { ti: ti, }) - _, err := p.Run() + err := p.Run() if err != nil { log.Fatalf("Error running program: %v", err) } diff --git a/examples/set-window-title/main.go b/examples/set-window-title/main.go index b8655af919..7cb7d1d75f 100644 --- a/examples/set-window-title/main.go +++ b/examples/set-window-title/main.go @@ -14,11 +14,11 @@ const windowTitle = "Hello, Bubble Tea" type model struct{} -func (m model) Init() (tea.Model, tea.Cmd) { +func (m model) Init() (model, tea.Cmd) { return m, tea.SetWindowTitle(windowTitle) } -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { switch msg.(type) { case tea.KeyPressMsg: return m, tea.Quit @@ -33,7 +33,7 @@ func (m model) View() fmt.Stringer { } func main() { - if _, err := tea.NewProgram(model{}).Run(); err != nil { + if err := tea.NewProgram(model{}).Run(); err != nil { fmt.Println("Uh oh:", err) os.Exit(1) } diff --git a/examples/space/main.go b/examples/space/main.go index b5a1f3dbc5..b0501f73b5 100644 --- a/examples/space/main.go +++ b/examples/space/main.go @@ -26,7 +26,7 @@ type model struct { height int } -func (m model) Init() (tea.Model, tea.Cmd) { +func (m model) Init() (model, tea.Cmd) { return m, tea.Batch( tea.EnterAltScreen, tickCmd(), @@ -41,7 +41,7 @@ func tickCmd() tea.Cmd { type tickMsg struct{} -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyPressMsg: switch msg.String() { @@ -117,9 +117,8 @@ func (m model) View() fmt.Stringer { } func main() { - p := tea.NewProgram(model{}, tea.WithAltScreen()) - - _, err := p.Run() + p := tea.NewProgram(model{}) + err := p.Run() if err != nil { fmt.Printf("Error running program: %v", err) os.Exit(1) diff --git a/examples/spinner/main.go b/examples/spinner/main.go index 5ee5ddba8c..f21d6aee87 100644 --- a/examples/spinner/main.go +++ b/examples/spinner/main.go @@ -27,11 +27,11 @@ func initialModel() model { return model{spinner: s} } -func (m model) Init() (tea.Model, tea.Cmd) { +func (m model) Init() (model, tea.Cmd) { return m, m.spinner.Tick } -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyPressMsg: switch msg.String() { @@ -66,7 +66,7 @@ func (m model) View() fmt.Stringer { func main() { p := tea.NewProgram(initialModel()) - if _, err := p.Run(); 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 83e7dbd9d5..9161b29502 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).Run(); err != nil { + if err := tea.NewProgram(m).Run(); err != nil { fmt.Println("could not run program:", err) os.Exit(1) } @@ -43,11 +43,11 @@ type model struct { spinner spinner.Model } -func (m model) Init() (tea.Model, tea.Cmd) { +func (m model) Init() (model, tea.Cmd) { return m, m.spinner.Tick } -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyPressMsg: switch msg.String() { diff --git a/examples/splash/main.go b/examples/splash/main.go index 2a5f586e7e..5b06af4d7d 100644 --- a/examples/splash/main.go +++ b/examples/splash/main.go @@ -37,12 +37,15 @@ type model struct { rate int64 } -func (m model) Init() (tea.Model, tea.Cmd) { +func (m model) Init() (model, tea.Cmd) { m.rate = 90 - return m, tick + return m, tea.Batch( + tea.EnterAltScreen, + tick, + ) } -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyPressMsg: return m, tea.Quit @@ -170,12 +173,8 @@ func abs(i int) int { } func main() { - p := tea.NewProgram( - model{}, - tea.WithAltScreen(), - ) - - if _, err := p.Run(); err != nil { + p := tea.NewProgram(model{}) + if err := p.Run(); err != nil { fmt.Printf("Error running program: %v", err) } } diff --git a/examples/split-editors/main.go b/examples/split-editors/main.go index 47799906fd..c831f4dd0f 100644 --- a/examples/split-editors/main.go +++ b/examples/split-editors/main.go @@ -51,7 +51,7 @@ func newTextarea() textarea.Model { t.Prompt = "" t.Placeholder = "Type something" t.ShowLineNumbers = true - t.Cursor.Style = cursorStyle + t.VirtualCursor.Style = cursorStyle t.Styles.Focused.Placeholder = focusedPlaceholderStyle t.Styles.Blurred.Placeholder = placeholderStyle t.Styles.Focused.CursorLine = cursorLineStyle @@ -111,11 +111,14 @@ func newModel() model { return m } -func (m model) Init() (tea.Model, tea.Cmd) { - return m, textarea.Blink +func (m model) Init() (model, tea.Cmd) { + return m, tea.Batch( + tea.EnterAltScreen, + textarea.Blink, + ) } -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { var cmds []tea.Cmd switch msg := msg.(type) { @@ -198,7 +201,7 @@ func (m model) View() fmt.Stringer { } func main() { - if _, err := tea.NewProgram(newModel(), tea.WithAltScreen()).Run(); err != nil { + if err := tea.NewProgram(newModel()).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 afa63ff864..b7303608b1 100644 --- a/examples/stopwatch/main.go +++ b/examples/stopwatch/main.go @@ -25,7 +25,7 @@ type keymap struct { quit key.Binding } -func (m model) Init() (tea.Model, tea.Cmd) { +func (m model) Init() (model, tea.Cmd) { sw, cmd := m.stopwatch.Init() m.stopwatch = sw return m, cmd @@ -52,7 +52,7 @@ func (m model) helpView() string { }) } -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyPressMsg: switch { @@ -98,7 +98,7 @@ func main() { m.keymap.start.SetEnabled(false) - if _, err := tea.NewProgram(m).Run(); 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/suspend/main.go b/examples/suspend/main.go index 7b61a389eb..e49397efba 100644 --- a/examples/suspend/main.go +++ b/examples/suspend/main.go @@ -13,11 +13,11 @@ type model struct { suspending bool } -func (m model) Init() (tea.Model, tea.Cmd) { +func (m model) Init() (model, tea.Cmd) { return m, nil } -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { switch msg := msg.(type) { case tea.ResumeMsg: m.suspending = false @@ -47,7 +47,7 @@ func (m model) View() fmt.Stringer { } func main() { - if _, err := tea.NewProgram(model{}).Run(); err != nil { + if err := tea.NewProgram(model{}).Run(); err != nil { fmt.Println("Error running program:", err) if errors.Is(err, tea.ErrInterrupted) { os.Exit(130) diff --git a/examples/table-resize/main.go b/examples/table-resize/main.go index bca025166a..248022b93c 100644 --- a/examples/table-resize/main.go +++ b/examples/table-resize/main.go @@ -28,9 +28,9 @@ type model struct { table *table.Table } -func (m model) Init() (tea.Model, tea.Cmd) { return m, nil } +func (m model) Init() (model, tea.Cmd) { return m, tea.EnterAltScreen } -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { var cmd tea.Cmd switch msg := msg.(type) { case tea.WindowSizeMsg: @@ -154,7 +154,7 @@ func main() { }). Border(lipgloss.ThickBorder()) - if _, err := tea.NewProgram(model{t}, tea.WithAltScreen()).Run(); err != nil { + if err := tea.NewProgram(model{t}).Run(); err != nil { fmt.Println("Error running program:", err) os.Exit(1) } diff --git a/examples/table/main.go b/examples/table/main.go index 4e3c43b8a1..5366040bf5 100644 --- a/examples/table/main.go +++ b/examples/table/main.go @@ -17,9 +17,9 @@ type model struct { table table.Model } -func (m model) Init() (tea.Model, tea.Cmd) { return m, nil } +func (m model) Init() (model, tea.Cmd) { return m, nil } -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { var cmd tea.Cmd switch msg := msg.(type) { case tea.KeyPressMsg: @@ -177,7 +177,7 @@ func main() { t.SetStyles(s) m := model{t} - if _, err := tea.NewProgram(m).Run(); 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 9cbf8e1472..22c0a3899b 100644 --- a/examples/tabs/main.go +++ b/examples/tabs/main.go @@ -49,11 +49,11 @@ type model struct { activeTab int } -func (m model) Init() (tea.Model, tea.Cmd) { +func (m model) Init() (model, tea.Cmd) { return m, tea.RequestBackgroundColor } -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { switch msg := msg.(type) { case tea.BackgroundColorMsg: m.styles = newStyles(msg.IsDark()) @@ -126,7 +126,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).Run(); err != nil { + if err := tea.NewProgram(m).Run(); err != nil { fmt.Println("Error running program:", err) os.Exit(1) } diff --git a/examples/textinput/main.go b/examples/textinput/main.go index fb004a5ad6..cfb36b5ff8 100644 --- a/examples/textinput/main.go +++ b/examples/textinput/main.go @@ -13,7 +13,7 @@ import ( func main() { p := tea.NewProgram(initialModel()) - if _, err := p.Run(); err != nil { + if err := p.Run(); err != nil { log.Fatal(err) } } @@ -40,11 +40,11 @@ func initialModel() model { } } -func (m model) Init() (tea.Model, tea.Cmd) { +func (m model) Init() (model, tea.Cmd) { return m, textinput.Blink } -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { var cmd tea.Cmd switch msg := msg.(type) { diff --git a/examples/textinputs/main.go b/examples/textinputs/main.go index 6f1c33d1be..a7116d9ccd 100644 --- a/examples/textinputs/main.go +++ b/examples/textinputs/main.go @@ -64,11 +64,11 @@ func initialModel() model { return m } -func (m model) Init() (tea.Model, tea.Cmd) { +func (m model) Init() (model, tea.Cmd) { return m, textinput.Blink } -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyPressMsg: switch msg.String() { @@ -171,7 +171,7 @@ func (m model) View() fmt.Stringer { } func main() { - if _, err := tea.NewProgram(initialModel()).Run(); 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 9a1147176a..0edd60a0de 100644 --- a/examples/timer/main.go +++ b/examples/timer/main.go @@ -27,13 +27,13 @@ type keymap struct { quit key.Binding } -func (m model) Init() (tea.Model, tea.Cmd) { +func (m model) Init() (model, tea.Cmd) { timer, cmd := m.timer.Init() m.timer = timer return m, cmd } -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { switch msg := msg.(type) { case timer.TickMsg: var cmd tea.Cmd @@ -117,7 +117,7 @@ func main() { } m.keymap.start.SetEnabled(false) - if _, err := tea.NewProgram(m).Run(); 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/window-size/main.go b/examples/window-size/main.go index c33ea55487..758c2bd779 100644 --- a/examples/window-size/main.go +++ b/examples/window-size/main.go @@ -11,18 +11,18 @@ import ( func main() { p := tea.NewProgram(model{}) - if _, err := p.Run(); err != nil { + if err := p.Run(); err != nil { log.Fatal(err) } } type model struct{} -func (m model) Init() (tea.Model, tea.Cmd) { +func (m model) Init() (model, tea.Cmd) { return m, nil } -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m model) Update(msg tea.Msg) (model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyPressMsg: if s := msg.String(); s == "ctrl+c" || s == "q" || s == "esc" {