def _textwrap_slices(text, width, strip_leading_indent=False):
    """ Nearly identical to textwrap.wrap except this routine is a tad bit
    safer in its algo that textwrap.  I ran into some issues with textwrap
    output that make it unusable to this usecase as a baseline text wrapper.
    Further this utility returns slices instead of strings.  So the slices
    can be used to extract your lines manually. """
    if not isinstance(text, str):
        raise TypeError("Expected `str` type")
    chunks = (x for x in _textwrap_word_break.split(text) if x)
    remaining = width
    buf = []
    lines = [buf]
    whitespace = []
    whitespace_len = 0
    pos = 0
    try:
        chunk = next(chunks)
    except StopIteration:
        chunk = ''
    if not strip_leading_indent and is_whitespace(chunk):
        # Add leading indent for first line, but only up to one lines worth.
        chunk_len = len(chunk)
        if chunk_len >= width:
            _add_slice(buf, slice(0, width))
            buf = []
            lines.append(buf)
        else:
            _add_slice(buf, slice(0, chunk_len))
            remaining -= chunk_len
        pos = chunk_len
        try:
            chunk = next(chunks)
        except StopIteration:
            chunk = ''
    while True:
        avail_len = remaining - whitespace_len
        chunk_len = len(chunk)
        if chunk == '\n':
            buf = []
            lines.append(buf)
            whitespace = []
            whitespace_len = 0
            remaining = width
        elif is_whitespace(chunk):
            if buf:
                _add_slice(whitespace, slice(pos, pos + chunk_len))
                whitespace_len += chunk_len
        elif len(chunk) > avail_len:
            if not buf:
                # Must hard split the chunk.
                for x in whitespace:
                    _add_slice(buf, x)
                _add_slice(buf, slice(pos, pos + avail_len))
                chunk = chunk[avail_len:]
                pos += avail_len
            # Bump to next line without fetching the next chunk.
            buf = []
            lines.append(buf)
            whitespace = []
            whitespace_len = 0
            remaining = width
            continue
        else:
            if buf:
                remaining -= whitespace_len
                for x in whitespace:
                    _add_slice(buf, x)
            whitespace = []
            whitespace_len = 0
            _add_slice(buf, slice(pos, pos + chunk_len))
            remaining -= chunk_len
        pos += chunk_len
        try:
            chunk = next(chunks)
        except StopIteration:
            break
    return lines
Nearly identical to textwrap.wrap except this routine is a tad bit
    safer in its algo that textwrap.  I ran into some issues with textwrap
    output that make it unusable to this usecase as a baseline text wrapper.
    Further this utility returns slices instead of strings.  So the slices
    can be used to extract your lines manually.