Improve examples in docs
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 1703547 · Browse files · 3 files·+39 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
3 files+39 added−11 removed
- other:+39 added−11 removed
Provenance
- Commit
6fcdf99- Tree
a70ba70- Author
Christian Rocha <christian@rocha.is>- Committer
Christian Rocha <christian@rocha.is>- Parent
1703547
3 files changed+39 added−11 removed
modified:commands.go+21 added-3 removed
13 unmodified lines14 // Because we're ticking with the system clock the tick will likely not run for15 // the entire specified duration. For example, if we're ticking for one minute16 // and the clock is at 12:34:20 then the next tick will happen at 12:35:00, 4017 // seconds later.18+//19+// To produce the command, pass a duration and a fnuction which returns20+// a message containing the time at which the tick occurred.21+//22+// type TickMsg time.Time23+//24+// cmd := Every(time.Second, func(t time.Time) Msg {25+// return TickMsg(t)26+// })27 func Every(duration time.Duration, fn func(time.Time) Msg) Cmd {28 return func() Msg {29 n := time.Now()30 d := n.Truncate(duration).Add(duration).Sub(n)1 unmodified line32 return fn(<-t.C)33 }34 }35 27-// Tick is a command that at an interval independent of the system clock at the28-// given duration. That is, the timer begins when precisely when invoked, and29-// runs for its entire duration.36+// Tick produces a command that at an interval independent of the system clock37+// at the given duration. That is, the timer begins when precisely when38+// invoked, and runs for its entire duration.39+//40+// To produce the command, pass a duration and a fnuction which returns41+// a message containing the time at which the tick occurred.42+//43+// type TickMsg time.Time44+//45+// cmd := Tick(time.Second, func(t time.Time) Msg {46+// return TickMsg(t)47+// })48 func Tick(d time.Duration, fn func(time.Time) Msg) Cmd {49 return func() Msg {50 t := time.NewTimer(d)51 return fn(<-t.C)2 unmodified linesmodified:key.go+13 added-4 removed
9 unmodified lines10 // KeyMsg contains information about a keypress. KeyMsgs are always sent to11 // the program's update function. There are a couple general patterns you could12 // use to check for keypresses:13 //14+// // Switch on the type (safer)15 // switch msg := msg.(type) {16 // case KeyMsg:17 // switch msg.Type {17-// case KeyEnter:18-// fmt.Println("you pressed enter!")18+// case KeyEnter:19+// fmt.Println("you pressed enter!")20+// case KeyRune:21+// switch msg.Rune {22+// case 'a':23+// fmt.Println("you pressed a!")24+// }25 // }26 // }27 //28+// // Switch on the string representation of the key (shorter)29 // switch msg := msg.(type) {30 // case KeyMsg:31 // switch msg.String() {25-// case "enter":26-// fmt.Println("you pressed enter!")32+// case "enter":33+// fmt.Println("you pressed enter!")34+// case "a':35+// fmt.Println("you pressed a!")36 // }37 // }38 type KeyMsg Key39 290 unmodified linesmodified:tea.go+5 added-4 removed
1-// Package tea provides an Elm-inspired framework for building rich terminal2-// user interfaces. It's well-suited for simple and complex terminal3-// applications, either inline, full-window, or a mix of both. It's been4-// battle-tested in several large projects and is production-ready.1+// Package tea provides a framework for building rich terminal user interfaces2+// based on the paradigms of The Elm Architecture. It's well-suited for simple3+// and complex terminal applications, either inline, full-window, or a mix of4+// both. It's been battle-tested in several large projects and is5+// production-ready.6 //7 // A tutorial is available at https://github.com/charmbracelet/bubbletea/tree/master/tutorials8 //9 // Example programs can be found at https://github.com/charmbracelet/bubbletea/tree/master/examples256 unmodified lines