From dd27a1e5ab40e5e9fbcdb2e4f38f5e12b68dfa41 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Mon, 17 Oct 2011 19:59:16 +0200 Subject: [PATCH] client-barcode: Handle long labels better --- client-barcode/freitagskasse.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index ae4886e..a9b8964 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -108,9 +108,15 @@ class Status: % ('', '', color(balance), sign(balance, plus), 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): 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)) def show_bar():