commit 4abdee1dc1891ad212a48040d89ebc5b9dcc6088
parent 3809d99e78466142c4dd8247e40f0826f436e8b6
Author: Adrián Oliva <[email protected]>
Date:   Sun,  7 May 2023 17:56:57 -0600

Balance now has colors!

Moved color functions to its own file. Now the colored output can be
easily edited in general.

Diffstat:
Mutils/balance.py | 9+++++----
Autils/colored_output.py | 21+++++++++++++++++++++
Mutils/register.py | 17+----------------
3 files changed, 27 insertions(+), 20 deletions(-)

diff --git a/utils/balance.py b/utils/balance.py @@ -2,6 +2,7 @@ from typing import List from utils.read_file import entry from utils.register import currencies, complete_prices +from utils.colored_output import * class tree: @@ -53,18 +54,18 @@ class tree: result = '' if not ignore_level: for price in self.value: - result += f'{price:>20}\n' + result += price_f(f'{price:>20}') + '\n' result = result.rstrip() result += ' ' + ' '*(2 * level) if len(self.children) == 1: - result += self.name + ':' + result += account_f(self.name + ':') for child in self.children: result += child.__str__(level + 1, ignore_level = True) else: - result += self.name + '\n' + result += account_f(self.name) + '\n' for child in self.children: result += child.__str__(level + 1) @@ -96,7 +97,7 @@ class accounts_tree: result += '--------------------\n' for price in self.my_accounts.value: - result += f'{price:>20}\n' + result += price_f(f'{price:>20}') + '\n' return result.rstrip() diff --git a/utils/colored_output.py b/utils/colored_output.py @@ -0,0 +1,21 @@ +import colorama + + +def date_f(text: str) -> str: + """Format of the date.""" + return text + +def comment_f(text: str) -> str: + """Format of the transaction's comment.""" + return colorama.Style.BRIGHT + text + colorama.Style.RESET_ALL + +def account_f(text: str) -> str: + """Format of the account's name.""" + return colorama.Fore.BLUE + text + colorama.Style.RESET_ALL + +def price_f(text: str) -> str: + """Format of the price.""" + if '-' in text: + return colorama.Fore.RED + text + colorama.Style.RESET_ALL + else: + return text diff --git a/utils/register.py b/utils/register.py @@ -1,24 +1,9 @@ from utils.read_file import entry +from utils.colored_output import * from typing import List, Iterator import re import shutil -import colorama - -def date_f(text: str): - return text - -def comment_f(text: str): - return colorama.Style.BRIGHT + text + colorama.Style.RESET_ALL - -def account_f(text: str): - return colorama.Fore.BLUE + text + colorama.Style.RESET_ALL - -def price_f(text: str): - if '-' in text: - return colorama.Fore.RED + text + colorama.Style.RESET_ALL - else: - return text class currencies: