Skip to content

views

dev_tool.tui.views

ViewManager

A manager class for handling view switching and delegation.

This class centralizes view management, reducing controller complexity.

The constructor for the ViewManager class.

Parameters:

  • terminal (Terminal) –

    The blessed Terminal instance.

  • ui (UserInterface) –

    The user interface instance.

Source code in dev_tool/tui/views.py
def __init__(self, terminal: Terminal, ui: UserInterface) -> None:
    """
    The constructor for the ViewManager class.

    :param terminal: The blessed Terminal instance.
    :param ui: The user interface instance.
    """

    self.current = ViewType.MAIN_MENU
    self.display_content: str | None = None
    self.display_interface = DisplayInterface(terminal)
    self.help_interface = HelpInterface(terminal)
    self.task_interface = TaskInterface(terminal)
    self.terminal = terminal
    self.ui = ui

current = ViewType.MAIN_MENU instance-attribute

display_content = None instance-attribute

display_interface = DisplayInterface(terminal) instance-attribute

help_interface = HelpInterface(terminal) instance-attribute

task_interface = TaskInterface(terminal) instance-attribute

terminal = terminal instance-attribute

ui = ui instance-attribute

draw

A method that draws the current view.

Source code in dev_tool/tui/views.py
def draw(self) -> None:
    """A method that draws the current view."""

    match self.current:
        case ViewType.HELP:
            self.help_interface.draw_help_screen()
        case ViewType.TASK:
            self.task_interface.draw_progress_screen()
        case ViewType.DISPLAY if self.display_content:
            self.display_interface.draw_display(self.display_content)
        case _:
            self.ui.draw_menu()

handle_input

A method that delegates input handling to the current view.

Parameters:

  • key (str) –

    The key name.

Returns:

  • str | None

    The action result or None to continue.

Source code in dev_tool/tui/views.py
def handle_input(self, key: str) -> str | None:
    """
    A method that delegates input handling to the current view.

    :param key: The key name.
    :return: The action result or None to continue.
    """

    if key.lower() == Key.QUIT:
        return MenuAction.QUIT

    match self.current:
        case ViewType.HELP:
            return self._handle_help_input(key)
        case ViewType.DISPLAY:
            return self._handle_display_input(key)
        case ViewType.TASK:
            return self._handle_task_input(key)
        case _:
            return self._handle_menu_input(key)

needs_redraw

A method that checks if the current view needs redrawing.

Returns:

  • bool

    True if redraw needed, False otherwise.

Source code in dev_tool/tui/views.py
def needs_redraw(self) -> bool:
    """
    A method that checks if the current view needs redrawing.

    :return: True if redraw needed, False otherwise.
    """

    match self.current:
        case ViewType.TASK:
            return self.task_interface.needs_refresh()
        case _:
            return False

set_display_content

A method that sets display content and switches to display view.

Parameters:

  • content (str) –

    The content to display.

Source code in dev_tool/tui/views.py
def set_display_content(self, content: str) -> None:
    """
    A method that sets display content and switches to display view.

    :param content: The content to display.
    """

    self.display_content = content
    self.display_interface.offset = 0
    self.switch_to(ViewType.DISPLAY)

switch_to

A method that switches to a different view.

Parameters:

  • view (ViewType) –

    The view type to switch to.

Source code in dev_tool/tui/views.py
def switch_to(self, view: ViewType) -> None:
    """
    A method that switches to a different view.

    :param view: The view type to switch to.
    """

    if view == ViewType.MAIN_MENU:
        self.display_content = None

    self.current = view
    self.draw()