(
    line_content: str,
    secret_index_start: int,
    secret_index_end: int,
    max_width: Optional[int] = None,
)
return formatted_line, (secret_display_index_start, secret_display_index_end)
Format a line containing a secret.
    :param line_content: the whole line, as a string
    :param secret_index_start: the index in the line, as an integer, where the secret
    starts
    :param secret_index_end: the index in the line, as an integer, where the secret
    ends
    :param max_width: if set, context will be clipped if needed
    :return The formatted detector as a string, and the position (start and end index)
    of the secret in it.
Format a line containing a secret.
    :param line_content: the whole line, as a string
    :param secret_index_start: the index in the line, as an integer, where the secret
    starts
    :param secret_index_end: the index in the line, as an integer, where the secret
    ends
    :param max_width: if set, context will be clipped if needed
    :return The formatted detector as a string, and the position (start and end index)
    of the secret in it.
Format a line containing a secret . : param line_content : the whole line as a string : param secret_index_start : the index in the line as an integer where the secret starts : param secret_index_end : the index in the line as an integer where the secret ends : param max_width : if set context will be clipped if needed : return The formatted detector as a string and the position ( start and end index ) of the secret in it .
def format_line_with_secret(
    line_content: str,
    secret_index_start: int,
    secret_index_end: int,
    max_width: Optional[int] = None,
) -> Tuple[str, Tuple[int, int]]:
    """
    Format a line containing a secret.
    :param line_content: the whole line, as a string
    :param secret_index_start: the index in the line, as an integer, where the secret
    starts
    :param secret_index_end: the index in the line, as an integer, where the secret
    ends
    :param max_width: if set, context will be clipped if needed
    :return The formatted detector as a string, and the position (start and end index)
    of the secret in it.
    """
    context_before = line_content[:secret_index_start]
    secret = line_content[secret_index_start:secret_index_end]
    context_after = line_content[secret_index_end:]
    secret_length = len(secret)

    # Clip the context if it is too long
    if max_width:
        context_max_length = max_width - secret_length
        if len(context_before) + len(context_after) > context_max_length:
            # Both before and after context are too long, cut them to the same size
            if (
                len(context_before) > context_max_length // 2
                and len(context_after) > context_max_length // 2
            ):
                context_before = clip_long_line(
                    context_before, context_max_length // 2, before=True
                )
                context_after = clip_long_line(
                    context_after, context_max_length // 2, after=True
                )
            # Only the before context is too long, clip it but use the maximum space
            # available
            elif len(context_before) > context_max_length // 2:
                context_before = clip_long_line(
                    context_before, context_max_length - len(context_after), before=True
                )
            # Only the after context is too long, same idea
            elif len(context_after) > context_max_length // 2:
                context_after = clip_long_line(
                    context_after, context_max_length - len(context_before), after=True
                )

    formatted_line = (
        (display_patch(context_before) if context_before else "")
        + display_match_value(secret)
        + (display_patch(context_after) if context_after else "")
        + "\n"
    )

    secret_display_index_start = len(context_before)
    secret_display_index_end = secret_display_index_start + secret_length
    return formatted_line, (secret_display_index_start, secret_display_index_end)
def format_line_with_secret ( line_content : str , secret_index_start : int , secret_index_end : int , max_width : Optional [ int ] = None , ) -> Tuple [ str , Tuple [ int , int ] ] : context_before = line_content [ : secret_index_start ] secret = line_content [ secret_index_start : secret_index_end ] context_after = line_content [ secret_index_end : ] secret_length = len ( secret ) # Clip the context if it is too long if max_width : context_max_length = max_width - secret_length if len ( context_before ) + len ( context_after ) > context_max_length : # Both before and after context are too long, cut them to the same size if ( len ( context_before ) > context_max_length // 2 and len ( context_after ) > context_max_length // 2 ) : context_before = clip_long_line ( context_before , context_max_length // 2 , before = True ) context_after = clip_long_line ( context_after , context_max_length // 2 , after = True ) # Only the before context is too long, clip it but use the maximum space # available elif len ( context_before ) > context_max_length // 2 : context_before = clip_long_line ( context_before , context_max_length - len ( context_after ) , before = True ) # Only the after context is too long, same idea elif len ( context_after ) > context_max_length // 2 : context_after = clip_long_line ( context_after , context_max_length - len ( context_before ) , after = True ) formatted_line = ( ( display_patch ( context_before ) if context_before else "" ) + display_match_value ( secret ) + ( display_patch ( context_after ) if context_after else "" ) + "\n" ) secret_display_index_start = len ( context_before ) secret_display_index_end = secret_display_index_start + secret_length return formatted_line , ( secret_display_index_start , secret_display_index_end )