def split_line(what, indent='', cols=79):
    """Split a line on the closest space, or break the last word with '-'.

    Args:
        what(str): text to spli one line of.
        indent(str): will prepend this indent to the split line, taking it into
        account in the column count.
        cols(int): maximum length of the split line.

    Returns:
        tuple(str, str): rest of the text and split line in that order.

    Raises:
        ValueError: when the indent is greater than the indent, or the cols
        param is too small
    """
    if len(indent) > cols:
        raise ValueError("The indent can't be longer than cols.")

    if cols < 2:
        raise ValueError(
            "The cols can't be smaller than 2 (a char plus a possible '-')"
        )

    what = indent + what.lstrip()

    if len(what) <= cols:
        what, new_line = '', what
    else:
        try:
            closest_space = what[:cols].rindex(' ')
        except ValueError:
            closest_space = -1

        if closest_space > len(indent):
            what, new_line = (
                what[closest_space:],
                what[:closest_space],
            )
        elif what[cols] == ' ':
            what, new_line = (
                what[cols:],
                what[:cols],
            )
        else:
            what, new_line = what[cols - 1:], what[:cols - 1] + '-'

    return what.lstrip(), new_line.rstrip()
def split_line ( what , indent = '' , cols = 79 ) : if len ( indent ) > cols : raise ValueError ( "The indent can't be longer than cols." ) if cols < 2 : raise ValueError ( "The cols can't be smaller than 2 (a char plus a possible '-')" ) what = indent + what . lstrip ( ) if len ( what ) <= cols : what , new_line = '' , what else : try : closest_space = what [ : cols ] . rindex ( ' ' ) except ValueError : closest_space = - 1 if closest_space > len ( indent ) : what , new_line = ( what [ closest_space : ] , what [ : closest_space ] , ) elif what [ cols ] == ' ' : what , new_line = ( what [ cols : ] , what [ : cols ] , ) else : what , new_line = what [ cols - 1 : ] , what [ : cols - 1 ] + '-' return what . lstrip ( ) , new_line . rstrip ( )
Split a line on the closest space, or break the last word with '-'.

    Args:
        what(str): text to spli one line of.
        indent(str): will prepend this indent to the split line, taking it into
        account in the column count.
        cols(int): maximum length of the split line.

    Returns:
        tuple(str, str): rest of the text and split line in that order.

    Raises:
        ValueError: when the indent is greater than the indent, or the cols
        param is too small