(maxcol, tol, dispchrs, dispcols, positions,
                 intervals, styles, stylemap, nowrap=False, nowrapindent=False)
return ret
Split string by column
Split string by column
Split string by column
def col_splitter(maxcol, tol, dispchrs, dispcols, positions,
                 intervals, styles, stylemap, nowrap=False, nowrapindent=False):
    """Split string by column"""

    if nowrap:
        return [Row(tol, tol, 0, 0, dispchrs, dispcols, positions, intervals)]

    assert maxcol >= 2
    rowfrom = rowto = 0
    sumcols = 0
    wrappos = None
    sumcols_at_wrappos = 0

    posfrom = tol
    colfrom = 0
    wrapindent = 0

    ret = []

    for col in dispcols:

        if not col:
            rowto += 1
            continue

        # check if nowrap
        if rowfrom < rowto:
            wrappable = True

            if rowto < len(positions):

                curpos = positions[rowto - 1]
                nextpos = positions[rowto]

                tokenid = styles[curpos - tol]
                nexttokenid = styles[nextpos - tol]

                style = stylemap.get(tokenid, None)
                if style and style.nowrap:
                    nextstyle = stylemap.get(nexttokenid)
                    if nextstyle and nextstyle.nowrap:
                        wrappable = False

            if wrappable:
                wrappos = rowto
                sumcols_at_wrappos = sumcols

        if ((sumcols + col) >= (maxcol - wrapindent)) and (rowfrom != rowto):
            # do not split at newlines
            if (rowto >= len(dispchrs)) or (dispchrs[rowto] != '\n'):

                if wrappos is None:
                    # No wrappable position found. So, fill as many chars as we
                    # can.
                    wrappos = rowto
                    sumcols_at_wrappos = sumcols

                assert rowfrom != wrappos
                row = Row(
                    posfrom, tol, colfrom, wrapindent, dispchrs[
                        rowfrom:wrappos],
                    dispcols[rowfrom:wrappos], positions[
                        rowfrom:wrappos],
                    intervals[rowfrom:wrappos])

                ret.append(row)
                colfrom += sum(dispcols[rowfrom:wrappos])

                rowfrom = wrappos
                sumcols = sumcols - sumcols_at_wrappos

                wrappos = None
                sumcols_at_wrappos = None

                posfrom = row.posto

                # set wrap-indent width after second row
                if not nowrapindent and len(ret) == 1:
                    wrapindent = re.match(r' *', dispchrs).end()
                    if wrapindent + MIN_WRAPCOLS > maxcol:
                        wrapindent = max(0, maxcol - MIN_WRAPCOLS)

        sumcols += col
        rowto += 1

    if rowfrom != len(dispcols) or not dispchrs:
        row = Row(
            posfrom, tol, colfrom, wrapindent, dispchrs[
                rowfrom:], dispcols[rowfrom:],
            positions[rowfrom:], intervals[rowfrom:])
        ret.append(row)

    return ret
def col_splitter ( maxcol , tol , dispchrs , dispcols , positions , intervals , styles , stylemap , nowrap = False , nowrapindent = False ) : if nowrap : return [ Row ( tol , tol , 0 , 0 , dispchrs , dispcols , positions , intervals ) ] assert maxcol >= 2 rowfrom = rowto = 0 sumcols = 0 wrappos = None sumcols_at_wrappos = 0 posfrom = tol colfrom = 0 wrapindent = 0 ret = [ ] for col in dispcols : if not col : rowto += 1 continue # check if nowrap if rowfrom < rowto : wrappable = True if rowto < len ( positions ) : curpos = positions [ rowto - 1 ] nextpos = positions [ rowto ] tokenid = styles [ curpos - tol ] nexttokenid = styles [ nextpos - tol ] style = stylemap . get ( tokenid , None ) if style and style . nowrap : nextstyle = stylemap . get ( nexttokenid ) if nextstyle and nextstyle . nowrap : wrappable = False if wrappable : wrappos = rowto sumcols_at_wrappos = sumcols if ( ( sumcols + col ) >= ( maxcol - wrapindent ) ) and ( rowfrom != rowto ) : # do not split at newlines if ( rowto >= len ( dispchrs ) ) or ( dispchrs [ rowto ] != '\n' ) : if wrappos is None : # No wrappable position found. So, fill as many chars as we # can. wrappos = rowto sumcols_at_wrappos = sumcols assert rowfrom != wrappos row = Row ( posfrom , tol , colfrom , wrapindent , dispchrs [ rowfrom : wrappos ] , dispcols [ rowfrom : wrappos ] , positions [ rowfrom : wrappos ] , intervals [ rowfrom : wrappos ] ) ret . append ( row ) colfrom += sum ( dispcols [ rowfrom : wrappos ] ) rowfrom = wrappos sumcols = sumcols - sumcols_at_wrappos wrappos = None sumcols_at_wrappos = None posfrom = row . posto # set wrap-indent width after second row if not nowrapindent and len ( ret ) == 1 : wrapindent = re . match ( r' *' , dispchrs ) . end ( ) if wrapindent + MIN_WRAPCOLS > maxcol : wrapindent = max ( 0 , maxcol - MIN_WRAPCOLS ) sumcols += col rowto += 1 if rowfrom != len ( dispcols ) or not dispchrs : row = Row ( posfrom , tol , colfrom , wrapindent , dispchrs [ rowfrom : ] , dispcols [ rowfrom : ] , positions [ rowfrom : ] , intervals [ rowfrom : ] ) ret . append ( row ) return ret