Further fixes to format_grid

This commit is contained in:
Griatch 2020-04-11 11:37:30 +02:00
parent c9cab183f5
commit a863ff77db

View file

@ -1746,18 +1746,13 @@ def format_grid(elements, width=78, sep=" "):
wl = wls[ie] wl = wls[ie]
lrow = len(row) lrow = len(row)
debug = row.replace(" ", ".") debug = row.replace(" ", ".")
# from evennia import set_trace;set_trace()
if ie >= nelements - 1: if lrow + wl > width:
# last element in list - make sure to add it # last slot extends outside grid, move to next line
if lrow + wl > width: row += " " * (width - lrow)
# last slot extends outside grid, move to next line
row += " " * (width - lrow)
rows.append(row)
row = crop(element, width)
else:
row += crop(element, width)
row += " " * max(0, (width - len(row)))
rows.append(row) rows.append(row)
row = crop(element, width)
ic = 0
elif ic >= aver_per_row - 1: elif ic >= aver_per_row - 1:
# last slot on the line # last slot on the line
if ic == 0: if ic == 0:
@ -1796,6 +1791,10 @@ def format_grid(elements, width=78, sep=" "):
row += element + " " * max(0, averlen - wl) row += element + " " * max(0, averlen - wl)
ic += 1 ic += 1
if ie >= nelements - 1:
# last element, make sure to store
rows.append(row)
return "\n".join(rows) return "\n".join(rows)