"""
Base screen class for the console UI.

Every screen in the application inherits from :class:`Screen` and overrides
:meth:`on_enter`, :meth:`on_key`, and :meth:`render`.
"""


class Screen:
    """Abstract base for all console screens.

    Subclasses must override the three lifecycle methods to provide real
    behaviour.  The base implementations are intentional no-ops so that
    simple screens (e.g. a static splash page) need not implement every
    method.

    Attributes:
        name:  Machine-readable identifier used by :class:`Navigation`.
        title: Human-readable heading displayed at the top of the screen.
    """

    def __init__(self, name: str, title: str):
        self.name = name
        self.title = title

    def on_enter(self, context, db, renderer) -> None:
        """Called once when this screen becomes the active screen.

        Use this hook to load data, reset scroll positions, or set up
        key bindings specific to the screen.
        """

    def on_key(self, key: int, context, db, renderer, nav):
        """Handle a single keypress.

        Returns a navigation instruction (e.g. a dict or tuple) when the
        screen wants to push/pop, or ``None`` to stay on the current
        screen.
        """
        return None

    def render(self, context, db, renderer) -> None:
        """Draw the screen contents using *renderer*.

        Called after every keypress and on initial display.
        """
