(
    flat_matches_dict: Dict[int, List[Match]],
    lines: List[Line],
    padding: int,
    offset: int,
    nb_lines: int,
    clip_long_lines: bool = False,
)
return leak_msg.getvalue()
Display leak message of an incident with location in content.

    :param lines: The lines list
    :param line_index: The last index in the line
    :param detector_line: The list of detectors object in the line
    :param padding: The line padding
    :param offset: The offset due to the line display
Display leak message of an incident with location in content.
Display leak message of an incident with location in content .
def leak_message_located(
    flat_matches_dict: Dict[int, List[Match]],
    lines: List[Line],
    padding: int,
    offset: int,
    nb_lines: int,
    clip_long_lines: bool = False,
) -> str:
    """
    Display leak message of an incident with location in content.

    :param lines: The lines list
    :param line_index: The last index in the line
    :param detector_line: The list of detectors object in the line
    :param padding: The line padding
    :param offset: The offset due to the line display
    """
    leak_msg = StringIO()
    max_width = shutil.get_terminal_size()[0] - offset if clip_long_lines else 0

    lines_to_display = get_lines_to_display(flat_matches_dict, lines, nb_lines)

    old_line_number: Optional[int] = None
    for line_number in sorted(lines_to_display):
        multiline_end = None
        line = lines[line_number]
        line_content = line.content

        if old_line_number is not None and line_number - old_line_number != 1:
            leak_msg.write(format_line_count_break(padding))

        # The current line number matches a found secret
        if line_number in flat_matches_dict:
            for flat_match in sorted(
                flat_matches_dict[line_number],
                key=lambda x: x.index_start,  # type: ignore
            ):
                is_multiline = flat_match.line_start != flat_match.line_end

                if is_multiline:
                    detector_position = float("inf"), float("-inf")

                    # Iterate on the different (and consecutive) lines of the secret
                    for match_line_index, match_line in enumerate(
                        flat_match.match.splitlines(False)
                    ):
                        multiline_line_number = line_number + match_line_index
                        leak_msg.write(
                            lines[multiline_line_number].build_line_count(
                                padding, is_secret=True
                            )
                        )

                        if match_line_index == 0:
                            # The first line of the secret may contain something else
                            # before
                            formatted_line, secret_position = format_line_with_secret(
                                line_content,
                                flat_match.index_start,
                                len(line_content),
                                max_width,
                            )
                        elif multiline_line_number == flat_match.line_end:
                            # The last line of the secret may contain something else
                            # after
                            last_line_content = lines[flat_match.line_end].content
                            formatted_line, secret_position = format_line_with_secret(
                                last_line_content, 0, len(match_line), max_width
                            )
                            multiline_end = multiline_line_number
                        else:
                            # All the other lines have nothing else but a part of the
                            # secret in them
                            formatted_line, secret_position = format_line_with_secret(
                                match_line, 0, len(match_line), max_width
                            )
                        leak_msg.write(formatted_line)

                        detector_position = (
                            min(detector_position[0], secret_position[0]),
                            max(detector_position[1], secret_position[1]),
                        )

                else:
                    leak_msg.write(line.build_line_count(padding, is_secret=True))
                    formatted_line, detector_position = format_line_with_secret(
                        line_content,
                        flat_match.index_start,
                        flat_match.index_end,
                        max_width,
                    )
                    leak_msg.write(formatted_line)

                detector_position = int(detector_position[0]), int(detector_position[1])
                detector = format_detector(flat_match.match_type, *detector_position)
                leak_msg.write(display_detector(detector, offset))

        # The current line is just here for context
        else:
            leak_msg.write(line.build_line_count(padding, is_secret=False))
            if clip_long_lines:
                line_content = clip_long_line(line_content, max_width, after=True)
            leak_msg.write(f"{display_patch(line_content)}\n")

        old_line_number = multiline_end if multiline_end else line_number

    return leak_msg.getvalue()
def leak_message_located ( flat_matches_dict : Dict [ int , List [ Match ] ] , lines : List [ Line ] , padding : int , offset : int , nb_lines : int , clip_long_lines : bool = False , ) -> str : leak_msg = StringIO ( ) max_width = shutil . get_terminal_size ( ) [ 0 ] - offset if clip_long_lines else 0 lines_to_display = get_lines_to_display ( flat_matches_dict , lines , nb_lines ) old_line_number : Optional [ int ] = None for line_number in sorted ( lines_to_display ) : multiline_end = None line = lines [ line_number ] line_content = line . content if old_line_number is not None and line_number - old_line_number != 1 : leak_msg . write ( format_line_count_break ( padding ) ) # The current line number matches a found secret if line_number in flat_matches_dict : for flat_match in sorted ( flat_matches_dict [ line_number ] , key = lambda x : x . index_start , # type: ignore ) : is_multiline = flat_match . line_start != flat_match . line_end if is_multiline : detector_position = float ( "inf" ) , float ( "-inf" ) # Iterate on the different (and consecutive) lines of the secret for match_line_index , match_line in enumerate ( flat_match . match . splitlines ( False ) ) : multiline_line_number = line_number + match_line_index leak_msg . write ( lines [ multiline_line_number ] . build_line_count ( padding , is_secret = True ) ) if match_line_index == 0 : # The first line of the secret may contain something else # before formatted_line , secret_position = format_line_with_secret ( line_content , flat_match . index_start , len ( line_content ) , max_width , ) elif multiline_line_number == flat_match . line_end : # The last line of the secret may contain something else # after last_line_content = lines [ flat_match . line_end ] . content formatted_line , secret_position = format_line_with_secret ( last_line_content , 0 , len ( match_line ) , max_width ) multiline_end = multiline_line_number else : # All the other lines have nothing else but a part of the # secret in them formatted_line , secret_position = format_line_with_secret ( match_line , 0 , len ( match_line ) , max_width ) leak_msg . write ( formatted_line ) detector_position = ( min ( detector_position [ 0 ] , secret_position [ 0 ] ) , max ( detector_position [ 1 ] , secret_position [ 1 ] ) , ) else : leak_msg . write ( line . build_line_count ( padding , is_secret = True ) ) formatted_line , detector_position = format_line_with_secret ( line_content , flat_match . index_start , flat_match . index_end , max_width , ) leak_msg . write ( formatted_line ) detector_position = int ( detector_position [ 0 ] ) , int ( detector_position [ 1 ] ) detector = format_detector ( flat_match . match_type , * detector_position ) leak_msg . write ( display_detector ( detector , offset ) ) # The current line is just here for context else : leak_msg . write ( line . build_line_count ( padding , is_secret = False ) ) if clip_long_lines : line_content = clip_long_line ( line_content , max_width , after = True ) leak_msg . write ( f"{display_patch(line_content)}\n" ) old_line_number = multiline_end if multiline_end else line_number return leak_msg . getvalue ( )