From 8f46d3006aed0da39e9c4d82b99d5e9d372ab989 Mon Sep 17 00:00:00 2001 From: Tiago Gomes Date: Mon, 25 Nov 2024 17:46:53 +0000 Subject: [PATCH] trybold --- src/investir/prettytable.py | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/investir/prettytable.py b/src/investir/prettytable.py index 8c29953..a30424f 100644 --- a/src/investir/prettytable.py +++ b/src/investir/prettytable.py @@ -5,11 +5,17 @@ import prettytable from investir.config import config +from investir.utils import boldify class PrettyTable(prettytable.PrettyTable): def __init__(self, *args, **kwargs) -> None: + + kwargs["field_names"] = list(map(lambda f: boldify(f), kwargs["field_names"])) + print(kwargs) + super().__init__(*args, **kwargs) + print("FN", self.field_names) def decimal_fmt(precision: int) -> Callable[[str, Any], str]: def _fmt(_field, val) -> str: @@ -22,23 +28,36 @@ def _fmt(_field, val) -> str: return _fmt - for f in kwargs["field_names"]: - match f.split()[0], f.split()[-1]: + print("FN", self.field_names) + + for f in self.field_names: + print(f, "|", f.split(" ")[0], "|", f.split(" ")[-1]) + print(f"|{f.split()[0].strip()}|") + ff = f.strip() + print(ff) + match ff.split()[0].strip(), ff.split()[-1]: case ("Name", _): - self.custom_format["Name"] = lambda _, val: f"{val:8}" + print(">>> MATCH NAME") + self.custom_format[f] = lambda _, val: f"{val:8}" self.align[f] = "l" case ("Quantity", _): - self.custom_format["Quantity"] = decimal_fmt(8) + print(">>> MATCH QTY") + self.custom_format[f] = decimal_fmt(8) self.align[f] = "r" case (_, "(£)") | (_, "(%)"): + print(">>> MATCH GBP") self.custom_format[f] = decimal_fmt(2) self.align[f] = "r" case _: + print(">>> FALLBACK") self.align[f] = "l" + print(self.align) + print(self.custom_format) + self.hrules = prettytable.HEADER self.vrules = prettytable.NONE