-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Hello, That's sorry for my bad english.
I need to update view, use async function.
I know the model.Update(msg tea.Msg) can update view, that will return a tea.Cmd, but how do i call update view function at a new async function (goroutine)?
I have a blog list, I use the list-fancy to show it, and when I type the Enter key, program will open a editor to edit it. I use a new goroutine to listen the editor's close, it success. but, I can't use a function to update view. (maybe update article title to "* {title} " or update the status message to "save file: {title} success")
like this,
case key.Matches(msg, keys.choose):
go func() {
time.Sleep(time.Second)
_ = Typora.Open(title)
Typora.OnClose(func() {
// what func should i call
// m.Update(msg)?
// It return `tea.Cmd`, but I can't use it
})
}()
return m.NewStatusMessage(statusMessageStyle("Open file: " + title))
I tried use a variable to record status, when status change
i use the new if branch to return m.NewStatusMessage(statusMessageStyle("Save file: " + title))
but it does not work...
like this,
var status int
case key.Matches(msg, keys.choose):
if status != 0 {
// It return `tea.Cmd`, but I have no a func to call with it
return m.NewStatusMessage(statusMessageStyle("Save file: " + title))
}
status = 1
go func() {
time.Sleep(time.Second)
_ = Typora.Open(title)
Typora.OnClose(func() {
m.Update(msg)
})
}()
return m.NewStatusMessage(statusMessageStyle("Open file: " + title))
Can somebody teach me how to update ?