diff options
author | jakobst1n <jakob.stendahl@outlook.com> | 2023-10-20 19:35:32 +0200 |
---|---|---|
committer | jakobst1n <jakob.stendahl@outlook.com> | 2023-10-20 19:35:32 +0200 |
commit | 81f0f8de331b382caad8e82348a3ccbac5bb150e (patch) | |
tree | fdaaeab78ba7cc55336fdbdfae258a15cf5b24f1 /src/journal_lib/dataclasses.py | |
parent | 3bb38fcbbc9703ba22429441604d66f577fc6010 (diff) | |
download | journal-lib-81f0f8de331b382caad8e82348a3ccbac5bb150e.tar.gz journal-lib-81f0f8de331b382caad8e82348a3ccbac5bb150e.zip |
Run black, and do some changes for enabling better syntax expandability
Diffstat (limited to 'src/journal_lib/dataclasses.py')
-rw-r--r-- | src/journal_lib/dataclasses.py | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/journal_lib/dataclasses.py b/src/journal_lib/dataclasses.py index 227cabe..73b81e9 100644 --- a/src/journal_lib/dataclasses.py +++ b/src/journal_lib/dataclasses.py @@ -3,22 +3,26 @@ from dataclasses import dataclass FORCE_NOCOLOR = False + def set_force_nocolor(value: bool): global FORCE_NOCOLOR FORCE_NOCOLOR = value + def anesc(code: str): return "" if FORCE_NOCOLOR or not sys.stdout.isatty() else f"\u001b[{code}" + def format_amount(amount: str, currency: str | None = None) -> str: if currency is None: return amount - if currency in ['NOK']: + if currency in ["NOK"]: return f"{amount} {currency}" - if currency in ['$']: + if currency in ["$"]: return f"{currency}{amount}" return f"{amount} {currency}" + @dataclass class JournalEntryTransaction: account: str @@ -26,6 +30,7 @@ class JournalEntryTransaction: amount: str | None comment: str | None + @dataclass class JournalEntry: date: str @@ -51,7 +56,7 @@ class JournalEntry: t = f" {anesc('33m')}{transaction.account:{max_account_len}}{anesc('0m')}" if transaction.amount is not None: amount_code = "32m" - if (transaction.amount[0] == "-"): + if transaction.amount[0] == "-": amount_code = "31m" t += f" {anesc(amount_code)}{format_amount(transaction.amount, transaction.currency)}{anesc('0m')}" if transaction.comment is not None: @@ -62,6 +67,7 @@ class JournalEntry: s += f" {anesc('38m')}{comment}{anesc('0m')}\n" return s + "\n" + @dataclass class JournalAccountDef: account: str @@ -73,6 +79,7 @@ class JournalAccountDef: s += f" {anesc('38m')}{self.comment}{anesc('0m')}" return s + "\n" + @dataclass class JournalCommodityDef: commodity: str @@ -93,6 +100,7 @@ class JournalCommodityDef: s += "\n" return s + @dataclass class Journal: entries: list[JournalEntry] @@ -132,4 +140,3 @@ class Journal: print(f"INVALID ELEMENT {element}") return Journal(entries=entries, accounts=accounts, commodities=commodities) - |