Skip to content

Index

dev_tool.tui.help

__all__ = ['HelpInterface', 'HelpSection'] module-attribute

HelpSection

Bases: StrEnum

MAIN_MENU = 'Main Menu' class-attribute instance-attribute

TASK_VIEW = 'Task View' class-attribute instance-attribute

TASK_RESULT_VIEW = 'Task Result View' class-attribute instance-attribute

GENERAL = 'General' class-attribute instance-attribute

HelpInterface

The constructor for the HelpInterface class.

Parameters:

  • terminal (Terminal) –

    The blessed Terminal instance.

Source code in dev_tool/tui/help/interface.py
def __init__(self, terminal: Terminal) -> None:
    """
    The constructor for the HelpInterface class.

    :param terminal: The blessed Terminal instance.
    """

    self.terminal = terminal

terminal = terminal instance-attribute

draw_help_screen

A method that draws the help screen with keyboard shortcuts.

Source code in dev_tool/tui/help/interface.py
def draw_help_screen(self) -> None:
    """A method that draws the help screen with keyboard shortcuts."""

    output = []
    output.append(self.terminal.home + self.terminal.clear)

    header = ' Help'
    background = ' ' * self.terminal.width

    output.append(
        self.terminal.move(0, 0) +
        self.terminal.on_color_rgb(43, 40, 59) +
        self.terminal.bold +
        self.terminal.color_rgb(255, 255, 255) +
        background +
        self.terminal.normal
    )

    output.append(
        self.terminal.move(0, 0) +
        self.terminal.on_color_rgb(43, 40, 59) +
        self.terminal.bold +
        self.terminal.color_rgb(255, 255, 255) +
        header +
        self.terminal.normal
    )

    sections = [
        (HelpSection.MAIN_MENU, [
            ('↑/↓', 'Navigate menu items'),
            ('←/→', 'Navigate tabs'),
            ('Enter', 'Select menu item'),
            ('Backspace', 'Go back'),
            ('Q', 'Quit application'),
            ('T', 'Open task monitor'),
            ('H', 'Toggle help'),
        ]),
        (HelpSection.TASK_VIEW, [
            ('↑/↓', 'Navigate tasks'),
            ('Enter', 'View task result'),
            ('R', 'Refresh'),
            ('Backspace', 'Return to main menu'),
            ('Q', 'Quit application'),
            ('H', 'Toggle help'),
        ]),
        (HelpSection.TASK_RESULT_VIEW, [
            ('Backspace', 'Return to task list'),
            ('Q', 'Quit application'),
            ('H', 'Toggle help'),
        ]),
        (HelpSection.GENERAL, [
            ('X', 'Dismiss notifications'),
        ]),
    ]

    line = 3

    for title, shortcuts in sections:
        output.append(
            self.terminal.move(line, 4) +
            self.terminal.bold +
            title + ':' +
            self.terminal.normal
        )

        line = line + 1

        for key, description in shortcuts:
            output.append(
                self.terminal.move(line, 8) +
                f'{key:<12} {description}'
            )

            line = line + 1

        line = line + 1

    status_text = ' Press h to close help menu'
    status_bg = ' ' * self.terminal.width
    status_line = self.terminal.height - 1

    output.append(
        self.terminal.move(status_line, 0) +
        self.terminal.on_color_rgb(70, 68, 80) +
        self.terminal.color_rgb(255, 255, 255) +
        status_bg +
        self.terminal.normal
    )

    output.append(
        self.terminal.move(status_line, 0) +
        self.terminal.on_color_rgb(70, 68, 80) +
        self.terminal.color_rgb(255, 255, 255) +
        status_text +
        self.terminal.normal
    )

    print(''.join(output), end='', flush=True)  # noqa: T201

handle_input

A method that handles input for the help interface.

Parameters:

  • key (str) –

    The key name.

Returns:

  • str | None

    The navigation result or None to continue.

Source code in dev_tool/tui/help/interface.py
def handle_input(self, key: str) -> str | None:
    """
    A method that handles input for the help interface.

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

    match key:
        case _ if key.lower() == Key.HELP:
            return MenuAction.HELP_CLOSE
        case _ if key.lower() == Key.QUIT:
            return MenuAction.QUIT
        case _ if key in (Key.BACKSPACE, Key.DELETE, Key.ESCAPE):
            return MenuAction.HELP_CLOSE
        case _:
            return None