From e1d4a14345372aaace8040a6f0055c2224fb395e Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Mon, 20 Jan 2020 10:35:03 -0800 Subject: [PATCH] Commands should probably receive the model as an arg, right? --- examples/go.mod | 10 ++++++++++ examples/go.sum | 11 +++++++++++ examples/http/main.go | 2 +- go.mod | 5 ++++- go.sum | 2 ++ tea.go | 8 ++++---- 6 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 examples/go.mod create mode 100644 examples/go.sum 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) }() } }