All of lore.kernel.org
 help / color / mirror / Atom feed
From: Petr Baudis <pasky@suse.cz>
To: Kirill Smelkov <kirr@landau.phys.spbu.ru>,
	Pierre Habouzit <madcoder@debian.org>
Cc: martin f krafft <madduck@madduck.net>, git@vger.kernel.org
Subject: Re: [PATCH (topgit) 1/2] Implement setup_pager just like in git
Date: Wed, 7 Jan 2009 16:10:00 +0100	[thread overview]
Message-ID: <20090107151000.GR12275@machine.or.cz> (raw)
In-Reply-To: <20090107144432.GC831@artemis.corp> <20090107112754.GA15158@roro3>

On Wed, Jan 07, 2009 at 02:27:54PM +0300, Kirill Smelkov wrote:
> >From 2193b7c703c2d31c8739eec617b8c0e8c1d09b79 Mon Sep 17 00:00:00 2001
> From: Kirill Smelkov <kirr@landau.phys.spbu.ru>
> Date: Tue, 6 Jan 2009 17:56:37 +0300
> Subject: [PATCH (topgit) v2] Implement setup_pager just like in git
> 
> setup_pager() spawns a pager process and redirect the rest of our output
> to it.
> 
> This will be needed to fix `tg patch` output in the next commit.
> 
> Signed-off-by: Kirill Smelkov <kirr@landau.phys.spbu.ru>

But you never use it...?

> ---
>  tg.sh |   54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 54 insertions(+), 0 deletions(-)
> 
> diff --git a/tg.sh b/tg.sh
> index 8c23d26..bf9cf5c 100644
> --- a/tg.sh
> +++ b/tg.sh
> @@ -243,6 +243,60 @@ do_help()
>  	fi
>  }
>  
> +## Pager stuff
> +
> +# isatty FD
> +isatty()
> +{
> +	tty -s 0<&$1
> +}
> +
> +# setup_pager
> +# Spawn pager process and redirect the rest of our output to it
> +setup_pager()
> +{
> +	isatty 1 || return 0
> +
> +	# TG_PAGER = GIT_PAGER | PAGER
> +	# (but differentiate between GIT_PAGER='' and unset variables)
> +	# http://unix.derkeiler.com/Newsgroups/comp.unix.shell/2004-03/0792.html
> +	case ${GIT_PAGER+XXX} in
> +	'')
> +		case ${PAGER+XXX} in
> +		'')

I'm pretty sure there's been a nice trick for this, but I can't remember
it at all now.

> +			# both GIT_PAGER & PAGER unset
> +			TG_PAGER=''
> +			;;
> +		*)
> +			TG_PAGER="$PAGER"
> +			;;
> +		esac
> +		;;
> +	*)
> +		TG_PAGER="$GIT_PAGER"
> +		;;
> +	esac
> +
> +	[ -z "$TG_PAGER"  -o  "$TG_PAGER" = "cat" ]  && return 0
> +
> +
> +	# now spawn pager
> +	export LESS=${LESS:-FRSX}	# as in pager.c:pager_preexec()
> +
> +	_pager_fifo_dir="$(mktemp -t -d tg-pager-fifo.XXXXXX)"
> +	_pager_fifo="$_pager_fifo_dir/0"
> +	mkfifo -m 600 "$_pager_fifo"
> +
> +	"$TG_PAGER" < "$_pager_fifo" &
> +	exec > "$_pager_fifo"		# dup2(pager_fifo.in, 1)
> +
> +	# this is needed so e.g. `git diff` will still colorize it's output if
> +	# requested in ~/.gitconfig with color.diff=auto
> +	export GIT_PAGER_IN_USE=1
> +
> +	# atexit(close(1); wait pager)
> +	trap "exec >&-; rm "$_pager_fifo"; rmdir "$_pager_fifo_dir"; wait" EXIT
> +}

Frankly, I would have been just much happier if something like git
pager--helper would be provided for external tools to use. Seeing how it
gets reimplemented like this just pains me greatly.

On Wed, Jan 07, 2009 at 03:44:32PM +0100, Pierre Habouzit wrote:
> On Wed, Jan 07, 2009 at 11:27:54AM +0000, Kirill Smelkov wrote:
> > isatty()
> > {
> > 	tty -s 0<&$1
> > }
> 
> why not test -t 0 ? I'm not sure it's POSIX though.

It's SUS for many issues already it seems.

-- 
				Petr "Pasky" Baudis
The average, healthy, well-adjusted adult gets up at seven-thirty
in the morning feeling just terrible. -- Jean Kerr

  parent reply	other threads:[~2009-01-07 15:11 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-06 15:16 [PATCH (topgit) 0/2] tg-patch: fix pagination Kirill Smelkov
2009-01-06 15:16 ` [PATCH (topgit) 1/2] Implement setup_pager just like in git Kirill Smelkov
2009-01-06 20:32   ` martin f krafft
2009-01-07 10:35     ` Adeodato Simó
2009-01-07 11:27     ` Kirill Smelkov
2009-01-07 12:24       ` Thomas Rast
2009-01-07 22:00         ` Kirill Smelkov
2009-01-08  2:06           ` martin f krafft
2009-01-08  9:23             ` Kirill Smelkov
2009-01-07 14:24       ` Bert Wesarg
2009-01-07 14:44       ` Pierre Habouzit
2009-01-07 15:10       ` Petr Baudis [this message]
2009-01-06 15:16 ` [PATCH (topgit) 2/2] tg-patch: fix pagination Kirill Smelkov
2009-01-18 15:04 ` [PATCH (topgit) 0/2] " Kirill Smelkov

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=20090107151000.GR12275@machine.or.cz \
    --to=pasky@suse.cz \
    --cc=git@vger.kernel.org \
    --cc=kirr@landau.phys.spbu.ru \
    --cc=madcoder@debian.org \
    --cc=madduck@madduck.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.