diff options
author | Thomas Nixon <tom@tomn.co.uk> | 2018-02-19 22:31:38 +0000 |
---|---|---|
committer | Thomas Nixon <tom@tomn.co.uk> | 2018-02-19 23:15:29 +0000 |
commit | 01016563fccf31ddee6e5b8b4b13c065149dd814 (patch) | |
tree | b40d9ec08e364ea7b21185b2379efa42e1b6a161 /alot/ui.py | |
parent | 021735bdcba6763a5ed42cfce305e0ca33714db4 (diff) |
Move screen stop/start logic into context manager.
As well as reducing duplication and adding screen size detection to
:pipeto and :pyshell, this ensures that the screen is always restarted,
resulting in cleaner error handling if an error occurs while the screen
is stopped.
Diffstat (limited to 'alot/ui.py')
-rw-r--r-- | alot/ui.py | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -7,6 +7,7 @@ import logging import os import signal import codecs +import contextlib from twisted.internet import reactor, defer, task import urwid @@ -363,6 +364,24 @@ class UI(object): exit_msg = 'Could not stop reactor: {}.'.format(e) logging.error('%s\nShutting down anyway..', exit_msg) + @contextlib.contextmanager + def paused(self): + """ + context manager that pauses the UI to allow running external commands. + + If an exception occurs, the UI will be started before the exception is + re-raised. + """ + self.mainloop.stop() + try: + yield + finally: + self.mainloop.start() + + # make sure urwid renders its canvas at the correct size + self.mainloop.screen_size = None + self.mainloop.draw_screen() + def buffer_open(self, buf): """register and focus new :class:`~alot.buffers.Buffer`.""" |