From 03f5d3bc0f1f228ba4ecdea7d27f49d77117274b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20D=C3=A9l=C3=A9az?= <gaetan.deleaz@smartjog.com> Date: Fri, 13 May 2011 18:32:29 +0200 Subject: [PATCH] Modify the display list_align --- cccli/command/list.py | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/cccli/command/list.py b/cccli/command/list.py index 6183dfa..b55f2b0 100644 --- a/cccli/command/list.py +++ b/cccli/command/list.py @@ -52,6 +52,7 @@ class Command_list(TqlCommand): def list_align(self, objs): '''Listing line aligned''' + term_height, term_width = self.printer.get_term_size() # get max size by tag tags = dict() for o in objs["objects"]: @@ -61,18 +62,49 @@ class Command_list(TqlCommand): order = [ t for t in objs.get("order", []) if t in tags ] order.extend(sorted(set(tags.keys()) - set(order))) # compute index width - indexw = int(math.log10(len(objs["objects"]))) + indexw = int(math.log10(len(objs["objects"]))) + 1 # dislay each object by line for (i,o) in enumerate(objs["objects"]): + line_pos = 0 + num_pos = 0 + # tag position on the line + pos = dict() if self.options.index: - line = ("[%d]"%i).ljust(indexw + 4) + line = ("[%d]"%i).ljust(indexw + 3) + line_pos = len(line) else: line = "" + # variable for create a newline + new_line = False + first_line = True for t in order: + # if tag doesn't fit into the space left, newline + if line_pos + len(t) + len(":") + tags[t] + len(" ") >= term_width or new_line: + line += os.linesep + line_pos = 0 + num_pos = 0 + new_line = False + first_line = False line += "%s%s:%s%s "%(self.tdtc(t), t, self.tdc(t), self.tdr(t, o.get(t, u"")).ljust(tags[t])) + pos[num_pos] = line_pos + line_pos += len(t) + len(":") + tags[t] + len(" ") + num_pos += 1 + # align the next tag on the tag above and right + tmp_pos = num_pos + found_pos = False + while tmp_pos in pos: + # if the tag position above is greater than the line position, add space to align the next tag + if pos[tmp_pos] > line_pos: + line += " " * (pos[tmp_pos] - line_pos) + line_pos = pos[tmp_pos] + found_pos = True + break + else: + tmp_pos += 1 + new_line = not found_pos and not first_line self.printer.out("%s%s"%(line, color["reset"])) def list_table(self, objs): -- GitLab