Skip to content
Myr

main.go

This file

Path

examples/fullscreen/main.go

58 lines · 938 bytes · Go

Last changed by

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

History of this file

Take it

The walk stopped after 200 commits: lines older than 3dfbcd9 point at it.

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 1–10why, one step back
1package main
23// A simple program that opens the alternate screen buffer then counts down4// from 5 and then exits.56import (7 "fmt"8 "log"9 "time"10

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

line 11why, one step back
11 tea "charm.land/bubbletea/v2"

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 12–18why, one step back
12)
1314type model int1516type tickMsg time.Time1718func main() {

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

line 19why, one step back
19 p := tea.NewProgram(model(5))

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 20–30why, one step back
20 if _, err := p.Run(); err != nil {
21 log.Fatal(err)22 }23}2425func (m model) Init() tea.Cmd {26 return tick()27}2829func (m model) Update(message tea.Msg) (tea.Model, tea.Cmd) {30 switch msg := message.(type) {

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

line 31why, one step back
31 case tea.KeyPressMsg:

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 32–47why, one step back
32 switch msg.String() {
33 case "q", "esc", "ctrl+c":34 return m, tea.Quit35 }3637 case tickMsg:38 m--39 if m <= 0 {40 return m, tea.Quit41 }42 return m, tick()43 }4445 return m, nil46}47

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

lines 48–51why, one step back
48func (m model) View() tea.View {
49 v := tea.NewView(fmt.Sprintf("\n\n Hi. This program will exit in %d seconds...", m))50 v.AltScreen = true51 return v

feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9

lines 52–58why, one step back
52}
5354func tick() tea.Cmd {55 return tea.Tick(time.Second, func(t time.Time) tea.Msg {56 return tickMsg(t)57 })58}