jroimartin / gocui

Minimalist Go package aimed at creating Console User Interfaces.
BSD 3-Clause "New" or "Revised" License
9.92k stars 608 forks source link

Forcing a re-update from another go-routine. #77

Closed awnumar closed 8 years ago

awnumar commented 8 years ago

I think #15 is related but it seems outdated since I can't find any reference to concurrency or the flush() function/method in the docs.

How can you update a view from another goroutine? Currently the only way I can make edits show up on the screen is by pressing a random key so it loops again and shows the updates. How can this be down without pressing the key?

It seems there is a flush function as referenced in #15, but it's not exported so cannot be accessed externally.

jroimartin commented 8 years ago

You can use *Gui.Execute():

https://godoc.org/github.com/jroimartin/gocui#Gui.Execute

From the documentation:

IMPORTANT: Views can only be created, destroyed or updated in three ways: from the Layout function within managers, from keybinding callbacks or via Gui.Execute(). The reason for this is that it allows gocui to be conccurent-safe. So, if you want to update your GUI from a goroutine, you must use Gui.Execute().

Also, you can give a look to this example:

https://github.com/jroimartin/gocui/blob/master/_examples/goroutine.go

awnumar commented 8 years ago

Ah I see. Sorry, that wasn't immediately obvious.

jroimartin commented 8 years ago

No problem! I'll try to make it clearer on the documentation. Also, I'm considering to rename it from *Gui.Execute() to *Gui.Do().

awnumar commented 8 years ago

I think it should just be more clear what execute does exactly, not just what you can use it to do.

Also, would the rename retain backwards compatibility?

jroimartin commented 8 years ago

Regarding backwards compatibility, If you look at the commits since tag v0.3, there are lots of breaking changes. I prefer to continue working on improving the API and making it more clear and consistent, even if it requires breaking the "contract".

Once gocui reaches 1.0, the API should be stable and new changes will respect backwards compatibility. In the meantime, people can use vendoring, forks, etc. to avoid broken builds and so on.

jroimartin commented 8 years ago

Relates to: #68

awnumar commented 8 years ago

Ah alright. That's fair enough.

On Sun, 13 Nov 2016, 11:20 Roi Martin, notifications@github.com wrote:

Regarding backwards compatibility, If you look at the commits since tag v0.3, there are lots of breaking changes. I prefer to continue working on improving the API and making it more clear and consistent, even if it requires breaking the "contract".

Once gocui reaches 1.0, the API should be stable and new changes will respect backwards compatibility. In the meantime, people can use vendoring, forks, etc. to avoid broken builds and so on.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/jroimartin/gocui/issues/77#issuecomment-260179983, or mute the thread https://github.com/notifications/unsubscribe-auth/AIhzn9MvcWaEn-GFy3zyDWOP2gYJu9BGks5q9vJlgaJpZM4KwPRT .

jroimartin commented 8 years ago

I created #78 and #79. Is it ok for you if I close this one? :)

awnumar commented 8 years ago

Sure thing.