You are not logged in.

#1 2010-03-12 15:23:35

sepo
Member
Registered: 2010-03-04
Posts: 2

howto prevent pacman -Qi $PKG from resizing its output?

Hi, i would like to parse the output of pacman -Qi $PKG, but i have some problems because pacman is auto-resizing the output to 80 columns.

Example:

$ LANG= pacman -Qi libjpeg
Name           : libjpeg
[...]
Required By    : compiz-fusion-plugins-main  directfb  ffmpegthumbnailer  gd  
                 ghostscript  gstreamer0.10-good-plugins  imlib2  jasper  
                 libdjvu  libgphoto2  libmng  libtiff  libwmf  mjpegtools  
                 mplayer  poppler  sdl_image  slim  thunar  vdr  
[...]
Description    : Library of JPEG support functions

$ LANG= pacman -Qi libjpeg | grep '^Required By'
Required By    : compiz-fusion-plugins-main  directfb  ffmpegthumbnailer  gd

It only prints the first line. I tried stty cols 200 but it does not work.
Is it somehow possible to prevent pacman from doing this?

Best wishes
Sebastian

Last edited by sepo (2010-03-12 15:23:54)

Offline

#2 2010-05-10 13:52:14

tindzk
Member
Registered: 2010-05-10
Posts: 25
Website

Re: howto prevent pacman -Qi $PKG from resizing its output?

Unfortunately, there's no simple way of doing it but the terminal width can be set with ioctl() and TIOCSWINSZ.

After changing the terminal width to a greater value, your pacman command works as expected. However, all other terminal applications will look different because the given width mismatches with the actual terminal size. I've overcome this problem by changing the terminal width to the old value which seems to work fine.

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <pty.h>

static int ChangeTerminalWidth(int width) {
    struct winsize win;

    if (ioctl(STDIN_FILENO, TIOCGWINSZ, &win)) {
        return;
    }

    int old = win.ws_col;
    win.ws_col = width;

    ioctl(STDIN_FILENO, TIOCSWINSZ, &win);

    return old;
}

int main(int argc, char *argv[]) {
    if (argc > 1) {
        printf("%i", ChangeTerminalWidth(atoi(argv[1])));
    } else {
        fprintf(stderr, "No width given.");
        return EXIT_FAILURE;
    }

    return EXIT_SUCCESS;
}

Use it as follows:
$ OLD=$(./termsize 500) ; pacman -Qi libjpeg ; ./termsize $OLD

Hope that helps.

Offline

Board footer

Powered by FluxBB