jquast / blessed

Blessed is an easy, practical library for making python terminal apps

Home Page:http://pypi.python.org/pypi/blessed

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Suggest 'fn_on_resize' callback argument to Terminal()?

jquast opened this issue · comments

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

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.

        :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