jsonschema_diff.color

Convenience re-exports for the colour sub-package.

End-users can simply write:

from jsonschema_diff.color import HighlighterPipeline, LineHighlighter

Submodules

Classes

LineHighlighter

Protocol for single-line high-lighters.

HighlighterPipeline

Chain of LineHighlighter() stages.

Package Contents

class LineHighlighter[source]

Protocol for single-line high-lighters.

Concrete implementations may also override colorize_lines() for bulk operations, but colorize_line() is the only mandatory method.

abstractmethod colorize_line(line: Text) Text[source]

Stylise one line in-place and return it.

Parameters:

line – A single rich.text.Text instance to be colour-styled.

Return type:

The same Text object, now containing style spans.

Raises:

NotImplementedError – Always here; concrete subclasses must override this method.

colorize_lines(
lines: Sequence[Text],
) List[Text][source]

Vectorised helper that stylises a sequence of lines.

The naïve fallback simply delegates to colorize_line().

Parameters:

lines – Ordered collection of rich.text.Text objects.

Return type:

The original objects, now styled in place.

class HighlighterPipeline(
stages: Iterable[LineHighlighter],
)[source]

Chain of LineHighlighter() stages.

Parameters:

stages – Iterable of LineHighlighter instances. The iterable is immediately materialised into a list so the pipeline can be reused.

Note

  • Each input line is passed through every stage in order.

  • If a stage exposes a bulk colorize_lines() method it is preferred over per-line iteration for performance.

stages: list[LineHighlighter]
colorize(text: str) Text[source]

Return a rich Text object with all styles applied.

Parameters:

text – Multi-line string to be colourised.

Returns:

  • One composite Text built by joining all styled lines with

  • \n separators.

colorize_and_render(
text: str,
auto_line_wrapping: bool = False,
) str[source]

Colourise and immediately render to ANSI.

Parameters:

text – Multi-line input string.

Return type:

ANSI-encoded string ready for terminal output.