Coverage for jsonschema_diff/color/abstraction.py: 86%
7 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-15 18:01 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-15 18:01 +0000
1"""
2Abstraction for line-based high-lighters
3=======================================
5This module defines :class:`LineHighlighter`, a thin
6:class:`typing.Protocol` that specifies the minimal contract required by the
7colour pipeline implemented in :pyfile:`base.py`.
9Implementors are expected to decorate :class:`rich.text.Text` objects **in
10place**; therefore methods must not alter the underlying string content –
11only styling metadata.
12"""
14from typing import List, Protocol, Sequence
16from rich.text import Text
19class LineHighlighter(Protocol):
20 """Protocol for single-line high-lighters.
22 Concrete implementations *may* also override
23 :meth:`colorize_lines` for bulk operations, but
24 :meth:`colorize_line` is the only mandatory method.
25 """
27 def colorize_line(self, line: Text) -> Text:
28 """Stylise one line **in-place** and return it.
30 Parameters
31 ----------
32 line :
33 A single :class:`rich.text.Text` instance to be colour-styled.
35 Returns
36 -------
37 The **same** `Text` object, now containing style spans.
39 Raises
40 ------
41 NotImplementedError
42 Always here; concrete subclasses must override this method.
43 """
44 raise NotImplementedError("LineHighlighter.colorize_line должен быть переопределен")
46 def colorize_lines(self, lines: Sequence[Text]) -> List[Text]:
47 """Vectorised helper that stylises a *sequence* of lines.
49 The naïve fallback simply delegates to :meth:`colorize_line`.
51 Parameters
52 ----------
53 lines :
54 Ordered collection of :class:`rich.text.Text` objects.
56 Returns
57 -------
58 The original objects, now styled in place.
59 """
60 return [self.colorize_line(t) for t in lines]