Skip to content

tab

dev_tool.tui.components.tab

TabComponent

A component for rendering the tabs.

The constructor for the TabComponent class.

Parameters:

  • terminal (Terminal) –

    The blessed Terminal instance.

  • theme (Default) –

    The theme instance for styling.

  • state (StateManager) –

    The state manager instance.

Source code in dev_tool/tui/components/tab.py
def __init__(self, terminal: Terminal, theme: Default, state: StateManager) -> None:
    """
    The constructor for the TabComponent class.

    :param terminal: The blessed Terminal instance.
    :param theme: The theme instance for styling.
    :param state: The state manager instance.
    """

    self.notification = NotificationDisplay(terminal)
    self.state = state
    self.terminal = terminal
    self.theme = theme

notification = NotificationDisplay(terminal) instance-attribute

state = state instance-attribute

terminal = terminal instance-attribute

theme = theme instance-attribute

draw

A method that draws the tab navigation if applicable.

Parameters:

  • output (list) –

    The list to append terminal output strings to.

Source code in dev_tool/tui/components/tab.py
def draw(self, output: list) -> None:
    """
    A method that draws the tab navigation if applicable.

    :param output: The list to append terminal output strings to.
    """

    if not self.state.is_tabs():
        return

    lines = len(self.notification.get_notification_lines())
    line = 3 + lines

    background = ' ' * self.terminal.width

    output.append(
        self.terminal.move(line, 0) +
        self.theme.tab_unselected(background)
    )

    tabs = self.state.root.items
    current = self.state.tab

    x = 0

    for index, item in enumerate(tabs):
        text = f'  {item.label}  '

        if index == current:
            output.append(
                self.terminal.move(line, x) +
                self.theme.tab_selected(text)
            )
        else:
            output.append(
                self.terminal.move(line, x) +
                self.theme.tab_unselected(text)
            )

        x = x + len(text)

        if x >= self.terminal.width - 20:
            break