[weboob] [PATCH 3/3] boobank: print text in red when balance < 0 or when balance - coming < 0

Laurent Dufrechou laurent.dufrechou at gmail.com
Tue Apr 5 00:43:43 CEST 2011


Signed-off-by: Laurent Dufrechou <laurent.dufrechou at gmail.com>
---
 weboob/applications/boobank/boobank.py |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/weboob/applications/boobank/boobank.py b/weboob/applications/boobank/boobank.py
index b040b8b..eb7bb44 100644
--- a/weboob/applications/boobank/boobank.py
+++ b/weboob/applications/boobank/boobank.py
@@ -66,11 +66,24 @@ class AccountListFormatter(IFormatter):
         else:
             id = item['id']
 
+        end_color = '\x1B[0m'
+
+        if float(item['balance']) < 0:
+                balance_color = "\x1B[1;31m"
+        else:
+                balance_color = "\x1B[0m"
+
+        if float(item['balance']) - float(item['coming'] or 0.0) < 0:
+                coming_color = "\x1B[1;31m"
+        else:
+                coming_color = "\x1B[0m"
+
         result = u''
         if self.count == 1:
             result += '               %s  Account                     Balance    Coming \n' % ((' ' * 15) if not self.interactive else '')
             result += '------------------------------------------%s+----------+----------\n' % (('-' * 15) if not self.interactive else '')
-        result += (u' %s%-' + (u'15' if self.interactive else '30') + u's%s %-25s  %8s   %8s') % \
+        result += (u' %s%-' + (u'15' if self.interactive else '30') + u's%s %-25s  '+balance_color+"%8s"+end_color+"   "\
+                       +coming_color+'%8s'+end_color) % \
                              (self.BOLD, id, self.NC,
                               item['label'], '%.2f' % item['balance'], '%.2f' % (item['coming'] or 0.0))
 
-- 
1.7.4.msysgit.0

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0003-boobank-print-text-in-red-when-balance-0-or-when-bal.patch
Type: application/octet-stream
Size: 1910 bytes
Desc: not available
URL: <http://lists.symlink.me/pipermail/weboob/attachments/20110404/b3dde2bf/attachment.obj>


More information about the weboob mailing list