Skip to content

Commit

Permalink
adds function to perform a single UI render
Browse files Browse the repository at this point in the history
  • Loading branch information
apoclyps committed May 4, 2021
1 parent acfcd74 commit eb62709
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 15 deletions.
18 changes: 11 additions & 7 deletions cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from create import prepare_database
from reviews import config
from reviews.tasks import render
from reviews.tasks import render, single_render
from reviews.version import __version__

CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"])
Expand All @@ -17,19 +17,23 @@ async def main():


@main.command(help="Display a dashboard")
async def dashboard():
@click.option("-r", "--reload/--no-reload", default=True, is_flag=True)
async def dashboard(reload):
"""Dashboard command."""

click.echo("loading dashboard")

if config.ENABLE_PERSISTED_DATA:
prepare_database()

# TODO: move github polling to another thread
await asyncio.gather(
# asyncio.to_thread(update),
asyncio.to_thread(render),
)
if reload:
# TODO: move github polling to another thread
await asyncio.gather(
# asyncio.to_thread(update),
asyncio.to_thread(render),
)
else:
single_render()


if __name__ == "__main__":
Expand Down
12 changes: 6 additions & 6 deletions reviews/layout/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ def render_pull_request_table(
return table


def generate_layout() -> Layout:
def generate_layout(footer: bool = True) -> Layout:
"""Define the layout for the terminal UI."""
layout = Layout(name="root")

layout.split(
Layout(name="header", size=3),
Layout(name="main", ratio=1),
Layout(name="footer", size=7),
)
sections = [Layout(name="header", size=3), Layout(name="main", ratio=1)]
if footer:
sections.append(Layout(name="footer", size=7))
layout.split(*sections)

layout["main"].split_row(
Layout(name="left_side", size=50),
Layout(name="body", ratio=2, minimum_size=80),
Expand Down
11 changes: 9 additions & 2 deletions reviews/layout/managers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Optional

from rich.console import Console
from rich.panel import Panel

Expand All @@ -13,14 +15,19 @@ def __init__(self, layout):
self.layout = layout

def render_layout(
self, progress_table, body, pull_request_component, log_component
self,
body,
pull_request_component,
log_component,
progress_table: Optional[Panel] = None,
):
"""Renders the entire layout"""
self.render_header()
self.render_body(component=body)
self.render_log(component=log_component)
self.render_configuration(component=pull_request_component)
self.render_footer(progress_table=progress_table)
if progress_table:
self.render_footer(progress_table=progress_table)

return self.layout

Expand Down
25 changes: 25 additions & 0 deletions reviews/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,31 @@ def _render_pull_requests(
)


def single_render():
"""Renders the Terminal UI Dashboard once before closing the application"""

# initial load should be from database
add_log_event(message="initializing...")

configuration = config.get_configuration()
controller = PullRequestController()

layout_manager = RenderLayoutManager(layout=generate_layout(footer=False))
layout_manager.render_layout(
body=_render_pull_requests(controller=controller, configuration=configuration),
pull_request_component=generate_tree_layout(configuration=configuration),
log_component=generate_log_table(logs=logs),
)

with Live(
renderable=layout_manager.layout,
refresh_per_second=5,
transient=False,
screen=True,
):
add_log_event(message="updated")


def render():
"""Renders Terminal UI Dashboard"""
(
Expand Down

0 comments on commit eb62709

Please sign in to comment.