def split_text(text,char_limit,delims=' \t\n',strip=True,slack=False):
    """Break text into multiple lines

    Breaks supplied text into multiple lines where no line
    exceeds char_limit in length. Attempts to break text at
    positions marked by delimiters, so that (if using white
    space delimiters) words are not split.

    Arguments:
      text: text to be broken up
      char_limit: maximum length of lines to produce
      delims: optional, set of delimiter characters to
        break text on (defaults to whitespace characters)
      strip: optional, if True then trailing or leading
        delimiters are removed from lines (default)
      slack: optional, if True then allow lines to be
        longer than char_limit if not delimiter is found
        (default is to be strict)

    Returns:
      List of lines.

    """
    lines = []
    while len(text) > char_limit:
        # Locate nearest delimiter to the character limit
        line = text[:char_limit]
        while len(line) > 0:
            if line[-1] in delims:
                # Found delimiter at end of current line
                # fragment
                break
            else:
                line = line[:-1]
        # Unable to locate delimiter
        if len(line) == 0:
            if not slack:
                # Split on the character limit
                line = text[:char_limit]
            else:
                # Extend the line past the limit
                # to look for delimiter
                extent = char_limit
                while extent <= len(text):
                    line = text[:extent]
                    if line[-1] in delims:
                        break
                    else:
                        extent += 1
        # Append current line to list of lines and
        # prepare for next iteration
        text = text[len(line):]
        if strip:
            line = line.rstrip(delims)
            text = text.lstrip(delims)
        lines.append(line)
    # Append remaining text (which is less than character
    # limit)
    if strip:
        text = text.rstrip(delims)
    if text:
        lines.append(text)
    return lines