Skip to content

Commit

Permalink
Fix simple WIP; debugging of simple example broken
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Miller committed Feb 20, 2024
1 parent 080ccaf commit 9b1d03c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
5 changes: 3 additions & 2 deletions examples/deeper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,14 @@ func main() {
ns.Push(navstack.NavigationItem{Model: m, Title: "main menu"})
p := tea.NewProgram(ns, tea.WithAltScreen())

_, err := p.Run()
finalns, err := p.Run()
if err != nil {
fmt.Println("Error running program:", err)
os.Exit(1)
}

result := ns.Top().Model.(model)
// the resulting model is a navstack. With the top model being the one that quit.
result := finalns.(navstack.Model).Top().Model.(model)

log.Printf("You selected the color %s from the artist %s ", result.SelectedColor, result.SelectedArtist)
}
6 changes: 5 additions & 1 deletion examples/simple/color/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

switch msg.(tea.KeyMsg).String() {
case "esc":
return m, cmdize(navstack.PopNavigation{})
pop := cmdize(navstack.PopNavigation{})
selected := cmdize(ColorSelected{m.RGB})
return m, tea.Sequence(pop, selected)
case "ctrl+c":
return m, tea.Quit
}

return m, nil
Expand Down
5 changes: 3 additions & 2 deletions examples/simple/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ func main() {

p := tea.NewProgram(ns, tea.WithAltScreen())

_, err := p.Run()
finalns, err := p.Run()
if err != nil {
fmt.Println("Error running program:", err)
os.Exit(1)
}

log.Printf("You selected the color: %s", ns.Top().Model.(model).SelectedColor)
result := finalns.(navstack.Model).Top().Model.(model)
log.Printf("You selected the color: %s", result.SelectedColor)
}

0 comments on commit 9b1d03c

Please sign in to comment.