git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: norm@dad.org
Cc: Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	l.s.r@web.de, git@vger.kernel.org,
	Junio C Hamano <gitster@pobox.com>
Subject: [PATCH] pager: disable color when pager is "more"
Date: Mon, 18 Jul 2016 09:19:07 +0000	[thread overview]
Message-ID: <20160718091907.GA13588@starla> (raw)
In-Reply-To: <alpine.DEB.2.20.1607180922580.28832@virtualbox>

Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
> On Sun, 17 Jul 2016, norm@dad.org wrote:
> > 'git diff' outputs escape characters which clutter my terminal. Yes, I
> > can sed them out, but then why are they there?
> 
> Those are most likely the ANSI sequences to add color. Can you call Git
> with the --no-color option and see whether the escape characters go away?

Norm: do you have PAGER=more set by any chance?
Perhaps changing it to "less" will allow you to preserve colors.

I saw a similar or identical problem during my vacation in
FreeBSD-land.  Perhaps the out-of-the-box experience can be
improved:

-----8<-----
Subject: [PATCH] pager: disable color when pager is "more"

more(1) traditionally cannot handle colors.

On FreeBSD 10.3, a new user ~/.profile explicitly sets
PAGER=more, but does not configure it to display colors, leading
to a bad out-of-the-box experience with escape sequences being
seen by the user.

In the FreeBSD 10.3 case, /usr/bin/more is actually a hardlink
to /usr/bin/less and capable of handling colors.  While we could
set MORE=FRX, this breaks other more(1) implementations,
including the one provided by util-linux on common GNU/Linux
systems.

So take the safe route and assume anybody still using more(1)
today can live with monochrome output, but acknowledge 'R'
in the MORE environment variable if it was set by the user.

Signed-off-by: Eric Wong <e@80x24.org>
---
 environment.c |  2 +-
 pager.c       | 11 +++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/environment.c b/environment.c
index ca72464..cfb56fd 100644
--- a/environment.c
+++ b/environment.c
@@ -41,7 +41,7 @@ size_t packed_git_limit = DEFAULT_PACKED_GIT_LIMIT;
 size_t delta_base_cache_limit = 96 * 1024 * 1024;
 unsigned long big_file_threshold = 512 * 1024 * 1024;
 const char *pager_program;
-int pager_use_color = 1;
+int pager_use_color = -1;
 const char *editor_program;
 const char *askpass_program;
 const char *excludes_file;
diff --git a/pager.c b/pager.c
index 4bc0481..3110df4 100644
--- a/pager.c
+++ b/pager.c
@@ -80,6 +80,17 @@ void setup_pager(void)
 	if (!pager)
 		return;
 
+	if (pager_use_color < 0 && !strcmp(pager, "more")) {
+		const char *more = getenv("MORE");
+
+		/*
+		 * MORE=R does not work everywhere, so we cannot set it,
+		 * but we can respect it if set.
+		 */
+		if (!more || !strchr(more, 'R'))
+			pager_use_color = 0;
+	}
+
 	/*
 	 * force computing the width of the terminal before we redirect
 	 * the standard output to the pager.
-- 
EW

  reply	other threads:[~2016-07-18  9:19 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-16 19:12 Question: Getting 'git diff' to generate /usr/bin/diff output norm
2016-07-16 20:47 ` Perry Hutchison
2016-07-17  7:46   ` Johannes Schindelin
2016-07-19 15:20     ` norm
2016-07-17 12:18 ` René Scharfe
2016-07-17 17:26   ` norm
2016-07-18  7:23     ` Johannes Schindelin
2016-07-18  9:19       ` Eric Wong [this message]
2016-07-18 13:16         ` [PATCH] pager: disable color when pager is "more" Jeff King
2016-07-18 17:19           ` Junio C Hamano
2016-07-18 18:58             ` Jeff King
2016-07-19  2:37             ` Eric Wong

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=20160718091907.GA13588@starla \
    --to=e@80x24.org \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=l.s.r@web.de \
    --cc=norm@dad.org \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).