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

Suggest 'fn_on_resize' callback argument to Terminal()? #131

Open
jquast opened this issue Jan 18, 2020 · 2 comments
Open

Suggest 'fn_on_resize' callback argument to Terminal()? #131

jquast opened this issue Jan 18, 2020 · 2 comments

Comments

@jquast
Copy link
Owner

jquast commented Jan 18, 2020

We now have a "detect window size method" as a documentation snippet, which is not compatible with Windows. We should probably prefer to support it as a built-in, I'm sure there is a windows method. To the downstream developer, they define their own function for callback when the window is resized.

We also document that bit, about the need to be careful to do minimum processing, be interruptible and re-entrant, and suggest to perform no input or output in the callback itself (but rather, set a "dirty" flag).

@jquast jquast changed the title Suggest to add an 'fn_on_resize' callback argument to Terminal()? Suggest 'fn_on_resize' callback argument to Terminal()? Jan 18, 2020
@avylove
Copy link
Collaborator

avylove commented Jan 22, 2020

Unfortunately, on Windows it's not as easy as listening for a signal. Basically you can periodically check the size of the console or listen for a resize event on the input buffer. In both cases you need some kind of a loop, possibly running in another thread or process.

@jquast
Copy link
Owner Author

jquast commented Mar 25, 2020

        :arg on_resize: A function that is given the terminal as the first
            positional argument, which is called each time terminal is resized.

            .. note::

               A GUI operation of "drag resize" with a mouse may flare hundreds
               to thousands of calls per second, so a "dirty" flag or object
               such as :class:`threading.Event` should be used to indicate your
               event loop to refresh when set.

            .. warning::

               It is not safe to print from this function!

               This callback must perform no I/O and be re-entrant. This
               means **do not redraw the screen!** with the ``on_resize``
               callback funnction. It is not safe to print or perform
               any I/O, such as print. See https://bugs.python.org/issue24283

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