question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MarkdownTableWriter outputs ANSI Escape Sequences

See original GitHub issue

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 through pandoc 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

Python 3.8.3 (default, May 17 2020, 18:15:42)
[GCC 10.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pytablewriter
>>> writer = pytablewriter.MarkdownTableWriter()
>>> writer.headers = ["Test", "Test"]
>>> writer.value_matrix = [("hello", "world"), ("goodbye", "world")]
>>> writer.column_styles = [pytablewriter.style.Style(font_weight="bold"), pytablewriter.style.Style()]
>>> import sys
>>> writer.dump(sys.stdout, close_after_write=False)
|   Test    |Test |
|-----------|-----|
|**hello**  |world|
|**goodbye**|world|

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 through writer.dump. The example above was just a PoC.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
thombashicommented, Jul 21, 2020

For MarkdownTableWriter class, some styles are not available. Other than that, not so changed significantly.

You can find change logs at https://github.com/thombashi/pytablewriter/releases

0reactions
thombashicommented, Jul 26, 2020

I had released pytablewriter 0.55.0. In this version, dump method will disable ANSI escape sequences during the execution.

You can also disable ANSI escape by manual via enable_ansi_escape attribute of writer classes for other methods like write_table/dumps

Read more comments on GitHub >

github_iconTop Results From Across the Web

pytablewriter - PyPI
pytablewriter is a Python library to write a table in various formats: AsciiDoc / CSV / Elasticsearch / HTML / JavaScript / JSON...
Read more >
ANSI escape code - Wikipedia
ANSI escape sequences are a standard for in-band signaling to control cursor location, color, font styling, and other options on video text terminals...
Read more >
python - parsing data tagged with ANSI color escape sequences
The output I am looking for is as follows: 'SOME_INFO, SOME_OTHR_INFO, Thu Sep 09 00:59:12 XST, some variable length message which might contain ......
Read more >
Build your own Command Line with ANSI escape codes
Everyone is used to programs printing out output in a terminal that scrolls as new text appears, but that's not all your can...
Read more >
A shell tool to “tablify” input data containing ANSI escape codes
I want the output to remain colored, so the tablified output should maintain the ANSI color codes. Hence, naively stripping them away does...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found