columnize
columnize copied to clipboard
solve issues when display with terminal color
before this fix, the output was not aligned correctly
Hey @funkygao, thanks for the PR. I have a few concerns about this:
-
Performance is a factor, as I mentioned in a (recently) closed PR here. This logic has to pass over each character. I have not had the time to run the benchmark against this branch myself, but I am guessing there will be a good difference here, and I'm trying to avoid negating all of the performance optimization we did in #10. One thought would be to completely prune out the color codes prior to checking the length with a pre-compiled regular expression or similar. As I mentioned in the above linked comment, we might need to provide an option to enable/disable the color code detection so that systems which produce huge amounts of output don't become slow as a result.
-
I am not convinced that
minvariably indicates the end of a color sequence code. I'll admit I am not an expert in this area, but IIRC there is an escaping / terminal width calculation problem which can manifest if the color code is not enclosed in\[\]. We should be certain that this is the right way to detect the end of the color code for that case.