git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Duy Nguyen <pclouds@gmail.com>
To: Jeff King <peff@peff.net>
Cc: Git Mailing List <git@vger.kernel.org>
Subject: Re: [PATCH] tag: fix column output not using all terminal space
Date: Fri, 11 May 2018 10:43:45 +0200	[thread overview]
Message-ID: <CACsJy8CE2tnhH6eds6ZePyMxFXGnnyHDkWjSBbJz97BmYFr-gg@mail.gmail.com> (raw)
In-Reply-To: <20180511082840.GA22086@sigill.intra.peff.net>

On Fri, May 11, 2018 at 10:28 AM, Jeff King <peff@peff.net> wrote:
> On Fri, May 11, 2018 at 09:56:02AM +0200, Nguyễn Thái Ngọc Duy wrote:
>
>> git-tag runs a separate git-column command via run_column_filter().
>> This makes the new 'git-column' process fail to pick up the terminal
>> width for some reason and fall back to default width. Just explicitly
>> pass terminal width and avoid this terminal width detection business
>> in subprocesses.
>
> I think "some reason" is that we start the pager before running "git
> column". Running "git --no-pager tag --column=row" seems to fix it.
>
> It doesn't seem to have anything to do with the pager program itself.
> Doing:
>
>   # use sh to avoid optimizing out pager invocation
>   GIT_PAGER='sh -c cat' git tag --column=row
>
> shows the same problem. It looks like we force term_columns() to run
> before invoking the pager in order to cache the value. That makes sense,
> since TIOCGWINSZ on stdout is not going to be valid after we start
> piping it to the pager. But of course our git-column sub-process won't
> see that; the value is cached only in memory.
>
> So I think the approach of communicating the width to the sub-process is
> the right one. But I think we'd probably want to do so through the
> $COLUMNS variable, rather than passing a command-line option. That would
> fix the same bug for other cases where we might have multiple layers of
> sub-processes (e.g., if we pipe to the pager and then run a hook which
> columnizes output).
>
> Something like this seems to make it work for me:
>
> diff --git a/pager.c b/pager.c
> index 92b23e6cd1..c4f3412a84 100644
> --- a/pager.c
> +++ b/pager.c
> @@ -162,8 +162,12 @@ int term_columns(void)
>  #ifdef TIOCGWINSZ
>         else {
>                 struct winsize ws;
> -               if (!ioctl(1, TIOCGWINSZ, &ws) && ws.ws_col)
> +               if (!ioctl(1, TIOCGWINSZ, &ws) && ws.ws_col) {
> +                       char buf[64];
>                         term_columns_at_startup = ws.ws_col;
> +                       xsnprintf(buf, sizeof(buf), "%d", ws.ws_col);
> +                       setenv("COLUMNS", buf, 0);
> +               }
>         }
>  #endif
>
>
> though perhaps that should go into setup_pager(), which is what is
> actually making stdout inaccessible.
>
> As an aside, I was confused while looking into this because I _thought_
> I had COLUMNS set:
>
>   $ echo $COLUMNS
>   119
>
> But it turns out that bash sets that by default (if you have the
> checkwinsize option on) but does not export it. ;)

Yep. This confused me too and I was "f*ck it I don't want to deal with
this tty crap again". I'll leave the term_columns() fix to you then,
and limit this patch to the "while at there" part which should be
fixed anyway.
-- 
Duy

  reply	other threads:[~2018-05-11  8:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-11  7:56 [PATCH] tag: fix column output not using all terminal space Nguyễn Thái Ngọc Duy
2018-05-11  8:28 ` Jeff King
2018-05-11  8:43   ` Duy Nguyen [this message]
2018-05-11  9:25     ` [PATCH] pager: set COLUMNS to term_columns() Jeff King
2018-05-11 12:13       ` [PATCH] column: fix off-by-one default width Nguyễn Thái Ngọc Duy
2018-05-11 12:16       ` [PATCH] pager: set COLUMNS to term_columns() Duy Nguyen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CACsJy8CE2tnhH6eds6ZePyMxFXGnnyHDkWjSBbJz97BmYFr-gg@mail.gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).