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

Javier Cantero jcantero at escomposlinux.org
Mon Sep 12 15:42:54 UTC 2016


On Wed, Aug 17, 2016 at 10:46:59PM +0100, Manuel A. Fernandez Montecelo wrote:
 
> - somehow try to use the same width of the current terminal, with
>  possible truncation (would work fine in pipes for which the ultimate
>  output is the same terminal, but not if redirected and processed/seen
>  from another terminal/computer, unless the width is the same)

A way to get the width of the current terminal even when stdout was
redirected/piped is read it from stdin (fd 0) instead. With the
advantage that, unlike stdout, most of the times the standard input is
going to be connected directly to the terminal (I don't see actual cases
where somebody would want to redirect the standard input of aptitude to a
file/pipe, but maybe I'm wrong).

A simple proof of concept:

    #include <stdio.h>
    #include <unistd.h>
    #include <sys/ioctl.h>

    void check_term_size( int fd )
    {
        struct winsize ws;

        if ( isatty(fd) )
        {
            printf( "tty at FD %d\n", fd );
            if ( ioctl(fd, TIOCGWINSZ, &ws) != -1 )
            {
                printf( "ROWS=%d\n", ws.ws_row );
                printf( "COLUMNS=%d\n", ws.ws_col );
            }
        }
    }

    int main( int argc, char* argv[] )
    {
        check_term_size( 1 ); /* stdout */
        check_term_size( 0 ); /* stdin  */

        return 0;
    }


The downside is that the problem persists with redirections: they are
again dependent on the size of the terminal --meaning "aptitude search
<expr> > kk" would be different depending on the current width of the
terminal where the command is executed. But that is the case the -w
option was created for, right?

-- 
                       Saludos de Javier <jcantero at escomposlinux.org>


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 900 bytes
Desc: not available
URL: <http://lists.alioth.debian.org/pipermail/aptitude-devel/attachments/20160912/a3a6f0c3/attachment.sig>


More information about the Aptitude-devel mailing list