Skip to content

Commit

Permalink
trybold
Browse files Browse the repository at this point in the history
  • Loading branch information
tacgomes committed Nov 25, 2024
1 parent f9c52a7 commit 8f46d30
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/investir/prettytable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Expand Down

0 comments on commit 8f46d30

Please sign in to comment.