From 11906efb2cec82e24a2fd769a2eac0fb620372b9 Mon Sep 17 00:00:00 2001
From: Pierre-Antoine Rouby <pierre-antoine.rouby@inrae.fr>
Date: Wed, 3 May 2023 11:28:49 +0200
Subject: [PATCH] tools: Fix table size.

---
 src/tools.py | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/src/tools.py b/src/tools.py
index 902f2ea9..d2f11917 100644
--- a/src/tools.py
+++ b/src/tools.py
@@ -29,7 +29,19 @@ def display_timers():
     global _timers
     global _calls
 
-    print(f" +--{Style.BRIGHT}{Fore.BLUE}Timers{Style.RESET_ALL}------------------------------------------------------------------------------------------+")
+    fmax = max(
+        map(
+            lambda f: len(f.__qualname__) + len(f.__module__),
+            _timers
+        )
+    )
+
+    head = " +--"
+    head += f"{Style.BRIGHT}{Fore.BLUE}Timers{Style.RESET_ALL}"
+    for t in range(fmax + 26):
+        head += "-"
+    head += "+"
+    print(head)
 
     lst = sorted(
         map(
@@ -42,10 +54,14 @@ def display_timers():
 
     for func, time, calls in lst:
         name = (f"{Fore.BLUE}{func.__module__}{Style.RESET_ALL}" +
-                f".{Style.BRIGHT}{Fore.GREEN}{func.__qualname__:<{64 - len(func.__module__)}}{Style.RESET_ALL}")
+                f".{Style.BRIGHT}{Fore.GREEN}{func.__qualname__:<{fmax - len(func.__module__)}}{Style.RESET_ALL}")
         print(f" | {name} | {time:>10.6f} sec | {calls:>5} calls |")
 
-    print(" +--------------------------------------------------------------------------------------------------+")
+    tail = " +--"
+    for t in range(fmax + 32):
+        tail += "-"
+    tail += "+"
+    print(tail)
 
 def timer(func):
     """Function wrapper to register function runtime"""
-- 
GitLab