Commit 0510626ae6a614009c8a10d8d128fa826f0ca9c4
1 parent
7a46e12d
tablestream: added TableStyleSlimSep, fixed a few issues causing extra separators
Showing
1 changed file
with
19 additions
and
4 deletions
oletools/thirdparty/tablestream/tablestream.py
| ... | ... | @@ -229,6 +229,17 @@ class TableStyleSlim(TableStyle): |
| 229 | 229 | bottom_middle = u'+' |
| 230 | 230 | bottom_right = u'' |
| 231 | 231 | |
| 232 | +class TableStyleSlimSep(TableStyleSlim): | |
| 233 | + """ | |
| 234 | + Style for a TableStream: slim with separator between all rows | |
| 235 | + Example: | |
| 236 | + ------+--- | |
| 237 | + Header| | |
| 238 | + ------+--- | |
| 239 | + | | |
| 240 | + ------+--- | |
| 241 | + """ | |
| 242 | + sep = True | |
| 232 | 243 | |
| 233 | 244 | |
| 234 | 245 | class TableStream(object): |
| ... | ... | @@ -351,7 +362,8 @@ class TableStream(object): |
| 351 | 362 | def write_header(self): |
| 352 | 363 | if self.style.header_top: |
| 353 | 364 | self.write_header_top() |
| 354 | - self.write_row(self.header_row) | |
| 365 | + self.write_row(self.header_row, last=True) | |
| 366 | + # here we use last=True just to avoid an extra separator if style.sep=True | |
| 355 | 367 | if self.style.header_sep: |
| 356 | 368 | self.write_header_sep() |
| 357 | 369 | |
| ... | ... | @@ -369,9 +381,12 @@ class TableStream(object): |
| 369 | 381 | |
| 370 | 382 | def write_bottom(self): |
| 371 | 383 | s = self.style |
| 372 | - line = self.make_line(left=s.bottom_left, horiz=s.bottom_horiz, | |
| 373 | - middle=s.bottom_middle, right=s.bottom_right) | |
| 374 | - self.write(line) | |
| 384 | + # TODO: usually for the caller it's difficult to determine when to use last=True, | |
| 385 | + # so the last row will have already a separator if sep=True | |
| 386 | + if not s.sep: | |
| 387 | + line = self.make_line(left=s.bottom_left, horiz=s.bottom_horiz, | |
| 388 | + middle=s.bottom_middle, right=s.bottom_right) | |
| 389 | + self.write(line) | |
| 375 | 390 | |
| 376 | 391 | def close(self): |
| 377 | 392 | self.write_bottom() | ... | ... |