Subject: Re: bug#30430: [column] accounting for ansi color codes

From: Bernhard Voelker <[email-masked]>
Date: Mon, 12 Feb 2018 08:23:29 +0100

On 02/12/2018 07:07 AM, Boruch Baum wrote:
> The `column -t' command doesn't align input properly when that input
> includes ansi color codes.
> 
> An argument that it should do so, is that `column' serves to make input
> more readable, and easier to find and compare fields of input data - the
> same goal as colorization.
> 
> I encountered this when trying to columnate log output that had been fed
> through the colorization program `ccze'.
> 
> Example: Compare the output of the following two one-liners:
> 
>   awk '{sub("install|configure|upgrade|trigproc","& _",$3);print}' \
>   /var/log/dpkg.log | column -t
> 
>   awk '{sub("install|configure|upgrade|trigproc","& _",$3);print}' \
>   /var/log/dpkg.log | ccze -m ansi -o noscroll >&1 | column -t

Unfortunately, you did not show us neither the input - and I don't
have dpkg -, nor the output, so I'd have to guess what you think
might be going wrong.

Would you provide a simple reproducer, please?

In the following example, column(1) produces correct output:

   $ printf "%s\n"                \
       "this_is_a_long_string 99" \
       "short abcdefghijklmnop"   \
       | ccze -m ansi -o noscroll \
       | column -t
   this_is_a_long_string  99
   short                  abcdefghijklmnop

FWIW: what happens if you switch the two formatting commands, i.e., use

   $ ... | column -t | ccze ...

instead of

   $ ... | ccze .... | column -t

?
At least when the input uses a different separator, then you'd have to
do that anyway - otherwise the separation of the columns is messed;
compare:

   $ head -n3 /etc/passwd | ccze -m ansi -o noscroll | column -t -s:

   $ head -n3 /etc/passwd | column -t -s: | ccze -m ansi -o noscroll

Is that the same what's happening to you?

Have a nice day,
Berny