fitzzftw.patch.lines.HunkHeadLine

        ---
config:
  height: 300px
  width: 300px

title: HunkHeadLine
---
classDiagram
  PatchLine <|-- HunkHeadLine
  TerminalColorMixin <|-- HunkHeadLine
    

Inheritage diagramm for HunkHeadLine

class HunkHeadLine[source]

Bases: TerminalColorMixin, PatchLine

Represents a hunk header line within a patch (starting with ‘@@ ‘).

This class specializes PatchLine to handle coordinate metadata. It isolates the range information from optional context info (like function names) and provides parsed access to the line numbers.

Public Data Attributes:

prefix

The '@@ ' prefix at the start of the line (ro).

info

The optional context information after the coordinates (ro).

old_start

The starting line number in the original file (ro).

old_len

The number of lines affected in the original file (ro).

new_start

The starting line number in the new file (ro).

new_len

The number of lines in the new hunk (ro).

coords

All coordinates as a tuple: (old_start, old_len, new_start, new_len) (ro).

Inherited from TerminalColorMixin

use_colors

Global toggle to enable or disable colorized output.

Inherited from PatchLine

content

The cleaned content of the line without trailing newlines (ro).

orig_line

The original of the line without trailing newlines (ro).

has_trailing_whitespace

Public Methods:

__init__(raw_line)

Initializes the HunkHeadLine by extracting coordinates and optional info.

__repr__()

Return repr(self).

Inherited from TerminalColorMixin

colorize(text, color_key[, bold])

Colorizes the text using ANSI escape sequences.

print(**kwargs)

Prints the line with color mapping based on its prefix.

Inherited from PatchLine

__init__(raw_line)

Initializes a PatchLine instance by sanitizing the input.

__repr__()

Return repr(self).

Private Data Attributes:

_color_map

_HUNK_RE

Inherited from TerminalColorMixin

_ANSI

Internal mapping of semantic names to ANSI escape sequences.

Inherited from PatchLine

_TRAIL_WS_RE

_has_trailing_whitespace

_content

_orig_line


_ANSI: Color = <fitzzftw.patch.static.Color object>

Internal mapping of semantic names to ANSI escape sequences. Can be overridden for testing purposes.

__init__(raw_line)[source]

Initializes the HunkHeadLine by extracting coordinates and optional info.

Parameters:

raw_line (str) – The complete, unmodified hunk header line.

Raises:

ValueError – If the prefix or the coordinates are invalid.

colorize(text, color_key, bold=False, **kwargs)

Colorizes the text using ANSI escape sequences.

Parameters:
  • text (str) – The string to colorize.

  • color_key ('red' | 'green' | 'yellow' | 'cyan' | 'terminal') – The color to use (‘red’, ‘green’, ‘cyan’).

  • bold (bool) – Whether to make the output bold.

  • kwargs – Arbitrary keyword arguments forwarded to the built-in print() function. This allows for fine-grained control over the output, such as specifying a custom ‘file’ stream or changing the line termination via ‘end’ (e.g., end=”|”).

Returns:

Colorized string or plain text if colors are disabled.

Return type:

None

property content: str

The cleaned content of the line without trailing newlines (ro).

Returns:

A string representing the text content of the line.

property coords: tuple[int, int, int, int]

All coordinates as a tuple: (old_start, old_len, new_start, new_len) (ro).

property info: str | None

The optional context information after the coordinates (ro).

property new_len: int

The number of lines in the new hunk (ro).

property new_start: int

The starting line number in the new file (ro).

property old_len: int

The number of lines affected in the original file (ro).

property old_start: int

The starting line number in the original file (ro).

property orig_line: str

The original of the line without trailing newlines (ro).

Returns:

A string representing the text content of the line.

property prefix: str

The ‘@@ ‘ prefix at the start of the line (ro).

print(**kwargs)

Prints the line with color mapping based on its prefix.

Raises:

FtwProtocolError – If the class does not satisfy the LineLike protocol.

Parameters:

kwargs – Passed to colorize/print (e.g., end, file).

use_colors: ClassVar[bool] = True

Global toggle to enable or disable colorized output. Defaults to True; should be set explicitly based on CLI flags.