fitzzftw.patch.lines.HunkLine¶
---
config:
height: 300px
width: 300px
title: HunkLine
---
classDiagram
FileLine <|-- HunkLine
TerminalColorMixin <|-- HunkLine
Inheritage diagramm for HunkLine¶
- class HunkLine[source]¶
Bases:
TerminalColorMixin,FileLineRepresents a single content line within a hunk block of a unified diff.
The class parses the raw diff line upon instantiation and provides dynamically calculated, read-only content properties for different levels of whitespace normalization.
Public Data Attributes:
The diff prefix character (' ', '+', or '-') (ro).
Returns True if the line is a context line (' ') (ro).
Returns True if the line is an addition line ('+') (ro).
Returns True if the line is a deletion line ('-') (ro).
Inherited from
TerminalColorMixinGlobal toggle to enable or disable colorized output.
Inherited from
FileLineThe raw line content, stripped of the diff prefix and trailing newline (ro).
The line content, dynamically normalized according to the --normalize-ws rule (ro).
The line content, dynamically normalized according to the --ignore-all-ws rule (ro).
The diff prefix character (' ', '+', or '-') (ro).
Indicates if the original raw line contained trailing whitespace before the newline (ro).
Checks if the line content is an empty string (ro).
Get the processed line for filesystem output (ro).
State of the newline termination at the end of the line ((rw)).
Public Methods:
__init__(raw_line)Initializes the HunkLine by parsing the raw line.
__repr__()Return repr(self).
Inherited from
TerminalColorMixincolorize(text, color_key[, bold])Colorizes the text using ANSI escape sequences.
print(**kwargs)Prints the line with color mapping based on its prefix.
Private Data Attributes:
_color_map_prefix_has_newlineInherited from
TerminalColorMixinInternal mapping of semantic names to ANSI escape sequences.
Inherited from
FileLine_INTERNAL_WS_RE_ALL_WS_RE_prefixInherited 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 HunkLine by parsing the raw line.
The raw line must start with a valid diff prefix (’ ‘, ‘+’, or ‘-‘). The content is stored without the final newline character.
- Parameters:
raw_line (str) – The raw line from the patch file (including prefix).
- Raises:
PatchParseError – If the prefix is invalid or missing.
- 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 raw line content, stripped of the diff prefix and trailing newline (ro).
This value is used for standard matching when no whitespace flags are set.
- Returns:
The cleaned line content as a string.
- property has_newline: bool¶
State of the newline termination at the end of the line ((rw)).
- Parameters:
value – Set to False if the line lacks a trailing newline.
- Returns:
True if the line ends with a newline, False otherwise.
- property has_trailing_whitespace: bool¶
Indicates if the original raw line contained trailing whitespace before the newline (ro).
- Returns:
Boolean value.
- property ignore_all_ws_content: str¶
The line content, dynamically normalized according to the –ignore-all-ws rule (ro).
All forms of whitespace (leading, internal, trailing) are removed from the string.
- Returns:
The string content with all whitespace removed.
- property is_addition: bool¶
Returns True if the line is an addition line (‘+’) (ro).
- Returns:
Boolean value.
- property is_context: bool¶
Returns True if the line is a context line (’ ‘) (ro).
- Returns:
Boolean value.
- property is_deletion: bool¶
Returns True if the line is a deletion line (‘-’) (ro).
- Returns:
Boolean value.
- property is_empty: bool¶
Checks if the line content is an empty string (ro).
- Returns:
True if the line content is empty, False otherwise.
- property line_string: str¶
Get the processed line for filesystem output (ro).
The returned string includes the original line terminator only if the source line had one. This ensures that files without a trailing newline (e.g., at the end of the file) are reconstructed identically to their original or patched state.
- Returns:
The content string, optionally suffixed with a newline.
- property normalized_ws_content: str¶
The line content, dynamically normalized according to the –normalize-ws rule (ro).
Internal whitespace runs collapse to a single space; trailing whitespace is removed; leading whitespace is preserved.
- Returns:
The normalized string used for matches.
- 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 character (’ ‘, ‘+’, or ‘-’) (ro).
- Returns:
The prefix character.
- 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).