mirror of
https://github.com/erkin/ponysay.git
synced 2025-03-16 16:40:02 +01:00
better columnisation
This commit is contained in:
parent
5838fa1def
commit
89951de30b
1 changed files with 21 additions and 7 deletions
28
ponysay
28
ponysay
|
@ -284,22 +284,36 @@ class Ponysay():
|
||||||
|
|
||||||
cols = termwidth // width
|
cols = termwidth // width
|
||||||
rows = (len(ponies) + cols - 1) // cols
|
rows = (len(ponies) + cols - 1) // cols
|
||||||
lines = []
|
columns = []
|
||||||
for r in range(0, rows): lines.append([])
|
for c in range(0, cols): columns.append([])
|
||||||
|
|
||||||
if cols == 0:
|
|
||||||
print('\n'.join(ponies))
|
|
||||||
return
|
|
||||||
|
|
||||||
(y, x) = (0, 0)
|
(y, x) = (0, 0)
|
||||||
for j in range(0, len(ponies)):
|
for j in range(0, len(ponies)):
|
||||||
cell = ponies[j][1] + ' ' * (width - widths[j]);
|
cell = ponies[j][1] + ' ' * (width - widths[j]);
|
||||||
lines[y].append(cell)
|
columns[x].append(cell)
|
||||||
y += 1
|
y += 1
|
||||||
if y == rows:
|
if y == rows:
|
||||||
x += 1
|
x += 1
|
||||||
y = 0
|
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('\n'.join([''.join(line)[:-2] for line in lines]));
|
||||||
print()
|
print()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue