import textwrap


def _print_indented_block(text, indent=0, text_width=80):
    """
    Formats the block of text by wrapping it to the desired width and indenting it
    by inserting the desired number of spaces.

    Parameters
    ----------
    text: str
        Text to format
    indent: int
        The number of spaces to insert at the beginning of each line.
    text_width: int
        The maximum width of the text block including the leading spaces.

    Returns
    -------
    str
        The string that contains the formatted block.
    """
    text = textwrap.wrap(text.strip(), width=text_width - indent)
    text = "\n".join(text)
    if text and (text[-1] != "\n"):
        text += "\n"
    return textwrap.indent(text, " " * indent)