Add first bits of color
This commit is contained in:
parent
6b726137b8
commit
a3521100b6
|
@ -8,6 +8,10 @@ from __future__ import print_function
|
||||||
import freitagslib.network as net
|
import freitagslib.network as net
|
||||||
from freitagslib.commands import BuyCommand, DepositCommand
|
from freitagslib.commands import BuyCommand, DepositCommand
|
||||||
|
|
||||||
|
import colorama
|
||||||
|
from colorama import Fore, Style
|
||||||
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
import os
|
import os
|
||||||
|
@ -15,6 +19,17 @@ import time
|
||||||
import urllib2
|
import urllib2
|
||||||
|
|
||||||
|
|
||||||
|
COLOR_WARN = Fore.YELLOW
|
||||||
|
COLOR_ERROR = Fore.RED
|
||||||
|
COLOR_DEPOSIT = Fore.GREEN + Style.BRIGHT
|
||||||
|
COLOR_WITHDRAW = Fore.RED + Style.BRIGHT
|
||||||
|
|
||||||
|
COLOR_SOME = Fore.WHITE + Style.BRIGHT
|
||||||
|
COLOR_MUCH = Fore.YELLOW + Style.BRIGHT
|
||||||
|
|
||||||
|
COLOR_RESET = Style.RESET_ALL
|
||||||
|
|
||||||
|
|
||||||
def clear():
|
def clear():
|
||||||
os.system('clear')
|
os.system('clear')
|
||||||
|
|
||||||
|
@ -49,7 +64,7 @@ def warn_balance():
|
||||||
|
|
||||||
def error_page(message):
|
def error_page(message):
|
||||||
clear()
|
clear()
|
||||||
print(message)
|
print(COLOR_ERROR + message + COLOR_RESET)
|
||||||
print()
|
print()
|
||||||
delay('Weiter', 3)
|
delay('Weiter', 3)
|
||||||
|
|
||||||
|
@ -66,32 +81,52 @@ class Status:
|
||||||
self.transfers = None
|
self.transfers = None
|
||||||
|
|
||||||
def dump(self):
|
def dump(self):
|
||||||
|
def sign(amount, plus='+'):
|
||||||
|
return '-' if amount < 0 else plus
|
||||||
|
|
||||||
|
def color(amount):
|
||||||
|
return COLOR_WITHDRAW if amount < 0 else COLOR_DEPOSIT
|
||||||
|
|
||||||
|
def show_total(balance, plus=' '):
|
||||||
|
print('%3s %-40s %s%c %6.2f Euro%s' \
|
||||||
|
% ('', '', color(balance), sign(balance, plus),
|
||||||
|
abs(balance), COLOR_RESET))
|
||||||
|
|
||||||
|
def show_item(position, command):
|
||||||
|
diff = command.difference()
|
||||||
|
label = command.label()
|
||||||
|
print('%2d) %-40s %s%c %6.2f Euro%s' \
|
||||||
|
% (position, label, color(diff), sign(diff),
|
||||||
|
abs(diff), COLOR_RESET))
|
||||||
|
|
||||||
|
def show_bar():
|
||||||
|
print('%3s %-40s %13s' % ('', '', '============='))
|
||||||
|
|
||||||
if self.logged_in():
|
if self.logged_in():
|
||||||
print('Eingeloggt als: %s' % (self.login_name))
|
print('Eingeloggt als: %s%s%s' % (COLOR_SOME, self.login_name, COLOR_RESET))
|
||||||
print()
|
print()
|
||||||
if self.transfers:
|
if self.transfers:
|
||||||
print('Geplante Änderungen:')
|
|
||||||
initial_command, initial_balance = self.transfers[0]
|
initial_command, initial_balance = self.transfers[0]
|
||||||
print(('%3s %-40s %c %6.2f Euro') % ('', '', ' ' if initial_balance > 0 else '-', abs(initial_balance)))
|
|
||||||
|
print('Geplante Änderungen:')
|
||||||
|
show_total(initial_balance)
|
||||||
for i, (command, balance_backup) in enumerate(self.transfers):
|
for i, (command, balance_backup) in enumerate(self.transfers):
|
||||||
difference = command.difference()
|
show_item(i + 1, command)
|
||||||
label = command.label()
|
show_bar()
|
||||||
print(('%2d) %-40s %c %6.2f Euro') % (i + 1, label, '+' if difference > 0 else '-', abs(difference)))
|
show_total(self.balance)
|
||||||
print(('%3s %-40s %8s') % ('', '', '============='))
|
|
||||||
print(('%3s %-40s %c %6.2f Euro') % ('', '', ' ' if self.balance > 0 else '-', abs(self.balance)))
|
|
||||||
|
|
||||||
if self.balance < 0:
|
if self.balance < 0:
|
||||||
warn_balance()
|
warn_balance()
|
||||||
print()
|
print()
|
||||||
|
|
||||||
print('Committen nicht vergessen.')
|
print(COLOR_SOME + 'Committen nicht vergessen.' + COLOR_RESET)
|
||||||
else:
|
else:
|
||||||
print('Kontostand beträgt: %.2f Euro' % (self.balance))
|
print('Kontostand beträgt: %s%.2f Euro%s' % (COLOR_MUCH, self.balance, COLOR_RESET))
|
||||||
if self.balance < 0:
|
if self.balance < 0:
|
||||||
print()
|
print()
|
||||||
warn_balance()
|
warn_balance()
|
||||||
else:
|
else:
|
||||||
print('Bitte einloggen.')
|
print(COLOR_MUCH + 'Bitte einloggen.' + COLOR_RESET)
|
||||||
print()
|
print()
|
||||||
print('Scanne dazu deine ID-Karte mit dem Barcode-Leser.')
|
print('Scanne dazu deine ID-Karte mit dem Barcode-Leser.')
|
||||||
print()
|
print()
|
||||||
|
@ -195,6 +230,7 @@ def handle(line, status):
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
colorama.init()
|
||||||
status = Status()
|
status = Status()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
Loading…
Reference in New Issue