mirror of
https://github.com/taigrr/bubbletea.git
synced 2026-04-02 02:59:09 -07:00
chore: gofmt sources
This commit is contained in:
106
commands.go
106
commands.go
@@ -19,38 +19,38 @@ import (
|
||||
// To produce the command, pass a duration and a function which returns
|
||||
// a message containing the time at which the tick occurred.
|
||||
//
|
||||
// type TickMsg time.Time
|
||||
// type TickMsg time.Time
|
||||
//
|
||||
// cmd := Every(time.Second, func(t time.Time) Msg {
|
||||
// return TickMsg(t)
|
||||
// })
|
||||
// cmd := Every(time.Second, func(t time.Time) Msg {
|
||||
// return TickMsg(t)
|
||||
// })
|
||||
//
|
||||
// Beginners' note: Every sends a single message and won't automatically
|
||||
// dispatch messages at an interval. To do that, you'll want to return another
|
||||
// Every command after receiving your tick message. For example:
|
||||
//
|
||||
// type TickMsg time.Time
|
||||
// type TickMsg time.Time
|
||||
//
|
||||
// // Send a message every second.
|
||||
// func tickEvery() Cmd {
|
||||
// return Every(time.Second, func(t time.Time) Msg {
|
||||
// return TickMsg(t)
|
||||
// })
|
||||
// }
|
||||
// // Send a message every second.
|
||||
// func tickEvery() Cmd {
|
||||
// return Every(time.Second, func(t time.Time) Msg {
|
||||
// return TickMsg(t)
|
||||
// })
|
||||
// }
|
||||
//
|
||||
// func (m model) Init() Cmd {
|
||||
// // Start ticking.
|
||||
// return tickEvery()
|
||||
// }
|
||||
// func (m model) Init() Cmd {
|
||||
// // Start ticking.
|
||||
// return tickEvery()
|
||||
// }
|
||||
//
|
||||
// func (m model) Update(msg Msg) (Model, Cmd) {
|
||||
// switch msg.(type) {
|
||||
// case TickMsg:
|
||||
// // Return your Every command again to loop.
|
||||
// return m, tickEvery()
|
||||
// }
|
||||
// return m, nil
|
||||
// }
|
||||
// func (m model) Update(msg Msg) (Model, Cmd) {
|
||||
// switch msg.(type) {
|
||||
// case TickMsg:
|
||||
// // Return your Every command again to loop.
|
||||
// return m, tickEvery()
|
||||
// }
|
||||
// return m, nil
|
||||
// }
|
||||
//
|
||||
// Every is analogous to Tick in the Elm Architecture.
|
||||
func Every(duration time.Duration, fn func(time.Time) Msg) Cmd {
|
||||
@@ -69,38 +69,37 @@ func Every(duration time.Duration, fn func(time.Time) Msg) Cmd {
|
||||
// To produce the command, pass a duration and a function which returns
|
||||
// a message containing the time at which the tick occurred.
|
||||
//
|
||||
// type TickMsg time.Time
|
||||
// type TickMsg time.Time
|
||||
//
|
||||
// cmd := Tick(time.Second, func(t time.Time) Msg {
|
||||
// return TickMsg(t)
|
||||
// })
|
||||
// cmd := Tick(time.Second, func(t time.Time) Msg {
|
||||
// return TickMsg(t)
|
||||
// })
|
||||
//
|
||||
// Beginners' note: Tick sends a single message and won't automatically
|
||||
// dispatch messages at an interval. To do that, you'll want to return another
|
||||
// Tick command after receiving your tick message. For example:
|
||||
//
|
||||
// type TickMsg time.Time
|
||||
// type TickMsg time.Time
|
||||
//
|
||||
// func doTick() Cmd {
|
||||
// return Tick(time.Second, func(t time.Time) Msg {
|
||||
// return TickMsg(t)
|
||||
// })
|
||||
// }
|
||||
// func doTick() Cmd {
|
||||
// return Tick(time.Second, func(t time.Time) Msg {
|
||||
// return TickMsg(t)
|
||||
// })
|
||||
// }
|
||||
//
|
||||
// func (m model) Init() Cmd {
|
||||
// // Start ticking.
|
||||
// return doTick()
|
||||
// }
|
||||
//
|
||||
// func (m model) Update(msg Msg) (Model, Cmd) {
|
||||
// switch msg.(type) {
|
||||
// case TickMsg:
|
||||
// // Return your Tick command again to loop.
|
||||
// return m, doTick()
|
||||
// }
|
||||
// return m, nil
|
||||
// }
|
||||
// func (m model) Init() Cmd {
|
||||
// // Start ticking.
|
||||
// return doTick()
|
||||
// }
|
||||
//
|
||||
// func (m model) Update(msg Msg) (Model, Cmd) {
|
||||
// switch msg.(type) {
|
||||
// case TickMsg:
|
||||
// // Return your Tick command again to loop.
|
||||
// return m, doTick()
|
||||
// }
|
||||
// return m, nil
|
||||
// }
|
||||
func Tick(d time.Duration, fn func(time.Time) Msg) Cmd {
|
||||
return func() Msg {
|
||||
t := time.NewTimer(d)
|
||||
@@ -112,15 +111,14 @@ func Tick(d time.Duration, fn func(time.Time) Msg) Cmd {
|
||||
// commands.
|
||||
// The Msg returned is the first non-nil message returned by a Cmd.
|
||||
//
|
||||
// func saveStateCmd() Msg {
|
||||
// if err := save(); err != nil {
|
||||
// return errMsg{err}
|
||||
// }
|
||||
// return nil
|
||||
// }
|
||||
//
|
||||
// cmd := Sequentially(saveStateCmd, Quit)
|
||||
// func saveStateCmd() Msg {
|
||||
// if err := save(); err != nil {
|
||||
// return errMsg{err}
|
||||
// }
|
||||
// return nil
|
||||
// }
|
||||
//
|
||||
// cmd := Sequentially(saveStateCmd, Quit)
|
||||
func Sequentially(cmds ...Cmd) Cmd {
|
||||
return func() Msg {
|
||||
for _, cmd := range cmds {
|
||||
|
||||
12
exec.go
12
exec.go
@@ -34,17 +34,17 @@ func Exec(c ExecCommand, fn ExecCallback) Cmd {
|
||||
// a message containing the error which may have occurred when running the
|
||||
// ExecCommand.
|
||||
//
|
||||
// type VimFinishedMsg struct { err error }
|
||||
// type VimFinishedMsg struct { err error }
|
||||
//
|
||||
// c := exec.Command("vim", "file.txt")
|
||||
// c := exec.Command("vim", "file.txt")
|
||||
//
|
||||
// cmd := ExecProcess(c, func(err error) Msg {
|
||||
// return VimFinishedMsg{err: error}
|
||||
// })
|
||||
// cmd := ExecProcess(c, func(err error) Msg {
|
||||
// return VimFinishedMsg{err: error}
|
||||
// })
|
||||
//
|
||||
// Or, if you don't care about errors, you could simply:
|
||||
//
|
||||
// cmd := ExecProcess(exec.Command("vim", "file.txt"), nil)
|
||||
// cmd := ExecProcess(exec.Command("vim", "file.txt"), nil)
|
||||
//
|
||||
// For non-interactive i/o you should use a Cmd (that is, a tea.Cmd).
|
||||
func ExecProcess(c *exec.Cmd, fn ExecCallback) Cmd {
|
||||
|
||||
67
key.go
67
key.go
@@ -11,30 +11,30 @@ import (
|
||||
// the program's update function. There are a couple general patterns you could
|
||||
// use to check for keypresses:
|
||||
//
|
||||
// // Switch on the string representation of the key (shorter)
|
||||
// switch msg := msg.(type) {
|
||||
// case KeyMsg:
|
||||
// switch msg.String() {
|
||||
// case "enter":
|
||||
// fmt.Println("you pressed enter!")
|
||||
// case "a":
|
||||
// fmt.Println("you pressed a!")
|
||||
// }
|
||||
// }
|
||||
// // Switch on the string representation of the key (shorter)
|
||||
// switch msg := msg.(type) {
|
||||
// case KeyMsg:
|
||||
// switch msg.String() {
|
||||
// case "enter":
|
||||
// fmt.Println("you pressed enter!")
|
||||
// case "a":
|
||||
// fmt.Println("you pressed a!")
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // Switch on the key type (more foolproof)
|
||||
// switch msg := msg.(type) {
|
||||
// case KeyMsg:
|
||||
// switch msg.Type {
|
||||
// case KeyEnter:
|
||||
// fmt.Println("you pressed enter!")
|
||||
// case KeyRunes:
|
||||
// switch string(msg.Runes) {
|
||||
// case "a":
|
||||
// fmt.Println("you pressed a!")
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// // Switch on the key type (more foolproof)
|
||||
// switch msg := msg.(type) {
|
||||
// case KeyMsg:
|
||||
// switch msg.Type {
|
||||
// case KeyEnter:
|
||||
// fmt.Println("you pressed enter!")
|
||||
// case KeyRunes:
|
||||
// switch string(msg.Runes) {
|
||||
// case "a":
|
||||
// fmt.Println("you pressed a!")
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// Note that Key.Runes will always contain at least one character, so you can
|
||||
// always safely call Key.Runes[0]. In most cases Key.Runes will only contain
|
||||
@@ -58,10 +58,9 @@ type Key struct {
|
||||
// String returns a friendly string representation for a key. It's safe (and
|
||||
// encouraged) for use in key comparison.
|
||||
//
|
||||
// k := Key{Type: KeyEnter}
|
||||
// fmt.Println(k)
|
||||
// // Output: enter
|
||||
//
|
||||
// k := Key{Type: KeyEnter}
|
||||
// fmt.Println(k)
|
||||
// // Output: enter
|
||||
func (k Key) String() (str string) {
|
||||
if k.Alt {
|
||||
str += "alt+"
|
||||
@@ -80,16 +79,16 @@ func (k Key) String() (str string) {
|
||||
// All other keys will be type KeyRunes. To get the rune value, check the Rune
|
||||
// method on a Key struct, or use the Key.String() method:
|
||||
//
|
||||
// k := Key{Type: KeyRunes, Runes: []rune{'a'}, Alt: true}
|
||||
// if k.Type == KeyRunes {
|
||||
// k := Key{Type: KeyRunes, Runes: []rune{'a'}, Alt: true}
|
||||
// if k.Type == KeyRunes {
|
||||
//
|
||||
// fmt.Println(k.Runes)
|
||||
// // Output: a
|
||||
// fmt.Println(k.Runes)
|
||||
// // Output: a
|
||||
//
|
||||
// fmt.Println(k.String())
|
||||
// // Output: alt+a
|
||||
// fmt.Println(k.String())
|
||||
// // Output: alt+a
|
||||
//
|
||||
// }
|
||||
// }
|
||||
type KeyType int
|
||||
|
||||
func (k KeyType) String() (str string) {
|
||||
|
||||
12
logging.go
12
logging.go
@@ -12,12 +12,12 @@ import (
|
||||
//
|
||||
// Don't forget to close the file when you're done with it.
|
||||
//
|
||||
// f, err := LogToFile("debug.log", "debug")
|
||||
// if err != nil {
|
||||
// fmt.Println("fatal:", err)
|
||||
// os.Exit(1)
|
||||
// }
|
||||
// defer f.Close()
|
||||
// f, err := LogToFile("debug.log", "debug")
|
||||
// if err != nil {
|
||||
// fmt.Println("fatal:", err)
|
||||
// os.Exit(1)
|
||||
// }
|
||||
// defer f.Close()
|
||||
func LogToFile(path string, prefix string) (*os.File, error) {
|
||||
f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
|
||||
if err != nil {
|
||||
|
||||
2
mouse.go
2
mouse.go
@@ -63,7 +63,7 @@ var mouseEventTypes = map[MouseEventType]string{
|
||||
//
|
||||
// X10 mouse events look like:
|
||||
//
|
||||
// ESC [M Cb Cx Cy
|
||||
// ESC [M Cb Cx Cy
|
||||
//
|
||||
// See: http://www.xfree86.org/current/ctlseqs.html#Mouse%20Tracking
|
||||
func parseX10MouseEvents(buf []byte) ([]MouseEvent, error) {
|
||||
|
||||
13
options.go
13
options.go
@@ -7,8 +7,7 @@ import "io"
|
||||
//
|
||||
// Example usage:
|
||||
//
|
||||
// p := NewProgram(model, WithInput(someInput), WithOutput(someOutput))
|
||||
//
|
||||
// p := NewProgram(model, WithInput(someInput), WithOutput(someOutput))
|
||||
type ProgramOption func(*Program)
|
||||
|
||||
// WithOutput sets the output which, by default, is stdout. In most cases you
|
||||
@@ -51,11 +50,11 @@ func WithoutCatchPanics() ProgramOption {
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// p := tea.NewProgram(Model{}, tea.WithAltScreen())
|
||||
// if err := p.Start(); err != nil {
|
||||
// fmt.Println("Error running program:", err)
|
||||
// os.Exit(1)
|
||||
// }
|
||||
// p := tea.NewProgram(Model{}, tea.WithAltScreen())
|
||||
// if err := p.Start(); err != nil {
|
||||
// fmt.Println("Error running program:", err)
|
||||
// os.Exit(1)
|
||||
// }
|
||||
//
|
||||
// To enter the altscreen once the program has already started running use the
|
||||
// EnterAltScreen command.
|
||||
|
||||
7
tea.go
7
tea.go
@@ -124,10 +124,9 @@ type Program struct {
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// func (m model) Init() Cmd {
|
||||
// return tea.Batch(someCommand, someOtherCommand)
|
||||
// }
|
||||
//
|
||||
// func (m model) Init() Cmd {
|
||||
// return tea.Batch(someCommand, someOtherCommand)
|
||||
// }
|
||||
func Batch(cmds ...Cmd) Cmd {
|
||||
var validCmds []Cmd
|
||||
for _, c := range cmds {
|
||||
|
||||
Reference in New Issue
Block a user