jfreeze/ex_ncurses

enif_select error when calling getch() repeatedly

Closed this issue · 0 comments

Currently, selecting on stdin is enabled on the call to listen and disabled on the call to stop_listen. getch was implemented by enabling listening, getting a key and then stopping listening. This sometimes causes this error:

23:02:35.719 [error] enif_select(_, 26, READ, 'Elixir.ExNcurses.Nif':monitor, undefined) called before stop was called for NIF resource 'Elixir.ExNcurses.Nif':monitor

It's probably best for ExNcurses to listen for key events at all times and only forward the events to users when asked. This would fix this error. It seems like there's another error in how enif_select is handled, though, which may just be masked by making this change.

The intention is that users listen for key events at the beginning of the app and then stop listening when they're done with ncurses. Getch was implemented to help with one-off "wait for key" dialogs.

I'll fix this when I get a chance - leaving this bug here in case anyone else runs into it.