##// END OF EJS Templates
rename num_rows etc to max_rows for clarity...
naught101 -
Show More
@@ -618,28 +618,28 b' class DollarFormatter(FullEvalFormatter):'
618 618 # Utils to columnize a list of string
619 619 #-----------------------------------------------------------------------------
620 620
621 def _col_chunks(l, nrows, row_first=False):
622 """Yield successive nrows-sized column chunks from l."""
621 def _col_chunks(l, max_rows, row_first=False):
622 """Yield successive max_rows-sized column chunks from l."""
623 623 if row_first:
624 ncols = (len(l) // nrows) + (len(l) % nrows > 0)
624 ncols = (len(l) // max_rows) + (len(l) % max_rows > 0)
625 625 for i in py3compat.xrange(ncols):
626 626 yield [l[j] for j in py3compat.xrange(i, len(l), ncols)]
627 627 else:
628 for i in py3compat.xrange(0, len(l), nrows):
629 yield l[i:(i + nrows)]
628 for i in py3compat.xrange(0, len(l), max_rows):
629 yield l[i:(i + max_rows)]
630 630
631 631
632 632 def _find_optimal(rlist, row_first=False, separator_size=2, displaywidth=80):
633 633 """Calculate optimal info to columnize a list of string"""
634 for nrow in range(1, len(rlist) + 1):
635 col_widths = list(map(max, _col_chunks(rlist, nrow, row_first)))
634 for max_rows in range(1, len(rlist) + 1):
635 col_widths = list(map(max, _col_chunks(rlist, max_rows, row_first)))
636 636 sumlength = sum(col_widths)
637 637 ncols = len(col_widths)
638 638 if sumlength + separator_size * (ncols - 1) <= displaywidth:
639 639 break
640 640 return {'num_columns': ncols,
641 641 'optimal_separator_width': (displaywidth - sumlength) / (ncols - 1) if (ncols - 1) else 0,
642 'num_rows': nrow,
642 'max_rows': max_rows,
643 643 'column_widths': col_widths
644 644 }
645 645
@@ -685,8 +685,8 b' def compute_item_matrix(items, row_first=False, empty=None, *args, **kwargs) :'
685 685
686 686 num_columns
687 687 number of columns
688 num_rows
689 number of rows
688 max_rows
689 maximum number of rows (final number may be less)
690 690 column_widths
691 691 list of with of each columns
692 692 optimal_separator_width
@@ -707,10 +707,10 b' def compute_item_matrix(items, row_first=False, empty=None, *args, **kwargs) :'
707 707 {'num_columns': 3,
708 708 'column_widths': [5, 1, 1],
709 709 'optimal_separator_width': 2,
710 'num_rows': 5})
710 'max_rows': 5})
711 711 """
712 712 info = _find_optimal(list(map(len, items)), row_first, *args, **kwargs)
713 nrow, ncol = info['num_rows'], info['num_columns']
713 nrow, ncol = info['max_rows'], info['num_columns']
714 714 if row_first:
715 715 return ([[_get_or_default(items, r * ncol + c, default=empty) for c in range(ncol)] for r in range(nrow)], info)
716 716 else:
General Comments 0
You need to be logged in to leave comments. Login now