Exit example after pretend loading is completed

This commit is contained in:
Christian Rocha 2020-01-14 16:24:01 -05:00
parent 5999ff458c
commit 8df1395e0a
No known key found for this signature in database
GPG Key ID: D6CC7A16E5878018
1 changed files with 24 additions and 8 deletions

View File

@ -17,6 +17,7 @@ type Model struct {
Ticks int
Frames int
Progress float64
Loaded bool
}
type tickMsg struct{}
@ -25,7 +26,7 @@ type frameMsg struct{}
func main() {
p := tea.NewProgram(
Model{0, false, 10, 0, 0},
Model{0, false, 10, 0, 0, false},
update,
view,
[]tea.Sub{tick, frame},
@ -112,13 +113,23 @@ func updateChosen(msg tea.Msg, m Model) (tea.Model, tea.Cmd) {
}
case frameMsg:
if !m.Loaded {
m.Frames += 1
m.Progress = ease.OutBounce(float64(m.Frames) / float64(120))
if m.Progress > 1 {
m.Progress = ease.OutBounce(float64(m.Frames) / float64(60))
if m.Progress >= 1 {
m.Progress = 1
m.Loaded = true
m.Ticks = 3
}
}
return m, nil
case tickMsg:
if m.Loaded {
if m.Ticks == 0 {
return m, tea.Quit
}
m.Ticks -= 1
}
}
return m, nil
@ -165,12 +176,17 @@ func chosenView(m Model) string {
case 1:
msg = "A trip to the market?\n\nOkay, then we should install marketkit and libshopping..."
case 2:
msg = "Reading time?\n\nOkay, cool, then well need a library. Yes, a literal library..."
msg = "Reading time?\n\nOkay, cool, then well need a library. Yes, an actual library."
default:
msg = "Its always good to see friends.\n\nFetching social-skills and conversationutils..."
}
return "\n" + msg + "\n\n\n\n\n Downloading...\n" + progressbar(80, m.Progress) + "%"
label := "Downloading..."
if m.Loaded {
label = fmt.Sprintf("Downloaded. Exiting in %d...", m.Ticks)
}
return msg + "\n\n\n\n\n\n " + label + "\n" + progressbar(80, m.Progress) + "%"
}
func checkbox(label string, checked bool) string {