forked from Mirrors/bubbletea
Exit example after pretend loading is completed
This commit is contained in:
parent
5999ff458c
commit
8df1395e0a
|
@ -17,6 +17,7 @@ type Model struct {
|
||||||
Ticks int
|
Ticks int
|
||||||
Frames int
|
Frames int
|
||||||
Progress float64
|
Progress float64
|
||||||
|
Loaded bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type tickMsg struct{}
|
type tickMsg struct{}
|
||||||
|
@ -25,7 +26,7 @@ type frameMsg struct{}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
p := tea.NewProgram(
|
p := tea.NewProgram(
|
||||||
Model{0, false, 10, 0, 0},
|
Model{0, false, 10, 0, 0, false},
|
||||||
update,
|
update,
|
||||||
view,
|
view,
|
||||||
[]tea.Sub{tick, frame},
|
[]tea.Sub{tick, frame},
|
||||||
|
@ -112,13 +113,23 @@ func updateChosen(msg tea.Msg, m Model) (tea.Model, tea.Cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
case frameMsg:
|
case frameMsg:
|
||||||
|
if !m.Loaded {
|
||||||
m.Frames += 1
|
m.Frames += 1
|
||||||
m.Progress = ease.OutBounce(float64(m.Frames) / float64(120))
|
m.Progress = ease.OutBounce(float64(m.Frames) / float64(60))
|
||||||
if m.Progress > 1 {
|
if m.Progress >= 1 {
|
||||||
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
|
return m, nil
|
||||||
|
@ -165,12 +176,17 @@ func chosenView(m Model) string {
|
||||||
case 1:
|
case 1:
|
||||||
msg = "A trip to the market?\n\nOkay, then we should install marketkit and libshopping..."
|
msg = "A trip to the market?\n\nOkay, then we should install marketkit and libshopping..."
|
||||||
case 2:
|
case 2:
|
||||||
msg = "Reading time?\n\nOkay, cool, then we’ll need a library. Yes, a literal library..."
|
msg = "Reading time?\n\nOkay, cool, then we’ll need a library. Yes, an actual library."
|
||||||
default:
|
default:
|
||||||
msg = "It’s always good to see friends.\n\nFetching social-skills and conversationutils..."
|
msg = "It’s 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 {
|
func checkbox(label string, checked bool) string {
|
||||||
|
|
Loading…
Reference in New Issue