[Aptitude-devel] Bug#834402: Bug#834402: aptitude: search loses column format when redirected or piped

Manuel A. Fernandez Montecelo manuel.montezelo at gmail.com
Mon Aug 15 22:25:40 UTC 2016


Hi,

2016-08-15 20:54 Axel Beckert:
>Hi Manuel,
>
>Manuel A. Fernandez Montecelo wrote:
>> In the past it was just hardcoded to "80 columns", so your example when
>> doing it with and without pipe/redirection will have looked different as
>> well -- unless the terminal that you are using is 80-column wide, of
>> course.  (See attachment, the description is truncated).
>
>Either your examples show something different or not the problem:
>
>> $ aptitude search '~i~n^aptitude'
>> i   aptitude                                                                      - terminal-based package manager
>> i   aptitude-common                                                               - architecture independent files for the aptitude package manager
>>
>> $ aptitude search '~i~n^aptitude' | cat
>> i   aptitude                        - terminal-based package manager
>> i   aptitude-common                 - architecture independent files for the apt
>
>This definitely looks different here and IIRC also for the original
>submitter:
>[...]
>Manuel: I really wonder why your examples looked different than mine
>wrt. to aligned columns. Maybe some different options being set via
>configuration files?

Sorry that I was not very explicit... with "In the past" I meant the
version in stable/Jessie (or for that matter, any older than that), and
I was only saying that the output would have looked different in one way
or another.  (There were complaints in previous bug reports about
different aspects of this issue).

For example, if the default fields are used, the description will almost
always be truncated, sometimes in a slightly confusing ways as for
example in the case of aptitude-common above -- where it's not visually
obvious by the context that it was truncated, and one might thing that
aptitude just fails to process the short description incorrectly.

That is, the output when piping and redirecting was always different to
the "direct-to-terminal" one unless the terminal width happened to be
80.


To get always columns with these commands, no matter what, one can
define it explicitly, either with "-w" or with
Aptitude::CmdLine::Package-Display-Width (in the latter case, -w
overrides the config variable).  Of course, if one hardcodes
Aptitude::CmdLine::Package-Display-Width to e.g. 80 to have the same
behaviour as before, then it'll will always use 80 when outputting
directly to the terminal, unless overridden.

Aptitude::CmdLine::Package-Display-Format can also be used to define
another format, perhaps removing uninteresting fields (description?) and
setting explicit widths for the fields.

Another work around for the new behaviour is e.g.:

  $ alias aptitude-search="aptitude -w $COLUMNS search"


The reasoning for the change was that with pipes/redirections the
concept of "terminal" and consequently "width" is lost.  If it's
redirected it's possibly/likely that it's because it's moved and
processed elsewhere (where the new terminal size will likely be
different), or that the further processing doesn't bother with terminal
columns or uses smarter methods like using '|' as field separators.

In other words, trying to columnize the output when the width is unknown
(pipes or redirections) is a bit hacky and doesn't make much sense to
me, and forcing it to be 80 for a lack of better default is not always a
good solution as it might have been back in ~2000 (I think).


Cheers.
-- 
Manuel A. Fernandez Montecelo <manuel.montezelo at gmail.com>



More information about the Aptitude-devel mailing list