Skip to content
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

Closed
jquast opened this issue Aug 20, 2014 · 4 comments
Closed

Discover user's cursor position #19

jquast opened this issue Aug 20, 2014 · 4 comments

Comments

@jquast
Copy link
Owner

jquast commented Aug 20, 2014

See erikrose/blessings/#66 erikrose/blessings/#65 erikrose/blessings/#4

@thomasballinger
Copy link

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.

@jquast
Copy link
Owner Author

jquast commented Dec 2, 2014

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:

  • write the "report cursor position" sequence to output stream.
  • build a string by callling inkey() until the pattern is satisfied.
  • return any text received by inkey() and not satisfied by the pattern back into an input buffer for any subsequent calls to inkey().

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().

@thomasballinger
Copy link

Thanks, very clarifying. I had been putting the "only call once or twice" logic in the cursor query code, this is much nicer.

@jquast
Copy link
Owner Author

jquast commented Oct 24, 2015

Closed by #72

@jquast jquast closed this as completed Oct 24, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants