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