diff --git a/silkaj/commands.py b/silkaj/commands.py index e29e158df7dbe4dae383773ed97fbd5653cfbde1..ea7259b47281ef0351949eed407f27d0904b6741 100644 --- a/silkaj/commands.py +++ b/silkaj/commands.py @@ -24,9 +24,9 @@ from click import IntRange, argument, command, option from duniterpy.api import bma from duniterpy.api.client import WSConnection from pendulum import from_timestamp -from tabulate import tabulate from websocket._exceptions import WebSocketConnectionClosedException +from silkaj import tui from silkaj.blockchain_tools import get_head_block from silkaj.constants import ALL from silkaj.network_tools import client_instance, determine_endpoint @@ -112,11 +112,15 @@ def display_diffi(current: WSConnection, diffi: Dict) -> None: system("cls||clear") block_gen = from_timestamp(current["time"], tz="local").format(ALL) match = match_pattern(int(current["powMin"]))[0] - table = tabulate(sorted_diffi, headers="keys", tablefmt="orgtbl", stralign="center") + + table = tui.Table(style="columns").set_cols_dtype(["t", "t", "t", "i"]) + table.fill_from_dict_list(sorted_diffi) + content = f'Current block: n°{current["number"]}, generated on {block_gen}\n\ Generation of next block n°{diffi["block"]} \ possible by at least {issuers}/{len(diffi["levels"])} members\n\ -Common Proof-of-Work difficulty level: {current["powMin"]}, hash starting with `{match}`\n{table}' +Common Proof-of-Work difficulty level: {current["powMin"]}, hash starting with `{match}`\n\ +{table.draw()}' print(content) @@ -174,10 +178,11 @@ def print_blocks_views(issuers, current_nbr, number, detailed): print(header, end=" ") if detailed or number <= 30: sorted_list = sorted(issuers, key=itemgetter("block"), reverse=True) - table = tabulate( - sorted_list, headers="keys", tablefmt="orgtbl", stralign="center" - ) - print(f"\n{table}") + + table = tui.Table(style="columns") + table.fill_from_dict_list(sorted_list) + print(f"\n{table.draw()}") + else: list_issued = [] # type: List[OrderedDict] for issuer in issuers: @@ -195,14 +200,9 @@ def print_blocks_views(issuers, current_nbr, number, detailed): for issued in list_issued: issued["percent"] = issued["blocks"] / number * 100 sorted_list = sorted(list_issued, key=itemgetter("blocks"), reverse=True) - table = tabulate( - sorted_list, - headers="keys", - tablefmt="orgtbl", - floatfmt=".1f", - stralign="center", - ) - print(f"from {len(list_issued)} issuers\n{table}") + table = tui.Table(style="columns") + table.fill_from_dict_list(sorted_list) + print(f"from {len(list_issued)} issuers\n{table.draw()}") @command("argos", help="Display currency information formatted for Argos or BitBar")