beautifultable icon indicating copy to clipboard operation
beautifultable copied to clipboard

[Question/discussion] Handling other "codes to escape" in tables

Open vincent-lg opened this issue 3 years ago • 1 comments

Hi,

I was pleased to find that BeautifulTable does support ANSI colors. I haven't explored the code yet so I have no idea how that works, but I would like to know if there's a "relatively easy" way to support other, non-ANSI codes.

The basic idea is, like ANSI colors, to have an API to add "tags" to be ignored, that is, tags that don't "count" in a cell's length and would be closed before the cell, should the cell be split on several lines. HTML-like codes might be nice, for instance:

A cell <r>partly in red.</r>

Of course, it would be possible to replace <r> with the ANSI code for red, and </r> with the ANSI code for the end of the color tag. But if there's a clear API to do this, I would prefer to using it.

I know this is kind of specialized, and the interest might seem pretty limited, so that's an open-ended question.

Thanks for this tool,

vincent-lg avatar Dec 09 '20 12:12 vincent-lg

This does seem like a good thing to have but I'm not sure if providing a built in general solution is feasible due to difference in rules between various formats. Although an extendible class which handles the parsing would be a decent enough solution. As a workaround you could try to monkeypatch utils.textwrap function and roll out your own implementation of wrapping html text.

pri22296 avatar Dec 12 '20 07:12 pri22296