trying table

This commit is contained in:
Amber 2024-11-10 21:39:09 +01:00
parent 5945a56f2a
commit 733458f375

View File

@ -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():