Skip to content
Myr

main.go

This file

Path

examples/sequence/main.go

71 lines · 1.4 KiB · Go

Last changed by

examples/sequence: fix milisecond typo in SleepPrintlnmakoto-developerbefore adoption6fb1f47

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–7why, one step back
1package main
23// A simple example illustrating how to run a series of commands in order.45import (6 "fmt"7 "os"

Merge pull request #848 from wolfmagnate/fix-nested-cmd-orderAyman Bagabasbefore adoptionffa0502

line 8why, one step back
8 "time"

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

line 9why, one step back
9

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

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

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

lines 11–15why, one step back
11)
1213type model struct{}1415func (m model) Init() tea.Cmd {

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

lines 16–18why, one step back
16 // A tea.Sequence is a command that runs a series of commands in
17 // order. Contrast this with tea.Batch, which runs a series of commands18 // concurrently, with no order guarantees.

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

lines 19–20why, one step back
19 return tea.Sequence(
20 tea.Batch(

Merge pull request #848 from wolfmagnate/fix-nested-cmd-orderAyman Bagabasbefore adoptionffa0502

lines 21–28why, one step back
21 tea.Sequence(
22 SleepPrintln("1-1-1", 1000),23 SleepPrintln("1-1-2", 1000),24 ),25 tea.Batch(26 SleepPrintln("1-2-1", 1500),27 SleepPrintln("1-2-2", 1250),28 ),

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

line 29why, one step back
29 ),

Merge pull request #848 from wolfmagnate/fix-nested-cmd-orderAyman Bagabasbefore adoptionffa0502

lines 30–40why, one step back
30 tea.Println("2"),
31 tea.Sequence(32 tea.Batch(33 SleepPrintln("3-1-1", 500),34 SleepPrintln("3-1-2", 1000),35 ),36 tea.Sequence(37 SleepPrintln("3-2-1", 750),38 SleepPrintln("3-2-2", 500),39 ),40 ),

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

lines 41–42why, one step back
41 tea.Quit,
42 )

Merge pull request #848 from wolfmagnate/fix-nested-cmd-orderAyman Bagabasbefore adoptionffa0502

lines 43–45why, one step back
43}
4445// print string after stopping for a certain period of time

examples/sequence: fix milisecond typo in SleepPrintlnmakoto-developerbefore adoption6fb1f47

line 46why, one step back
46func SleepPrintln(s string, millisecond int) tea.Cmd {

Merge pull request #848 from wolfmagnate/fix-nested-cmd-orderAyman Bagabasbefore adoptionffa0502

lines 47–48why, one step back
47 printCmd := tea.Println(s)
48 return func() tea.Msg {

examples/sequence: fix milisecond typo in SleepPrintlnmakoto-developerbefore adoption6fb1f47

line 49why, one step back
49 time.Sleep(time.Duration(millisecond) * time.Millisecond)

Merge pull request #848 from wolfmagnate/fix-nested-cmd-orderAyman Bagabasbefore adoptionffa0502

lines 50–51why, one step back
50 return printCmd()
51 }

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

lines 52–55why, one step back
52}
5354func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {55 switch msg.(type) {

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

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

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

lines 57–61why, one step back
57 return m, tea.Quit
58 }59 return m, nil60}61

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

lines 62–63why, one step back
62func (m model) View() tea.View {
63 return tea.NewView("")

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

lines 64–71why, one step back
64}
6566func main() {67 if _, err := tea.NewProgram(model{}).Run(); err != nil {68 fmt.Println("Uh oh:", err)69 os.Exit(1)70 }71}