client-barcode: Handle long labels better

This commit is contained in:
Sebastian Pipping 2011-10-17 19:59:16 +02:00
parent 7a70f06bbb
commit dd27a1e5ab
1 changed files with 7 additions and 1 deletions

View File

@ -108,9 +108,15 @@ class Status:
% ('', '', color(balance), sign(balance, plus), % ('', '', color(balance), sign(balance, plus),
abs(balance), COLOR_RESET)) abs(balance), COLOR_RESET))
def shorten(text, length):
if len(text) <= length:
return text
else:
return text[:length - 3] + '...'
def show_item(position, diff, label, color): def show_item(position, diff, label, color):
print('%2d) %-40s %s%c %6.2f Euro%s' \ print('%2d) %-40s %s%c %6.2f Euro%s' \
% (position, label, color, sign(diff), % (position, shorten(label, 40), color, sign(diff),
abs(diff), COLOR_RESET)) abs(diff), COLOR_RESET))
def show_bar(): def show_bar():