Skip to content

display

dev_tool.services.notification.display

NotificationDisplay

A display class for rendering notifications in the terminal.

This class handles the formatting and styling of notifications for display in both banner and text formats with terminal color support.

The constructor for the NotificationDisplay class.

Parameters:

  • terminal (Terminal | None, default: None ) –

    The blessed Terminal instance for display operations.

  • theme (Default | None, default: None ) –

    The theme instance for styling notifications.

Source code in dev_tool/services/notification/display.py
def __init__(self, terminal: Terminal | None = None, theme: Default | None = None) -> None:
    """
    The constructor for the NotificationDisplay class.

    :param terminal: The blessed Terminal instance for display operations.
    :param theme: The theme instance for styling notifications.
    """

    self.notification = NotificationService()
    self.terminal = terminal or Terminal()
    self.theme = theme or Default(self.terminal)

notification = NotificationService() instance-attribute

terminal = terminal or Terminal() instance-attribute

theme = theme or Default(self.terminal) instance-attribute

display_active

A method that displays all active notifications in command mode.

Parameters:

Source code in dev_tool/services/notification/display.py
def display_active(self, service: NotificationService) -> None:
    """
    A method that displays all active notifications in command mode.

    :param service: The notification service to get active notifications from.
    """

    notifications = service.get_active()

    if notifications:
        print(self.terminal.clear_eos, end='', flush=True)  # noqa: T201

        for notification in notifications:
            banner = self.format_notification_banner(notification)
            print(banner)  # noqa: T201

display_new_notifications

A method that displays any new notifications that haven't been shown yet.

Parameters:

  • service (NotificationService) –

    The notification service to get active notifications from.

  • displayed (set) –

    Set of already displayed notification keys.

Source code in dev_tool/services/notification/display.py
def display_new_notifications(self, service: NotificationService, displayed: set) -> None:
    """
    A method that displays any new notifications that haven't been shown yet.

    :param service: The notification service to get active notifications from.
    :param displayed: Set of already displayed notification keys.
    """

    for notification in service.get_active():
        key = (notification.message, notification.timestamp)

        if key not in displayed:
            banner = self.format_notification_banner(notification)
            print(banner, flush=True)  # noqa: T201
            displayed.add(key)

format_notification_banner

A method that formats a notification for banner display.

Parameters:

  • notification (Notification) –

    The notification object to format.

Returns:

  • str

    The formatted notification banner string.

Source code in dev_tool/services/notification/display.py
def format_notification_banner(self, notification: Notification) -> str:
    """
    A method that formats a notification for banner display.

    :param notification: The notification object to format.
    :return: The formatted notification banner string.
    """

    if notification.notification_format == NotificationFormat.BANNER:
        return self._format_banner_style(notification)

    return self._format_text_style(notification)

get_notification_lines

A method that gets formatted notification lines for display.

Returns:

  • list[str]

    A list of formatted notification line strings.

Source code in dev_tool/services/notification/display.py
def get_notification_lines(self) -> list[str]:
    """
    A method that gets formatted notification lines for display.

    :return: A list of formatted notification line strings.
    """

    lines = []

    for notification in self.notification.get_active():
        if notification.persistent:
            dismiss = '[Press x to dismiss]'
        else:
            remaining = int(notification.remaining_time)
            dismiss = f'[Press x to dismiss] [{remaining}s]'

        if notification.notification_format == NotificationFormat.BANNER:
            line = self._format_notification_line(
                notification.notification_type,
                notification.message,
                dismiss,
                notification.show_prefix
            )
        else:
            line = self._format_text_notification_line(
                notification.notification_type,
                notification.message,
                dismiss,
                notification.show_prefix
            )

        lines.append(line)

    return lines

has_active_notifications

A method that checks if there are any active notifications.

Returns:

  • bool

    True if there are active notifications, False otherwise.

Source code in dev_tool/services/notification/display.py
def has_active_notifications(self) -> bool:
    """
    A method that checks if there are any active notifications.

    :return: True if there are active notifications, False otherwise.
    """

    active = self.notification.get_active()
    return len(active) > 0