def wrap_text(text: str, max_length: int, prefix: str):
    """
    Reformat text to a line limit, breaking on spaces

    :param text: Some text with spaces in it
    :param max_length: Max line length including the indent
    :param prefix: Prefix for each line
    :return: Wrapped text
    """
    rest = text
    result = []
    max_length -= len(prefix)
    while True:
        end = rest[:max_length].rfind(' ')
        if end == -1:
            assert max_length > len(rest), "not expecting very long lines with no spaces"
            result.append(prefix + rest)
            break
        else:
            result.append(prefix + rest[:end])
            rest = rest[end+1:]
    return '\n'.join(result)