From 733458f375feea4c3c99e22cdd231d44fdd03126 Mon Sep 17 00:00:00 2001 From: Amber Date: Sun, 10 Nov 2024 21:39:09 +0100 Subject: [PATCH] trying table --- src/testing/treediff.py | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/src/testing/treediff.py b/src/testing/treediff.py index 6f14372..5604c19 100644 --- a/src/testing/treediff.py +++ b/src/testing/treediff.py @@ -9,14 +9,41 @@ def table_formatter(tree_diff): m = max([(len(item['name']) + len(item['rel_path'])) for item in v ]) mlen.append(m) # name and relpath of node - first_column_length = max(mlen) + 2 - second_column_length = len('Local') + 5 - third_column_length = len('Remote') + 5 + column_separator = '\uFF5C' + padding_right = 5 + hflen = max(mlen) + padding_right + hsclen = 11 + padding_right + htclen = 11 + padding_right - head = "{0:>{1}}".format("Node", first_column_length) - head += "{0:>{1}}".format("Local", second_column_length) - head += "{0:>{1}}".format("Remote", third_column_length) - print(head) + htexts = ['Node', 'Local', 'Remote'] + hlens = [hflen, hsclen, htclen] + + head_str = '' + for thead_text, thead_len, align in zip(htexts, hlens, ['^']*len(hlens)): + head_str += "{0:{align}{flen}}".format(thead_text, align=align, flen=thead_len) + head_str += column_separator + head_str += '\n' + + sep_str = '' + for head_column_length in [hflen, hsclen, htclen]: + sep_str += '{0:{fill}<{flen}}'.format('',fill='\u2015', flen=head_column_length) + sep_str += column_separator + sep_str += '\n' + + # head_str += (len(column_separator)*len(hlens) + sum(hlens)) * '\u2015' + '\n' + head_str += sep_str + + rows = '' + row = '' + trow_texts = ['casual', 'M', 'X'] + for trow_text,flen in zip(trow_texts, hlens): + row += "{0:{flen}}".format(trow_text, flen=flen) + row += column_separator + + rows += row + + + print(head_str+rows) def human_tree_diff():