[pacman-dev] [PATCH] don't wrap lines when we don't have a column size

Xavier shiningxc at gmail.com
Wed Aug 26 18:48:09 EDT 2009


On Thu, Aug 27, 2009 at 12:45 AM, Xavier Chantry<shiningxc at gmail.com> wrote:
> From: Oleg Finkelshteyn <olegfink at gmail.com>
>
> for example when we are not in a tty, there is no point in wrapping the
> output. this actually makes the job harder for scripts.
>
> $ pacman -Si binutils | grep Desc
> Description           : A set of programs to assemble and manipulate binary and
>
> the description was cut because the rest was on the following line.
>
> Signed-off-by: Xavier Chantry <shiningxc at gmail.com>
> ---
>  src/pacman/util.c |   45 ++++++++++++++++++---------------------------
>  1 files changed, 18 insertions(+), 27 deletions(-)
>
> diff --git a/src/pacman/util.c b/src/pacman/util.c
> index 9c4b797..3c3379a 100644
> --- a/src/pacman/util.c
> +++ b/src/pacman/util.c
> @@ -95,34 +95,18 @@ int needs_root(void)
>  /* gets the current screen column width */
>  int getcols(void)
>  {
> -       if(!isatty(1)) {
> -               /* We will default to 80 columns if we're not a tty
> -                * this seems a fairly standard file width.
> -                */
> -               return 80;
> -       } else {
>  #ifdef TIOCGSIZE
> -               struct ttysize win;
> -               if(ioctl(1, TIOCGSIZE, &win) == 0) {
> -                       return win.ts_cols;
> -               }
> -#elif defined(TIOCGWINSZ)
> -               struct winsize win;
> -               if(ioctl(1, TIOCGWINSZ, &win) == 0) {
> -                       return win.ws_col;
> -               }
> -#endif
> -               /* If we can't figure anything out, we'll just assume 80 columns */
> -               /* TODO any problems caused by this assumption? */
> -               return 80;
> +       struct ttysize win;
> +       if(ioctl(1, TIOCGSIZE, &win) == 0) {
> +               return win.ts_cols;
>        }
> -       /* Original envvar way - prone to display issues
> -       const char *cenv = getenv("COLUMNS");
> -       if(cenv != NULL) {
> -               return atoi(cenv);
> +#elif defined(TIOCGWINSZ)
> +       struct winsize win;
> +       if(ioctl(1, TIOCGWINSZ, &win) == 0) {
> +               return win.ws_col;
>        }
> -       return -1;
> -       */
> +#endif
> +       return 0;
>  }
>

this patch looks hard to read, but we basically just removed the first
if(!isatty(1)) check, so all the rest was re-indented.


More information about the pacman-dev mailing list