Skip to content

interface

dev_tool.tui.interface

UserInterface

A class for the TUI user interface.

This class handles rendering and navigation in the TUI menu by composing various UI components together.

The constructor for the UserInterface class.

Parameters:

  • terminal (Terminal) –

    The blessed Terminal instance.

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

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

    self.terminal = terminal
    self.theme = Default(terminal)

    self.state = StateManager()

    self.header = HeaderComponent(terminal, self.theme)
    self.item = ItemComponent(terminal, self.theme, self.state)
    self.navigation = NavigationHandler(self.state, NotificationDisplay(terminal))
    self.notification = NotificationComponent(terminal)
    self.status_bar = StatusBarComponent(terminal, self.theme, self.state)
    self.tabs = TabComponent(terminal, self.theme, self.state)

terminal = terminal instance-attribute

theme = Default(terminal) instance-attribute

state = StateManager() instance-attribute

header = HeaderComponent(terminal, self.theme) instance-attribute

item = ItemComponent(terminal, self.theme, self.state) instance-attribute

navigation = NavigationHandler(self.state, NotificationDisplay(terminal)) instance-attribute

notification = NotificationComponent(terminal) instance-attribute

status_bar = StatusBarComponent(terminal, self.theme, self.state) instance-attribute

tabs = TabComponent(terminal, self.theme, self.state) instance-attribute

index property writable

A property that gets the current selected index.

Returns:

  • int

    The current index.

menu property

A property that gets the current menu.

Returns:

  • Menu

    The current menu.

offset property writable

A property that gets the current scroll offset.

Returns:

  • int

    The current offset.

row property writable

A property that gets the current row.

Returns:

  • int

    The current row.

stack property

A property that gets the navigation stack.

Returns:

  • list

    The navigation stack.

tab property writable

A property that gets the current tab index.

Returns:

  • int

    The current tab index.

draw_menu

A method that draws the entire menu.

Source code in dev_tool/tui/interface.py
def draw_menu(self) -> None:
    """A method that draws the entire menu."""

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

    self.header.draw(output)
    self.notification.draw(output)
    self.tabs.draw(output)
    self.item.draw(output)
    self.status_bar.draw(output)

    output.append(self.terminal.move(self.terminal.width - 1, self.terminal.height - 1))
    print(''.join(output), end='', flush=True)  # noqa: T201

get_selected_item

A method that gets the currently selected menu item.

Returns:

Source code in dev_tool/tui/interface.py
def get_selected_item(self) -> MenuItem:
    """
    A method that gets the currently selected menu item.

    :return: The selected menu item.
    """

    return self.navigation.get_selected_item()

go_back

A method that navigates back to the previous menu.

Source code in dev_tool/tui/interface.py
def go_back(self) -> None:
    """A method that navigates back to the previous menu."""

    self.state.go_back()

handle_navigation

A method that handles navigation key presses.

Parameters:

  • key (str) –

    The key name.

Source code in dev_tool/tui/interface.py
def handle_navigation(self, key: str) -> None:
    """
    A method that handles navigation key presses.

    :param key: The key name.
    """

    if self.navigation.handle_navigation(key):
        self.draw_menu()

set_menu

A method that sets the current menu.

Parameters:

  • menu (Menu) –

    The new menu.

Source code in dev_tool/tui/interface.py
def set_menu(self, menu: Menu) -> None:
    """
    A method that sets the current menu.

    :param menu: The new menu.
    """

    self.state.push_menu(menu)