def addStringToColumn(columns, width, s, columnSeparators): while True: columns[-1].append("") if color.lenNoCodes(s) == 0: break colorOffset = 0 while True: newOffset = len(s[:width + colorOffset]) - color.lenNoCodes( s[:width + colorOffset]) if newOffset == colorOffset: break colorOffset = newOffset toAdd = s[:width + colorOffset] + "{@" assert color.lenNoCodes(toAdd) <= width, toAdd while (color.lenNoCodes(toAdd) < width + SPACES_BETWEEN_COLUMNS): toAdd += " " if columnSeparators: toAdd = toAdd[:-2] + COLUMN_SEPARATOR + " " columns[-1][-1] += toAdd colorState = color.getColorState(s[:width]) s = s[width + colorOffset:] if color.lenNoCodes(s) == 0: break s = str(colorState) + s
def addStringToColumn( columns, width, s, columnSeparators ): while True: columns[-1].append("") if color.lenNoCodes(s) == 0: break colorOffset = 0 while True: newOffset = len(s[:width + colorOffset]) - color.lenNoCodes(s[:width + colorOffset]) if newOffset == colorOffset: break colorOffset = newOffset toAdd = s[:width+colorOffset] + "{@" assert color.lenNoCodes(toAdd) <= width, toAdd while( color.lenNoCodes(toAdd) < width + SPACES_BETWEEN_COLUMNS ): toAdd += " " if columnSeparators: toAdd = toAdd[:-2] + COLUMN_SEPARATOR + " " columns[-1][-1] += toAdd colorState = color.getColorState(s[:width]) s = s[width + colorOffset:] if color.lenNoCodes(s) == 0: break s = str(colorState) + s
def render(col, emptyLine): if len(col) > 0: #print "len col > 0 : %s " % col line = col.pop(0) if (color.lenNoCodes(line) > 0): return line return emptyLine
def render( col, emptyLine ): if len(col) > 0: #print "len col > 0 : %s " % col line = col.pop(0) if ( color.lenNoCodes(line) > 0 ): return line return emptyLine
def getEmptyColumnLine( width, columnSeparators ): EMPTY_COLUMN_LINE = "{@" while( color.lenNoCodes(EMPTY_COLUMN_LINE) < width + SPACES_BETWEEN_COLUMNS ): EMPTY_COLUMN_LINE += " " if columnSeparators: EMPTY_COLUMN_LINE = EMPTY_COLUMN_LINE[:-2] + COLUMN_SEPARATOR + " " return EMPTY_COLUMN_LINE
def getEmptyColumnLine(width, columnSeparators): EMPTY_COLUMN_LINE = "{@" while (color.lenNoCodes(EMPTY_COLUMN_LINE) < width + SPACES_BETWEEN_COLUMNS): EMPTY_COLUMN_LINE += " " if columnSeparators: EMPTY_COLUMN_LINE = EMPTY_COLUMN_LINE[:-2] + COLUMN_SEPARATOR + " " return EMPTY_COLUMN_LINE
def columnsFromStrings( strs, widths, columnSeparators ): columns = [] for s in strs: isStr(s) columns.append([]) width = widths.pop(0) while( color.lenNoCodes(s) > 0 ): newlineIndex = s.find("\r\n") if newlineIndex < 0: addStringToColumn( columns, width, s, columnSeparators ) break addStringToColumn( columns, width, s[:newlineIndex ], columnSeparators ) colorState = color.getColorState(s[:newlineIndex]) s = str(colorState) + s[newlineIndex + 2:] return columns
def columnsFromStrings(strs, widths, columnSeparators): columns = [] for s in strs: isStr(s) columns.append([]) width = widths.pop(0) while (color.lenNoCodes(s) > 0): newlineIndex = s.find("\r\n") if newlineIndex < 0: addStringToColumn(columns, width, s, columnSeparators) break addStringToColumn(columns, width, s[:newlineIndex], columnSeparators) colorState = color.getColorState(s[:newlineIndex]) s = str(colorState) + s[newlineIndex + 2:] return columns