예제 #1
0
    def _str_vertical(self):
        output = []

        title_width = sum(self._render_column_widths) + 1  # 1 for ":"
        title_width += len(self._column_padding) * (len(self._render_column_widths) - 1)
        output = [terminal.bold()]
        output.append(self._title.center(title_width, "~"))
        output.append(terminal.reset())
        output = ["".join(output)]
        output.extend(self.genDescription(title_width, title_width - 10))

        for i, column_name in enumerate(self._render_column_names):
            row = []
            row.append(terminal.style(terminal.bg_clear, terminal.fg_clear))

            column_title = column_name
            if column_name == "NODE":
                row.append(terminal.bold())
            row.append(column_title.ljust(self._render_column_widths[0]))
            row.append(":")
            row.append(self._column_padding)
            for j, (cell_format, cell) in enumerate((raw_data[i] for raw_data in self._data), 1):
                cell = cell.ljust(self._render_column_widths[j])
                row.append("%s%s" % (cell_format(), cell))
                row.append(self._column_padding)

            if column_name == "NODE":
                row.append(terminal.reset())
            output.append("".join(row))

        return "\n".join(output) + "\n"
예제 #2
0
    def _str_horizontal(self):
        output = []
        output.append(self._getHorizontalHeader())
        for drow in self._data:
            row = []
            for i, (cell_format, cell) in enumerate(drow):
                row.append(terminal.style(terminal.bg_clear, terminal.fg_clear))
                if i not in self._render_column_ids:
                    continue

                i = self._render_remap[i]

                column_name = self._render_column_names[i]

                if self._column_types[i] == "number":
                    cell = cell.rjust(self._render_column_widths[i])
                elif self._column_types[i] == "string":
                    cell = cell.ljust(self._render_column_widths[i])
                else:
                    raise ValueError("Unknown column type: '%s'" % self._render_column_types[i])

                row.append("%s%s" % (cell_format(), cell))
                row.append(self._column_padding)

            output.append("".join(row))
        output.append("Number of rows: %s" % (len(self._data)))
        return "\n".join(output) + "\n"