-
-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MarkdownTableWriter outputs ANSI Escape Sequences #30
Comments
Tracing through the code, it seems to be caused by a chain of actions starting in def _to_header_item(self, col_dp: ColumnDataProperty, value_dp: DataProperty) -> str:
return self.__escape_vertical_bar_char(super()._to_header_item(col_dp, value_dp))
def _to_row_item(self, row_idx: int, col_dp: ColumnDataProperty, value_dp: DataProperty) -> str:
return self.__escape_vertical_bar_char(super()._to_row_item(row_idx, col_dp, value_dp)) In turn, def _to_header_item(self, col_dp: ColumnDataProperty, value_dp: DataProperty) -> str:
format_string = self._get_header_format_string(col_dp, value_dp)
header = String(value_dp.data).force_convert().strip()
default_style = self._get_col_style(col_dp.column_index)
style = self._fetch_style_from_filter(-1, col_dp, value_dp, default_style)
return self._styler.apply_terminal_style(format_string.format(header), style=style) The def apply_terminal_style(self, value: str, style: Style) -> str:
if not self._writer.colorize_terminal:
return value
ansi_styles = []
if style.decoration_line in (DecorationLine.STRIKE, DecorationLine.LINE_THROUGH):
ansi_styles.append("strike")
if style.decoration_line == DecorationLine.UNDERLINE:
ansi_styles.append("underline")
if style.font_weight == FontWeight.BOLD:
ansi_styles.append("bold")
return tcolor(value, color=style.color, bg_color=style.bg_color, styles=ansi_styles) I was curious so I went through the code. Hope this was helpful. 👍 |
@calebstewart I will consider to add an interface that can be disabled ANSI escape from output for the future release. You can work around the issue by downgrade |
Thanks! Is there anything significant lost by downgrading to |
For You can find change logs at https://github.com/thombashi/pytablewriter/releases |
I had released You can also disable ANSI escape by manual via |
Problem
Creating a MarkdownTableWriter and specifying a column style with
font_weight="bold"
results in the correct**content**
being output, but also the entire column data (including the asterisks) are surrounded by ANSI escape sequences for bold text. The report I'm generating is eventually sent throughpandoc
which renders the ANSI sequences as ugly\xAB
characters in a browser.Expected output
A normal table cell just with
**
wrapped on either side of the data. No ANSI escape sequences.Steps to reproduce
You can't see the ANSI escape sequences above, obviously, but they are there when I just tested it. I also just installed the most recent version from PyPI, and my Python version is seen above in the output.
edit: forgot to mention, this also happens when writing somewhere that is not
stdout
. My use-case is actually writing to a file throughwriter.dump
. The example above was just a PoC.The text was updated successfully, but these errors were encountered: