[Solved] Multiplexing ncurses getch and mpsc::channel


#1

I want to process ncurses input (from wgetch, a blocking API) and output from a child process (that I’m currently sending through an mpsc::Receiver) as they’re received. I need to do this on a single thread since ncurses isn’t multithreaded.

In C land, it looks like someone accomplished something similar with poll(2) here.

What’s the “rustic” way of doing this? I’m not sure if it’s possible to integrate tokio with ncurses (maybe with the blocking annotation?). I wasn’t able to get poll to work with the child FD – I just ran into deadlock while waiting for the child to be read from.


#2

I think I have a solution: I wrapped the ncurses library in a global lock, and then poll stdin’s fd on a separate thread. When poll returns, I can lock ncurses, call wgetch, and then send the input through a channel. No need to also poll on the child!