Implement synchronization for using keys in testing #102
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 receivingtimeEvent
fromtcell
. 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 theflush()
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 intcell
but is used only in tcell application, so it shouldn't interfere with anything ingocui
(tcell shouldn't post it in regular cases which gocui deals with).