Skip to content

Commit

Permalink
refactor: core: Explicitly define & encapsulate internal draw data.
Browse files Browse the repository at this point in the history
Also explicitly return True in callback from pipe to avoid possibility
of pipe removal.

Test amended.
  • Loading branch information
neiljp committed Nov 19, 2020
1 parent 4ac868e commit eaa7704
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion tests/core/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def test_initialize_controller(self, controller, mocker) -> None:

assert self.main_loop.call_count == 1
controller.loop.watch_pipe.assert_has_calls([
mocker.call(controller.draw_screen),
mocker.call(controller._draw_screen),
mocker.call(controller._raise_exception)
])

Expand Down
12 changes: 8 additions & 4 deletions zulipterminal/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ def __init__(self, config_file: str, theme_name: str, theme: ThemeSpec,
self.loop = urwid.MainLoop(self.view,
self.theme,
screen=screen)
self.update_pipe = self.loop.watch_pipe(self.draw_screen)

# urwid pipe for concurrent screen update handling
self._update_pipe = self.loop.watch_pipe(self._draw_screen)

# data and urwid pipe for inter-thread exception handling
self._exception_info = None # type: Optional[ExceptionInfo]
Expand Down Expand Up @@ -142,12 +144,14 @@ def restore_stdout(self) -> None:
del self._stdout

def update_screen(self) -> None:
# Update should not happen until pipe is set
assert hasattr(self, '_update_pipe')
# Write something to update pipe to trigger draw_screen
if hasattr(self, 'update_pipe'):
os.write(self.update_pipe, b'1')
os.write(self._update_pipe, b'1')

def draw_screen(self, *args: Any, **kwargs: Any) -> None:
def _draw_screen(self, *args: Any, **kwargs: Any) -> Literal[True]:
self.loop.draw_screen()
return True # Always retain pipe

def maximum_popup_dimensions(self) -> Tuple[int, int]:
"""
Expand Down

0 comments on commit eaa7704

Please sign in to comment.