"""Abstraction for line-based high-lighters=======================================This module defines :class:`LineHighlighter`, a thin:class:`typing.Protocol` that specifies the minimal contract required by thecolour pipeline implemented in :pyfile:`base.py`.Implementors are expected to decorate :class:`rich.text.Text` objects **inplace**; therefore methods must not alter the underlying string content –only styling metadata."""fromtypingimportList,Protocol,Sequencefromrich.textimportText
[docs]classLineHighlighter(Protocol):"""Protocol for single-line high-lighters. Concrete implementations *may* also override :meth:`colorize_lines` for bulk operations, but :meth:`colorize_line` is the only mandatory method. """
[docs]defcolorize_line(self,line:Text)->Text:"""Stylise one line **in-place** and return it. Parameters ---------- line : A single :class:`rich.text.Text` instance to be colour-styled. Returns ------- The **same** `Text` object, now containing style spans. Raises ------ NotImplementedError Always here; concrete subclasses must override this method. """raiseNotImplementedError("LineHighlighter.colorize_line должен быть переопределен")
[docs]defcolorize_lines(self,lines:Sequence[Text])->List[Text]:"""Vectorised helper that stylises a *sequence* of lines. The naïve fallback simply delegates to :meth:`colorize_line`. Parameters ---------- lines : Ordered collection of :class:`rich.text.Text` objects. Returns ------- The original objects, now styled in place. """return[self.colorize_line(t)fortinlines]