solent-eng / solent

Free software sequencer architecture
GNU Lesser General Public License v3.0
7 stars 4 forks source link

Hack stdin receiver into the current event loop #76

Closed cratuki closed 7 years ago

cratuki commented 7 years ago

I'm having a think about major changes to the solent engine. But in the meantime, it is hard to do fun projects with it. To get through this period, it wouldn't hurt to put a mechanism into the engine so that we can hack stdin into the event loop. Reckon we need a new function to add it to the loop, with a callback that fires when stdin activity is detected.

cratuki commented 7 years ago

Hmm. This totally won't work on Windows. Can't select against anything except sockets on Windows. Let's get it working with unix, and then we might have to do something horrific with threads if it detects it's windows.

cratuki commented 7 years ago

Found a way to get it working. It's minimal: there is a mechanism for registering extra file descriptors with the engine for reading. If the engine detects activity with them, it does nothing itself, it just calls back.

In solent.client.tclient, I have shown how you can use this to detect that there is curses activity, and then use a curses-ey mechanism to get the keystrokes out. The result feels responsive, like you are interacting with a well-written text-editor.

This allows me to now use solent effectively for applications where I want curses interaction to feel responsive. Nice.