Skip to content
Snippets Groups Projects
Commit 4217d216 authored by Gaëtan Déléaz's avatar Gaëtan Déléaz Committed by Seblu
Browse files

Modify the display list_table

parent ae12b0ea
No related branches found
No related tags found
No related merge requests found
......@@ -77,32 +77,58 @@ class Command_list(TqlCommand):
def list_table(self, objs):
'''Listing table style'''
term_height, term_width = self.printer.get_term_size()
# get max size by tag
tags = dict()
for o in objs["objects"]:
for (t,v) in o.items():
tags[t] = max(len(self.tdr(t, v)), tags.get(t, len(t)))
size_id = tags["id"] + len(" ")
# compute index width
indexw = max(int(math.log10(len(objs["objects"]))+1), len("index "))
if size_id + indexw >= term_width:
raise cmdError("term width is too small")
# build initial print order
order = [ t for t in objs.get("order", []) if t in tags ]
order.extend(sorted(set(tags.keys()) - set(order)))
if self.options.index:
# compute index width
indexw = max(int(math.log10(len(objs["objects"]))+1), len("index "))
# print index title
self.printer.out("index ", nl="")
# print tag title in order
for t in order:
self.printer.out(self.tdtc(t), nl="")
self.printer.out(t.ljust(tags[t]), nl=" ")
self.printer.out(color["reset"])
# print tags in order
for (i,o) in enumerate(objs["objects"]):
# remove id of order
order = order[1:]
# print tag table by title group
while order:
tag_index = 0
line_pos = 0
if self.options.index:
# print index title
self.printer.out("index ", nl="")
line_pos = indexw
# print id title
self.printer.out(self.tdtc("id") + "id".ljust(tags["id"]), nl=" ")
line_pos += size_id
# print tags title section in order
for t in order:
# if the tag don't fit in space left, stop the title loop
if line_pos + tags[t] + len(" ") > term_width and tag_index != 0:
break
self.printer.out(self.tdtc(t) + t.ljust(tags[t]), nl=" ")
line_pos += tags[t] + len(" ")
tag_index += 1
self.printer.out(color["reset"])
# print tags corresponding to the title
for (i,o) in enumerate(objs["objects"]):
line_pos = 0
if self.options.index:
self.printer.out(("%d "%i).ljust(indexw), nl="")
self.printer.out(self.tdc(t), nl="")
self.printer.out(self.tdr(t, o.get(t, u"")).ljust(tags[t]) ,nl=" ")
self.printer.out(color["reset"])
line_pos += indexw
# print id value
self.printer.out(self.tdc("id") + self.tdr("id", o.get("id", u"")).ljust(tags["id"]), nl=" ")
line_pos += size_id
# print tag value
for t in order[:tag_index]:
self.printer.out(self.tdc(t), nl="")
buf, line_pos = self._format_indent_text(self.tdr(t, o.get(t, u"")).ljust(tags[t]) + " ", line_pos, size_id, term_width)
self.printer.out(buf, nl="")
self.printer.out(color["reset"])
order = order[tag_index:]
def list_vertical(self, objs):
'''Vertical display'''
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment