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

From: Boruch Baum <[email-masked]>
Date: Mon, 12 Feb 2018 07:22:22 -0500

On 2018-02-12 08:23, Bernhard Voelker wrote:
> On 02/12/2018 07:07 AM, Boruch Baum wrote:
>> ...

> Unfortunately, you did not show us neither the input

Easy... A sample input would be:

2018-02-09 11:10:27 status unpacked libefivar0:amd64 0.15-3
2018-02-09 11:10:28 status half-configured libefivar0:amd64 0.15-3
2018-02-09 11:10:28 status installed libefivar0:amd64 0.15-3
2018-02-09 11:10:28 trigproc man-db:amd64 2.7.0.2-5 <none>
2018-02-09 11:10:28 status half-configured man-db:amd64 2.7.0.2-5
2018-02-09 11:10:29 status installed man-db:amd64 2.7.0.2-5
2018-02-09 11:10:29 configure efibootmgr:amd64 0.11.0-3 <none>
2018-02-09 11:10:29 status unpacked efibootmgr:amd64 0.11.0-3
2018-02-09 11:10:29 status half-configured efibootmgr:amd64 0.11.0-3
2018-02-09 11:10:29 status installed efibootmgr:amd64 0.11.0-3

> - and I don't have dpkg -, nor the output,

Also easy. First, an easily readable sample output, without piping
colorization into `column' would be, :

>>   awk '{sub("install|configure|upgrade|trigproc","& _",$3);print}' \
>>   /var/log/dpkg.log | column -t

2018-02-09  11:10:27  status     unpacked         libefivar0:amd64
0.15-3
2018-02-09  11:10:28  status     half-configured  libefivar0:amd64
0.15-3
2018-02-09  11:10:28  status     installed        libefivar0:amd64
0.15-3
2018-02-09  11:10:28  trigproc   _                man-db:amd64
2.7.0.2-5  <none>
2018-02-09  11:10:28  status     half-configured  man-db:amd64
2.7.0.2-5
2018-02-09  11:10:29  status     installed        man-db:amd64
2.7.0.2-5
2018-02-09  11:10:29  configure  _                efibootmgr:amd64
0.11.0-3   <none>
2018-02-09  11:10:29  status     unpacked         efibootmgr:amd64
0.11.0-3
2018-02-09  11:10:29  status     half-configured  efibootmgr:amd64
0.11.0-3
2018-02-09  11:10:29  status     installed        efibootmgr:amd64  0.11.0-3

For the colorized output, ie. the actual raw output and the subject of
the bug report, here are two versions. First, in-line, with the
colorization codes stripped out so that it might be easily readable by
all, and; second, in raw format, as an mail attachment file, to avoid
having the control sequences somehow possibly messing with some hapless
reader's TTY.

>>   awk '{sub("install|configure|upgrade|trigproc","& _",$3);print}' \
>>   /var/log/dpkg.log | ccze -m ansi -o noscroll >&1 | column -t

2018-02-09  11:10:27  status  unpacked         libefivar0:amd64  0.15-3
2018-02-09  11:10:28  status  half-configured  libefivar0:amd64  0.15-3
2018-02-09  11:10:28  status  installed        libefivar0:amd64  0.15-3
2018-02-09  11:10:28  trigproc   _                man-db:amd64
2.7.0.2-5  <none>
2018-02-09  11:10:28  status  half-configured  man-db:amd64
2.7.0.2-5
2018-02-09  11:10:29  status  installed        man-db:amd64
2.7.0.2-5
2018-02-09  11:10:29  configure  _                efibootmgr:amd64
0.11.0-3   <none>
2018-02-09  11:10:29  status  unpacked         efibootmgr:amd64
0.11.0-3
2018-02-09  11:10:29  status  half-configured  efibootmgr:amd64
0.11.0-3
2018-02-09  11:10:29  status  installed        efibootmgr:amd64
0.11.0-3

> FWIW: what happens if you switch the two formatting commands, i.e., use
>
>   $ ... | column -t | ccze ...
>
> instead of
>
>   $ ... | ccze .... | column -t
>
> ?

! The colorization is not usefully applied, ie. the entire output is
monochrome, but in a color different that the input or normal STDOUT.

> At least when the input uses a different separator,

That would be a misunderstanding in what `ccze' does. It is specifically
intended for log files only. See, for example, man (1) ccze.

> 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:

As above, the colorization is not usefully applied, ie. the entire
output is monochrome, but in a color different that the input or normal
STDOUT.

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

A reasonably colorized output is applied.

-- 
hkp://keys.gnupg.net
CA45 09B5 5351 7C11 A9D1  7286 0036 9E45 1595 8BC0