forked from Mirrors/bubbletea
Commands should probably receive the model as an arg, right?
This commit is contained in:
parent
5156905c3e
commit
e1d4a14345
10
examples/go.mod
Normal file
10
examples/go.mod
Normal file
@ -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
|
||||
)
|
11
examples/go.sum
Normal file
11
examples/go.sum
Normal file
@ -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=
|
@ -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,
|
||||
}
|
||||
|
5
go.mod
5
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
|
||||
)
|
||||
|
2
go.sum
2
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=
|
||||
|
8
tea.go
8
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)
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user