awesome-gocui / gocui

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

Add ability to use tcell simulated screen for testing gocui #86

Closed lawrencegripper closed 3 years ago

lawrencegripper commented 3 years ago

Describe the feature you'd like (Happy to PR this feature) tcell supports a simulated screen, this allows you to write unit tests which provide input and then assert about the content drawn on the screen.

https://github.com/gdamore/tcell/blob/master/sim_test.go

Adding in this feature by either exposing the tcell simulated screen or a wrapper to abstract it but allow input of keys and validation of the resulting content drawn would help building testable UI apps.

Describe alternatives you've considered Currently I do some horrible things in our CI pipeline to create a "real" screen on the CI box then spin up a xterm instance and pipe the results back.

Additional context Here is an example of another tcell based project using the simulated screen to write some nice tests. https://github.com/zyedidia/micro/blob/c0907bb58e35ee05202a78226a2f53909af228ca/cmd/micro/micro_test.go#L183

mjarkk commented 3 years ago

That would be very handy and i could imagine make testing for a lot of programs a lot more accessible so yea i'm open for this feature!
feel free to create a PR for this!

lawrencegripper commented 3 years ago

Cool, going to take a run at this now and see how far I get.

Given the rest of gocui abstracts the underlying tcell lib I'm going to wrap the features so in theory future work could change the underlying tcell driver and reimplement the funcs using another lib without users needing to make changes.

mjarkk commented 3 years ago

Can we now close this issue?

lawrencegripper commented 3 years ago

Yup 🥳