awesome-gocui / gocui

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

Implement synchronization for using keys in testing #102

Closed dankox closed 2 years ago

dankox commented 2 years ago

Fixes #100

Key events are asynchronous when testing terminal application, but for testing it is better when the behaviour is more deterministic. That is the reason for this PR.

To have more deterministic testing we introduce notification channel, which is used only during testing to find out when all the events were processed in the MainLoop.

The gocui.testNotify channel is initalized only when creating new testing, so it is used only during testing.
Counter gocui.testCounter is used when receiving timeEvent from tcell. Counter is increased for each such event, so when multiple synchronizations are triggered, all gets their reply.
The reply occurs at the end of MainLoop after the flush() function. This way the user/test can be sure that the screen was updated and can try to check if the screen looks as requested.

The timeEvent event is present in tcell but is used only in tcell application, so it shouldn't interfere with anything in gocui (tcell shouldn't post it in regular cases which gocui deals with).

mjarkk commented 2 years ago

@zigdon can you also give this a review?

zigdon commented 2 years ago

looks good to me!