diff --git a/examples/go.mod b/examples/go.mod new file mode 100644 index 0000000..747af16 --- /dev/null +++ b/examples/go.mod @@ -0,0 +1,10 @@ +module examples + +go 1.13 + +require ( + github.com/charmbracelet/tea v0.0.0-20200120035228-5156905c3e10 + github.com/charmbracelet/teaparty v0.0.0-20200118155738-c83a0bee59b9 + github.com/fogleman/ease v0.0.0-20170301025033-8da417bf1776 + golang.org/x/sys v0.0.0-20200120151820-655fe14d7479 // indirect +) diff --git a/examples/go.sum b/examples/go.sum new file mode 100644 index 0000000..9e103a2 --- /dev/null +++ b/examples/go.sum @@ -0,0 +1,11 @@ +github.com/charmbracelet/tea v0.0.0-20200118154546-df52853f9d94/go.mod h1:lijy1lXOKNwMjBu/jTT/DvR8yE9PhtX2olGFsCz9/Vk= +github.com/charmbracelet/tea v0.0.0-20200120035228-5156905c3e10 h1:C8gRihuPFEUON+BsEe4SsKDfHhgZlStosn9YvE+mtjU= +github.com/charmbracelet/tea v0.0.0-20200120035228-5156905c3e10/go.mod h1:lijy1lXOKNwMjBu/jTT/DvR8yE9PhtX2olGFsCz9/Vk= +github.com/charmbracelet/teaparty v0.0.0-20200118155738-c83a0bee59b9 h1:YQvJgppGVexnzIJ+KJlK9lBYA3+zXfdqZO/5Ngedtb0= +github.com/charmbracelet/teaparty v0.0.0-20200118155738-c83a0bee59b9/go.mod h1:z8JWtuxM0oA+dZfi7BkgBW2YGbyOTbWAixFs46W3SK4= +github.com/fogleman/ease v0.0.0-20170301025033-8da417bf1776 h1:VRIbnDWRmAh5yBdz+J6yFMF5vso1It6vn+WmM/5l7MA= +github.com/fogleman/ease v0.0.0-20170301025033-8da417bf1776/go.mod h1:9wvnDu3YOfxzWM9Cst40msBF1C2UdQgDv962oTxSuMs= +github.com/pkg/term v0.0.0-20190109203006-aa71e9d9e942 h1:A7GG7zcGjl3jqAqGPmcNjd/D9hzL95SuoOQAaFNdLU0= +github.com/pkg/term v0.0.0-20190109203006-aa71e9d9e942/go.mod h1:eCbImbZ95eXtAUIbLAuAVnBnwf83mjf6QIVH8SHYwqQ= +golang.org/x/sys v0.0.0-20200120151820-655fe14d7479 h1:LhLiKguPgZL+Tglay4GhVtfF0kb8cvOJ0dHTCBO8YNI= +golang.org/x/sys v0.0.0-20200120151820-655fe14d7479/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/examples/http/main.go b/examples/http/main.go index 3351cf3..067e25a 100644 --- a/examples/http/main.go +++ b/examples/http/main.go @@ -73,7 +73,7 @@ func view(model tea.Model) string { return fmt.Sprintf("The server said: %d %s", m.Status, http.StatusText(m.Status)) } -func checkServer() tea.Msg { +func checkServer(_ tea.Model) tea.Msg { c := &http.Client{ Timeout: 10 * time.Second, } diff --git a/go.mod b/go.mod index a467eb6..d192701 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,7 @@ module github.com/charmbracelet/tea go 1.13 -require github.com/pkg/term v0.0.0-20190109203006-aa71e9d9e942 +require ( + github.com/pkg/term v0.0.0-20190109203006-aa71e9d9e942 + golang.org/x/sys v0.0.0-20200120151820-655fe14d7479 // indirect +) diff --git a/go.sum b/go.sum index ba844f5..5d1a519 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,4 @@ github.com/pkg/term v0.0.0-20190109203006-aa71e9d9e942 h1:A7GG7zcGjl3jqAqGPmcNjd/D9hzL95SuoOQAaFNdLU0= github.com/pkg/term v0.0.0-20190109203006-aa71e9d9e942/go.mod h1:eCbImbZ95eXtAUIbLAuAVnBnwf83mjf6QIVH8SHYwqQ= +golang.org/x/sys v0.0.0-20200120151820-655fe14d7479 h1:LhLiKguPgZL+Tglay4GhVtfF0kb8cvOJ0dHTCBO8YNI= +golang.org/x/sys v0.0.0-20200120151820-655fe14d7479/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/tea.go b/tea.go index 1741880..aa824d3 100644 --- a/tea.go +++ b/tea.go @@ -17,7 +17,7 @@ type Msg interface{} type Model interface{} // Cmd is an IO operation. If it's nil it's considered a no-op. -type Cmd func() Msg +type Cmd func(Model) Msg // Sub is an event subscription. If it returns nil it's considered a no-op. type Sub func(Model) Msg @@ -60,7 +60,7 @@ func NewErrMsg(s string) ErrMsg { } // Quit is a command that tells the program to exit -func Quit() Msg { +func Quit(_ Model) Msg { return quitMsg{} } @@ -121,7 +121,7 @@ func (p *Program) Start() error { } }() - // Initialize subscriptions + // Process subscriptions go func() { if len(p.subscriptions) > 0 { for _, sub := range p.subscriptions { @@ -143,7 +143,7 @@ func (p *Program) Start() error { case cmd := <-cmds: if cmd != nil { go func() { - msgs <- cmd() + msgs <- cmd(model) }() } }