fitzzftw.patch.lines.HeadLine

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

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

Inheritage diagramm for HeadLine

class HeadLine[source]

Bases: TerminalColorMixin, PatchLine

Represents a file header line within a patch (starting with ‘— ‘ or ‘+++ ‘).

This class specializes PatchLine to handle file-level metadata. It isolates the file path from the unified diff prefix and provides convenience methods to identify the role of the file (original vs. new) within a transition.

Public Data Attributes:

prefix

The diff prefix ('--- ' or '+++ ') identified at the start of the line (ro).

is_orig

Indicates if this line represents the original (source) file path (ro).

is_new

Indicates if this line represents the new (target) file path (ro).

is_null_path

Checks if the file path points to a null device (e.g., /dev/null) (ro).

info

Returns the metadata found after the file path (e.g., timestamps) (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 HeadLine by extracting the prefix and path content.

get_path(strip_count)

Returns the path as a Path object, stripped of N leading segments.

check_is_null_path(path)

Check if the given path represents a null path marker.

__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

_prefix

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 HeadLine by extracting the prefix and path content.

The first four characters are used to identify the header type. The remainder of the line is passed to the base class to ensure consistent sanitization of the path string.

Parameters:

raw_line (str) – The complete, unmodified header line from the patch.

static check_is_null_path(path)[source]

Check if the given path represents a null path marker.

This function detects special paths used in patch files to signify file deletion or creation, specifically: 1. ‘/dev/null’ (POSIX standard, case-sensitive). 2. ‘NUL’ (Windows standard, case-insensitive).

The implementation is hard-coded for maximum performance and stability, as these standards are highly unlikely to change.

Parameters:

path (Path | str) – The path object or string to check.

Returns:

True if the path matches a known null path marker, False otherwise.

Return type:

bool

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.

get_path(strip_count)[source]

Returns the path as a Path object, stripped of N leading segments.

Parameters:

strip_count (int) – Number of leading path components to remove.

Raises:

ValueError – If strip_count is too high for the available segments or is negative.

Returns:

A Path object of the remaining segments.

Return type:

Path

property info: str | None

Returns the metadata found after the file path (e.g., timestamps) (ro).

This contains everything that was separated by a tab character from the path. Returns an empty string or None if no metadata was present.

Returns:

The metadata string or None.

property is_new: bool

Indicates if this line represents the new (target) file path (ro).

Returns:

True if the prefix is ‘+++ ‘, False otherwise.

property is_null_path: bool

Checks if the file path points to a null device (e.g., /dev/null) (ro).

This property uses the static method check_is_null_path() to perform the null-path check.

Returns:

True if the content matches a null path pattern.

property is_orig: bool

Indicates if this line represents the original (source) file path (ro).

Returns:

True if the prefix is ‘— ‘, False otherwise.

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 diff prefix (’— ‘ or ‘+++ ‘) identified at the start of the line (ro).

Returns:

The prefix string.

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.