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

Window rendering improvements. #90

Merged
merged 2 commits into from
Jul 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/move_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async def window_moves():

for _ in range(15):
w2.move(dx=-2, dy=-1 if random.random()<0.4 else 0)
await api.window_render(w2)
await api.window_render(w2, terminal_render=False)
w1.move(dx=2, dy=1 if random.random()<0.5 else 0)
await api.window_render(w1)
await api.sleep(0.02)
Expand Down
7 changes: 5 additions & 2 deletions src/ppytty/kernel/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,16 @@ def window_destroy(window):


@types.coroutine
def window_render(window, full=False):
def window_render(window, full=False, terminal_render=True):
"""
Renders `window` onto the output terminal.
If `full` is True, the whole window contents is rendered; otherwise, only
the lines that changed since the previous render will be rendered.
If `terminal_render` is True, the terminal is rendered to the output TTY;
this allows tasks to optimize rendering multiple windows to the terminal
while only triggering the final terminal to TTY rendering at the end.
"""
yield Trap.WINDOW_RENDER, window, full
yield Trap.WINDOW_RENDER, window, full, terminal_render



Expand Down
22 changes: 14 additions & 8 deletions src/ppytty/kernel/traps.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def window_destroy(task, window):


@handler_for(Trap.WINDOW_RENDER)
def window_render(task, window, full=False):
def window_render(task, window, full=False, terminal_render=True):

if not window in state.task_windows[task]:
state.trap_will_throw(task, exceptions.TrapException('no such window'))
Expand All @@ -158,31 +158,37 @@ def window_render(task, window, full=False):
except ValueError:
raise RuntimeError('unexpected condition: window not in all_windows')

# Speed up attribute access
state_terminal = state.terminal
common_render_window_to_terminal = common.render_window_to_terminal
state_all_windows = state.all_windows

uncovered = window.uncovered_geometry()
if uncovered:
state.terminal.window.erase_geometry(*uncovered)
state_terminal.window.erase_geometry(*uncovered)
# Re-render windows below `window`, as needed.
for w in state.all_windows[:window_index]:
for w in state_all_windows[:window_index]:
if not w.overlaps_geometry(*uncovered):
continue
common.render_window_to_terminal(w, full=True)
common_render_window_to_terminal(w, full=True)
# Uncovered means move/resize: a full render is needed.
full = True


# Render the actual window.
common.render_window_to_terminal(window, full=full)
common_render_window_to_terminal(window, full=full)

# Re-render windows on top of `window`, as needed.
for w in state.all_windows[window_index+1:]:
for w in state_all_windows[window_index+1:]:
if not uncovered:
if not w.overlaps(window):
continue
elif not w.overlaps(window) and not w.overlaps_geometry(*uncovered):
continue
common.render_window_to_terminal(w, full=True)
common_render_window_to_terminal(w, full=True)

state.terminal.render()
if terminal_render:
state_terminal.render()

state.runnable_tasks.append(task)

Expand Down