Print a simple nicely-aligned table. table must be a list of (equal-length) lists. Columns are space-separated, and as narrow as possible, but no wider than max_width. Text may overflow columns; note that unlike string.format, this will not affect subsequent columns, if possible.
(table, max_width)
| 39 | return len(re.sub(r'\033\[[\d;]+m', '', s)) |
| 40 | |
| 41 | def print_table(table, max_width): |
| 42 | """Print a simple nicely-aligned table. |
| 43 | |
| 44 | table must be a list of (equal-length) lists. Columns are space-separated, |
| 45 | and as narrow as possible, but no wider than max_width. Text may overflow |
| 46 | columns; note that unlike string.format, this will not affect subsequent |
| 47 | columns, if possible.""" |
| 48 | |
| 49 | max_widths = [max_width] * len(table[0]) |
| 50 | column_widths = [max(printed_len(row[j]) + 1 for row in table) |
| 51 | for j in range(len(table[0]))] |
| 52 | column_widths = [min(w, max_w) for w, max_w in zip(column_widths, max_widths)] |
| 53 | |
| 54 | for row in table: |
| 55 | row_str = '' |
| 56 | right_col = 0 |
| 57 | for cell, width in zip(row, column_widths): |
| 58 | right_col += width |
| 59 | row_str += cell + ' ' |
| 60 | row_str += ' ' * max(right_col - printed_len(row_str), 0) |
| 61 | print row_str |
| 62 | |
| 63 | def summarize_net(net): |
| 64 | disconnected_tops = set() |