diff options
author | Mattias Andrée <maandree@operamail.com> | 2012-08-23 03:01:15 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2012-08-23 03:01:15 +0200 |
commit | 89951de30b932bd08d6680018dc4459f1927d1e2 (patch) | |
tree | 159e2c6dc20573fce63e6cacee88c500b6f2210b /ponysay | |
parent | 5838fa1def97b60bce62fc27669e4cb94508b9ff (diff) | |
download | ponysay-89951de30b932bd08d6680018dc4459f1927d1e2.tar.gz ponysay-89951de30b932bd08d6680018dc4459f1927d1e2.tar.bz2 ponysay-89951de30b932bd08d6680018dc4459f1927d1e2.zip |
better columnisation
Diffstat (limited to 'ponysay')
-rwxr-xr-x | ponysay | 28 |
1 files changed, 21 insertions, 7 deletions
@@ -284,22 +284,36 @@ class Ponysay(): cols = termwidth // width rows = (len(ponies) + cols - 1) // cols - lines = [] - for r in range(0, rows): lines.append([]) - - if cols == 0: - print('\n'.join(ponies)) - return + columns = [] + for c in range(0, cols): columns.append([]) (y, x) = (0, 0) for j in range(0, len(ponies)): cell = ponies[j][1] + ' ' * (width - widths[j]); - lines[y].append(cell) + columns[x].append(cell) y += 1 if y == rows: x += 1 y = 0 + diff = rows * cols - len(ponies) + if diff > 2: + c = cols - 1 + diff -= 1 + while diff > 0: + columns[c] = columns[c - 1][-diff:] + columns[c] + c -= 1 + columns[c] = columns[c][:-diff] + diff -= 1 + pass + + lines = [] + for r in range(0, rows): + lines.append([]) + for c in range(0, cols): + if r < len(columns[c]): + line = lines[r].append(columns[c][r]) + print('\n'.join([''.join(line)[:-2] for line in lines])); print() |