

def FormattedTable(self, width=80, force_display=False, ml_delimiter=True, color=True, display_header=True, columns=None):
    "Returns whole table, with whitespace padding and row delimiters.\n\n    Args:\n      width: An int, the max width we want the table to fit in.\n      force_display: A bool, if set to True will display table when the table\n          can't be made to fit to the width.\n      ml_delimiter: A bool, if set to False will not display the multi-line\n          delimiter.\n      color: A bool. If true, display any colours in row.colour.\n      display_header: A bool. If true, display header.\n      columns: A list of str, show only columns with these names.\n\n    Returns:\n      A string.  The tabled output.\n\n    Raises:\n      TableError: Width too narrow to display table.\n    "

    def _FilteredCols():
        'Returns list of column names to display.'
        if (not columns):
            return self._Header().values
        return [col for col in self._Header().values if (col in columns)]
    largest = {
        
    }
    smallest = {
        
    }
    for key in _FilteredCols():
        largest[key] = 0
        smallest[key] = 0
    for row in self._table:
        for (key, value) in row.items():
            if (key not in _FilteredCols()):
                continue
            if isinstance(value, list):
                value = ', '.join(value)
            value = terminal.StripAnsiText(value)
            largest[key] = max(len(value), largest[key])
            smallest[key] = max(self._SmallestColSize(value), smallest[key])
    min_total_width = 0
    multi_word = []
    for key in _FilteredCols():
        largest[key] += 2
        smallest[key] += 2
        min_total_width += smallest[key]
        if (largest[key] != smallest[key]):
            multi_word.append(key)
    if ((min_total_width > width) and (not force_display)):
        raise TableError('Width too narrow to display table.')
    if multi_word:
        desired_width = 0
        spare_width = (width - min_total_width)
        for key in multi_word:
            spare_width += smallest[key]
            desired_width += largest[key]
        done = False
        while (not done):
            done = True
            for key in multi_word:
                if (largest[key] <= round(((largest[key] / float(desired_width)) * spare_width))):
                    smallest[key] = largest[key]
                    multi_word.remove(key)
                    spare_width -= smallest[key]
                    desired_width -= largest[key]
                    done = False
                elif (smallest[key] >= round(((largest[key] / float(desired_width)) * spare_width))):
                    columns.remove(key)
                    spare_width -= smallest[key]
                    desired_width -= largest[key]
                    done = False
        for key in multi_word:
            smallest[key] = int(round(((largest[key] / float(desired_width)) * spare_width)))
    total_width = 0
    row_count = 0
    result_dict = {
        
    }
    for key in _FilteredCols():
        result_dict[key] = self._TextJustify(key, smallest[key])
        if (len(result_dict[key]) > row_count):
            row_count = len(result_dict[key])
        total_width += smallest[key]
    header_list = []
    for row_idx in xrange(row_count):
        for key in _FilteredCols():
            try:
                header_list.append(result_dict[key][row_idx])
            except IndexError:
                header_list.append((' ' * smallest[key]))
        header_list.append('\n')
    result_dict = {
        
    }
    body_list = []
    prev_muli_line = False
    first_line = True
    for row in self:
        row_count = 0
        for (key, value) in row.items():
            if (key not in _FilteredCols()):
                continue
            if isinstance(value, list):
                value = ', '.join(value)
            result_dict[key] = self._TextJustify(value, smallest[key])
            if (len(result_dict[key]) > row_count):
                row_count = len(result_dict[key])
        if (row_count > 1):
            prev_muli_line = True
        if ((not first_line) and prev_muli_line and ml_delimiter):
            body_list.append((('-' * total_width) + '\n'))
            if (row_count == 1):
                prev_muli_line = False
        row_list = []
        for row_idx in xrange(row_count):
            for key in _FilteredCols():
                try:
                    row_list.append(result_dict[key][row_idx])
                except IndexError:
                    row_list.append((' ' * smallest[key]))
            row_list.append('\n')
        if (color and (row.color is not None)):
            body_list.append(terminal.AnsiText(''.join(row_list)[:(- 1)], command_list=row.color))
            body_list.append('\n')
        else:
            body_list.append(''.join(row_list))
        first_line = False
    header = (''.join(header_list) + ('=' * total_width))
    if (color and (self._Header().color is not None)):
        header = terminal.AnsiText(header, command_list=self._Header().color)
    if display_header:
        return ('%s\n%s' % (header, ''.join(body_list)))
    return ('%s' % ''.join(body_list))

dataset/ETHPy150Open google/textfsm/texttable.py TextTable.FormattedTable/VarMisuse@474/899 `multi_word`->`columns`