-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Discover user's cursor position #19
Comments
What kind of reentrancy behavior should getting the users's cursor position have? A common use case might be calling this from a SIGWINCH handler, in which case multiple calls could come in interrupting each other. In Curtsies I want to have a reentrant "get cursor vertical diff" function which doesn't double-count - ie call it several times, the sum of the differences you get will be the total difference in cursor vertical position - but seems like this could be build on top of any version. My question is what order reentrant calls to get_cursor_position should be resolved - a second call might receive the response intended for the first request. |
get_cursor_position() could not be re-entrant, it is most certainly a blocking call. You should never write to stdin/stdout from a signal handler, or do very much work at all. get_cursor_position() would:
Given this -- it is most definitely a blocking call, and you should not call it from a signal handler. This is not a limitation, however. You should not do any stdin/stdout writing of any kind directly from any signal handler -- Only so much as set a "dirty = True" flag that your primary event loop can handle. See for example in @Polyphemus's project https://github.com/polyphemus/macht/blob/develop/macht/term/main.py#L90 This way when a user resizes the screen 30 times in less than one second, (which happens when dragging the corner of a window), only 1 or 2 calls to "reconstitute" the display is needed, as the next time the event loops, it will just inspect such flag, unset it, then perform any necessary activity, such as calling get_cursor_position(). |
Thanks, very clarifying. I had been putting the "only call once or twice" logic in the cursor query code, this is much nicer. |
Closed by #72 |
See erikrose/blessings/#66 erikrose/blessings/#65 erikrose/blessings/#4
The text was updated successfully, but these errors were encountered: