chore: gofmt sources
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Christian Muehlhaeuser · committed by Christian Muehlhaeuser · parent a7b1d7c · Browse files · 7 files·+107 added−112 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
7 files+107 added−112 removed
- other:+107 added−112 removed
Provenance
- Commit
1e1b5f7- Tree
f3dab42- Author
Christian Muehlhaeuser <muesli@gmail.com>- Committer
Christian Muehlhaeuser <muesli@gmail.com>- Parent
a7b1d7c
7 files changed+107 added−112 removed
modified:commands.go+52 added-54 removed
17 unmodified lines18 //19 // To produce the command, pass a duration and a function which returns20 // a message containing the time at which the tick occurred.21 //22-// type TickMsg time.Time22+// type TickMsg time.Time23 //24-// cmd := Every(time.Second, func(t time.Time) Msg {25-// return TickMsg(t)26-// })24+// cmd := Every(time.Second, func(t time.Time) Msg {25+// return TickMsg(t)26+// })27 //28 // Beginners' note: Every sends a single message and won't automatically29 // dispatch messages at an interval. To do that, you'll want to return another30 // Every command after receiving your tick message. For example:31 //32-// type TickMsg time.Time32+// type TickMsg time.Time33 //34-// // Send a message every second.35-// func tickEvery() Cmd {36-// return Every(time.Second, func(t time.Time) Msg {37-// return TickMsg(t)38-// })39-// }34+// // Send a message every second.35+// func tickEvery() Cmd {36+// return Every(time.Second, func(t time.Time) Msg {37+// return TickMsg(t)38+// })39+// }40 //41-// func (m model) Init() Cmd {42-// // Start ticking.43-// return tickEvery()44-// }41+// func (m model) Init() Cmd {42+// // Start ticking.43+// return tickEvery()44+// }45 //46-// func (m model) Update(msg Msg) (Model, Cmd) {47-// switch msg.(type) {48-// case TickMsg:49-// // Return your Every command again to loop.50-// return m, tickEvery()51-// }52-// return m, nil53-// }46+// func (m model) Update(msg Msg) (Model, Cmd) {47+// switch msg.(type) {48+// case TickMsg:49+// // Return your Every command again to loop.50+// return m, tickEvery()51+// }52+// return m, nil53+// }54 //55 // Every is analogous to Tick in the Elm Architecture.56 func Every(duration time.Duration, fn func(time.Time) Msg) Cmd {57 return func() Msg {10 unmodified lines68 //69 // To produce the command, pass a duration and a function which returns70 // a message containing the time at which the tick occurred.71 //72-// type TickMsg time.Time72+// type TickMsg time.Time73 //74-// cmd := Tick(time.Second, func(t time.Time) Msg {75-// return TickMsg(t)76-// })74+// cmd := Tick(time.Second, func(t time.Time) Msg {75+// return TickMsg(t)76+// })77 //78 // Beginners' note: Tick sends a single message and won't automatically79 // dispatch messages at an interval. To do that, you'll want to return another80 // Tick command after receiving your tick message. For example:81 //82-// type TickMsg time.Time82+// type TickMsg time.Time83 //84-// func doTick() Cmd {85-// return Tick(time.Second, func(t time.Time) Msg {86-// return TickMsg(t)87-// })88-// }84+// func doTick() Cmd {85+// return Tick(time.Second, func(t time.Time) Msg {86+// return TickMsg(t)87+// })88+// }89 //90-// func (m model) Init() Cmd {91-// // Start ticking.92-// return doTick()93-// }90+// func (m model) Init() Cmd {91+// // Start ticking.92+// return doTick()93+// }94 //95-// func (m model) Update(msg Msg) (Model, Cmd) {96-// switch msg.(type) {97-// case TickMsg:98-// // Return your Tick command again to loop.99-// return m, doTick()100-// }101-// return m, nil102-// }103-//95+// func (m model) Update(msg Msg) (Model, Cmd) {96+// switch msg.(type) {97+// case TickMsg:98+// // Return your Tick command again to loop.99+// return m, doTick()100+// }101+// return m, nil102+// }103 func Tick(d time.Duration, fn func(time.Time) Msg) Cmd {104 return func() Msg {105 t := time.NewTimer(d)106 return fn(<-t.C)3 unmodified lines110 // Sequentially produces a command that sequentially executes the given111 // commands.112 // The Msg returned is the first non-nil message returned by a Cmd.113 //115-// func saveStateCmd() Msg {116-// if err := save(); err != nil {117-// return errMsg{err}118-// }119-// return nil120-// }114+// func saveStateCmd() Msg {115+// if err := save(); err != nil {116+// return errMsg{err}117+// }118+// return nil119+// }120 //122-// cmd := Sequentially(saveStateCmd, Quit)123-//121+// cmd := Sequentially(saveStateCmd, Quit)122 func Sequentially(cmds ...Cmd) Cmd {123 return func() Msg {124 for _, cmd := range cmds {125 if cmd == nil {9 unmodified linesmodified:exec.go+6 added-6 removed
32 unmodified lines33 // To produce the command, pass an *exec.Cmd and a function which returns34 // a message containing the error which may have occurred when running the35 // ExecCommand.36 //37-// type VimFinishedMsg struct { err error }37+// type VimFinishedMsg struct { err error }38 //39-// c := exec.Command("vim", "file.txt")39+// c := exec.Command("vim", "file.txt")40 //41-// cmd := ExecProcess(c, func(err error) Msg {42-// return VimFinishedMsg{err: error}43-// })41+// cmd := ExecProcess(c, func(err error) Msg {42+// return VimFinishedMsg{err: error}43+// })44 //45 // Or, if you don't care about errors, you could simply:46 //47-// cmd := ExecProcess(exec.Command("vim", "file.txt"), nil)47+// cmd := ExecProcess(exec.Command("vim", "file.txt"), nil)48 //49 // For non-interactive i/o you should use a Cmd (that is, a tea.Cmd).50 func ExecProcess(c *exec.Cmd, fn ExecCallback) Cmd {51 return Exec(wrapExecCommand(c), fn)78 unmodified linesmodified:key.go+33 added-34 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 string representation of the key (shorter)15-// switch msg := msg.(type) {16-// case KeyMsg:17-// switch msg.String() {18-// case "enter":19-// fmt.Println("you pressed enter!")20-// case "a":21-// fmt.Println("you pressed a!")22-// }23-// }14+// // Switch on the string representation of the key (shorter)15+// switch msg := msg.(type) {16+// case KeyMsg:17+// switch msg.String() {18+// case "enter":19+// fmt.Println("you pressed enter!")20+// case "a":21+// fmt.Println("you pressed a!")22+// }23+// }24 //25-// // Switch on the key type (more foolproof)26-// switch msg := msg.(type) {27-// case KeyMsg:28-// switch msg.Type {29-// case KeyEnter:30-// fmt.Println("you pressed enter!")31-// case KeyRunes:32-// switch string(msg.Runes) {33-// case "a":34-// fmt.Println("you pressed a!")35-// }36-// }37-// }25+// // Switch on the key type (more foolproof)26+// switch msg := msg.(type) {27+// case KeyMsg:28+// switch msg.Type {29+// case KeyEnter:30+// fmt.Println("you pressed enter!")31+// case KeyRunes:32+// switch string(msg.Runes) {33+// case "a":34+// fmt.Println("you pressed a!")35+// }36+// }37+// }38 //39 // Note that Key.Runes will always contain at least one character, so you can40 // always safely call Key.Runes[0]. In most cases Key.Runes will only contain41 // one character, though certain input method editors (most notably Chinese15 unmodified lines57 58 // String returns a friendly string representation for a key. It's safe (and59 // encouraged) for use in key comparison.60 //61-// k := Key{Type: KeyEnter}62-// fmt.Println(k)63-// // Output: enter64-//61+// k := Key{Type: KeyEnter}62+// fmt.Println(k)63+// // Output: enter64 func (k Key) String() (str string) {65 if k.Alt {66 str += "alt+"67 }10 unmodified lines78 // KeyType indicates the key pressed, such as KeyEnter or KeyBreak or KeyCtrlC.79 // All other keys will be type KeyRunes. To get the rune value, check the Rune80 // method on a Key struct, or use the Key.String() method:81 //83-// k := Key{Type: KeyRunes, Runes: []rune{'a'}, Alt: true}84-// if k.Type == KeyRunes {82+// k := Key{Type: KeyRunes, Runes: []rune{'a'}, Alt: true}83+// if k.Type == KeyRunes {84 //86-// fmt.Println(k.Runes)87-// // Output: a85+// fmt.Println(k.Runes)86+// // Output: a87 //89-// fmt.Println(k.String())90-// // Output: alt+a88+// fmt.Println(k.String())89+// // Output: alt+a90 //92-// }91+// }92 type KeyType int93 94 func (k KeyType) String() (str string) {95 if s, ok := keyNames[k]; ok {471 unmodified linesmodified:logging.go+6 added-6 removed
10 unmodified lines11 // doesn't exist it will be created.12 //13 // Don't forget to close the file when you're done with it.14 //15-// f, err := LogToFile("debug.log", "debug")16-// if err != nil {17-// fmt.Println("fatal:", err)18-// os.Exit(1)19-// }20-// defer f.Close()15+// f, err := LogToFile("debug.log", "debug")16+// if err != nil {17+// fmt.Println("fatal:", err)18+// os.Exit(1)19+// }20+// defer f.Close()21 func LogToFile(path string, prefix string) (*os.File, error) {22 f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)23 if err != nil {24 return nil, err15 unmodified linesmodified:mouse.go+1 added-1 removed
61 unmodified lines62 // was December 1986, by the way.63 //64 // X10 mouse events look like:65 //66-// ESC [M Cb Cx Cy66+// ESC [M Cb Cx Cy67 //68 // See: http://www.xfree86.org/current/ctlseqs.html#Mouse%20Tracking69 func parseX10MouseEvents(buf []byte) ([]MouseEvent, error) {70 var r []MouseEvent79 unmodified linesmodified:options.go+6 added-7 removed
5 unmodified lines6 // accept a variable number of options.7 //8 // Example usage:9 //10-// p := NewProgram(model, WithInput(someInput), WithOutput(someOutput))11-//10+// p := NewProgram(model, WithInput(someInput), WithOutput(someOutput))11 type ProgramOption func(*Program)12 13 // WithOutput sets the output which, by default, is stdout. In most cases you14 // won't need to use this.34 unmodified lines49 // be automatically exited when the program quits.50 //51 // Example:52 //54-// p := tea.NewProgram(Model{}, tea.WithAltScreen())55-// if err := p.Start(); err != nil {56-// fmt.Println("Error running program:", err)57-// os.Exit(1)58-// }53+// p := tea.NewProgram(Model{}, tea.WithAltScreen())54+// if err := p.Start(); err != nil {55+// fmt.Println("Error running program:", err)56+// os.Exit(1)57+// }58 //59 // To enter the altscreen once the program has already started running use the60 // EnterAltScreen command.61 func WithAltScreen() ProgramOption {70 unmodified linesmodified:tea.go+3 added-4 removed
122 unmodified lines123 // about the results. Use a Batch to return several commands.124 //125 // Example:126 //127-// func (m model) Init() Cmd {128-// return tea.Batch(someCommand, someOtherCommand)129-// }130-//127+// func (m model) Init() Cmd {128+// return tea.Batch(someCommand, someOtherCommand)129+// }130 func Batch(cmds ...Cmd) Cmd {131 var validCmds []Cmd132 for _, c := range cmds {133 if c == nil {601 unmodified lines