"""
Classes used to replace the input in some tabs or special situations,
but which are not inputs.
"""

import logging
from poezio.windows.inputs import InputLike
from poezio.theming import get_theme, to_curses_attr

log = logging.getLogger(__name__)


class NoInput(InputLike):
    """A class for when there is no input field on a tab."""
    def refresh(self) -> None:
        return


class HelpText(InputLike):
    """
    A Window just displaying a read-only message.
    Usually used to replace an Input when the tab is in
    command mode.
    """

    def __init__(self, text: str = '') -> None:
        super().__init__()
        self.txt = text

    def refresh(self) -> None:
        """Refresh the window."""
        log.debug('Refresh: %s', self.__class__.__name__)
        self._win.erase()
        self.addstr(0, 0, self.txt[:self.width - 1],
                    to_curses_attr(get_theme().COLOR_INFORMATION_BAR))
        self.finish_line(get_theme().COLOR_INFORMATION_BAR)
        self._refresh()

    def refresh_txt(self, txt: str | None) -> None:
        """Refresh the window, but with new text."""
        if txt is not None:
            self.txt = txt
        self.refresh()
