From 0510626ae6a614009c8a10d8d128fa826f0ca9c4 Mon Sep 17 00:00:00 2001 From: decalage2 Date: Wed, 19 May 2021 00:38:09 +0200 Subject: [PATCH] tablestream: added TableStyleSlimSep, fixed a few issues causing extra separators --- oletools/thirdparty/tablestream/tablestream.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/oletools/thirdparty/tablestream/tablestream.py b/oletools/thirdparty/tablestream/tablestream.py index cd5a924..0445d1c 100644 --- a/oletools/thirdparty/tablestream/tablestream.py +++ b/oletools/thirdparty/tablestream/tablestream.py @@ -229,6 +229,17 @@ class TableStyleSlim(TableStyle): bottom_middle = u'+' bottom_right = u'' +class TableStyleSlimSep(TableStyleSlim): + """ + Style for a TableStream: slim with separator between all rows + Example: + ------+--- + Header| + ------+--- + | + ------+--- + """ + sep = True class TableStream(object): @@ -351,7 +362,8 @@ class TableStream(object): def write_header(self): if self.style.header_top: self.write_header_top() - self.write_row(self.header_row) + self.write_row(self.header_row, last=True) + # here we use last=True just to avoid an extra separator if style.sep=True if self.style.header_sep: self.write_header_sep() @@ -369,9 +381,12 @@ class TableStream(object): def write_bottom(self): s = self.style - line = self.make_line(left=s.bottom_left, horiz=s.bottom_horiz, - middle=s.bottom_middle, right=s.bottom_right) - self.write(line) + # TODO: usually for the caller it's difficult to determine when to use last=True, + # so the last row will have already a separator if sep=True + if not s.sep: + line = self.make_line(left=s.bottom_left, horiz=s.bottom_horiz, + middle=s.bottom_middle, right=s.bottom_right) + self.write(line) def close(self): self.write_bottom() -- libgit2 0.21.4