Skip to content
Myr

Fix broken logic in original "views" example

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Christian Rocha · committed by Christian Rocha · parent b10f6d6 · Browse files · 1 file+17 added−11 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+17 added−11 removed

  • other:+17 added−11 removed

1 file+17 added−11 removed

modified:examples/views/main.go+17 added-11 removed
42 unmodified lines
4344// INIT4546func initialize() (tea.Model, tea.Cmd) {47 return Model{0, false, 10, 0, 0, false}, tick47 return Model{0, false, 10, 0, 0, false}, tick()48}4950// CMDS5152func tick() tea.Msg {53 time.Sleep(time.Second)54 return tickMsg{}52func tick() tea.Cmd {53 return tea.Tick(time.Second, func(time.Time) tea.Msg {54 return tickMsg{}55 })56}5757func frame() tea.Msg {58 time.Sleep(time.Second / 60)59 return frameMsg{}58func frame() tea.Cmd {59 return tea.Tick(time.Second/60, func(time.Time) tea.Msg {60 return frameMsg{}61 })62}6364// UPDATE65
26 unmodified lines
92 m.Choice = 093 }94 case "enter":95 m.Chosen = true94 return m, nil96 return m, frame()97 case "q":98 fallthrough99 case "esc":100 fallthrough
5 unmodified lines
106 if m.Ticks == 0 {107 return m, tea.Quit108 }109 m.Ticks -= 1110 return m, tick()111 }112110 return m, tick113 return m, nil114}115116func updateChosen(msg tea.Msg, m Model) (tea.Model, tea.Cmd) {117 switch msg := msg.(type) {
10 unmodified lines
128129 case frameMsg:130 if !m.Loaded {131 m.Frames += 1129 m.Progress = ease.OutBounce(float64(m.Frames) / float64(160))132 m.Progress = ease.OutBounce(float64(m.Frames) / float64(100))133 if m.Progress >= 1 {134 m.Progress = 1135 m.Loaded = true136 m.Ticks = 3137 return m, tick()138 }139 return m, frame()140 }141142 case tickMsg:143 if m.Loaded {144 if m.Ticks == 0 {145 return m, tea.Quit146 }147 m.Ticks -= 1148 return m, tick()149 }150 }151146 return m, frame152 return m, nil153}154155// VIEW156
69 unmodified lines