user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 11/11] lei (lcat|q): support --no-color and --color
Date: Wed, 28 Apr 2021 07:52:05 +0000	[thread overview]
Message-ID: <20210428075205.19440-12-e@80x24.org> (raw)
In-Reply-To: <20210428075205.19440-1-e@80x24.org>

This should be familiar to git users who wish to force color
when writing to pipes or disable color.
---
 lib/PublicInbox/LEI.pm         | 9 +++++----
 lib/PublicInbox/LeiViewText.pm | 2 +-
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index 403f9ed8..7ffcf163 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -144,8 +144,8 @@ our %CMD = ( # sorted in order of importance/use:
 	@lxs_opt,
 	qw(save output|mfolder|o=s format|f=s dedupe|d=s threads|t+
 	sort|s=s reverse|r offset=i pretty jobs|j=s globoff|g augment|a
-	import-before! lock=s@ rsyncable alert=s@ mua=s verbose|v+), @c_opt,
-	opt_dash('limit|n=i', '[0-9]+') ],
+	import-before! lock=s@ rsyncable alert=s@ mua=s verbose|v+
+	color!), @c_opt, opt_dash('limit|n=i', '[0-9]+') ],
 
 'up' => [ 'OUTPUT|--all', 'update saved search',
 	qw(jobs|j=s lock=s@ alert=s@ mua=s verbose|v+ all:s), @c_opt ],
@@ -155,8 +155,8 @@ our %CMD = ( # sorted in order of importance/use:
 	# some of these options are ridiculous for lcat
 	@lxs_opt, qw(output|mfolder|o=s format|f=s dedupe|d=s threads|t+
 	sort|s=s reverse|r offset=i jobs|j=s globoff|g augment|a
-	import-before! lock=s@ rsyncable alert=s@ mua=s verbose|v+), @c_opt,
-	opt_dash('limit|n=i', '[0-9]+') ],
+	import-before! lock=s@ rsyncable alert=s@ mua=s verbose|v+
+	color!), @c_opt, opt_dash('limit|n=i', '[0-9]+') ],
 
 'blob' => [ 'OID', 'show a git blob, reconstructing from mail if necessary',
 	qw(git-dir=s@ cwd! verbose|v+ mail! oid-a|A=s path-a|a=s path-b|b=s),
@@ -268,6 +268,7 @@ my %OPTDESC = (
 'incremental!	import' => 'import already seen IMAP and NNTP articles',
 'globoff|g' => "do not match locations using '*?' wildcards ".
 		"and\xa0'[]'\x{a0}ranges",
+'color!' => 'disable color (for --format=text)',
 'verbose|v+' => 'be more verbose',
 'external!' => 'do not use externals',
 'mail!' => 'do not look in mail storage for OID',
diff --git a/lib/PublicInbox/LeiViewText.pm b/lib/PublicInbox/LeiViewText.pm
index e0d62c0d..d0f8b7f4 100644
--- a/lib/PublicInbox/LeiViewText.pm
+++ b/lib/PublicInbox/LeiViewText.pm
@@ -69,7 +69,7 @@ sub uncolored { ${$_[0]->{obuf}} .= $_[2] }
 sub new {
 	my ($cls, $lei) = @_;
 	my $self = bless { %{$lei->{opt}}, -colored => \&uncolored }, $cls;
-	return $self unless $self->{color} || -t $lei->{1};
+	return $self unless $self->{color} //= -t $lei->{1};
 	my $cmd = [ qw(git config -z --includes -l) ];
 	my ($r, $pid) = popen_rd($cmd, undef, { 2 => $lei->{2} });
 	my $cfg = PublicInbox::Config::config_fh_parse($r, "\0", "\n");

      parent reply	other threads:[~2021-04-28  7:52 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-28  7:51 [PATCH 00/11] lei: misc fixes, more lcat color support Eric Wong
2021-04-28  7:51 ` [PATCH 01/11] t/lei-p2q: add diagnostics Eric Wong
2021-04-28  7:51 ` [PATCH 02/11] tests: restore CWD with "lei -C" and run_script Eric Wong
2021-04-28  7:51 ` [PATCH 03/11] view_diff: minor coding style fixes Eric Wong
2021-04-28  7:51 ` [PATCH 04/11] lei_p2q: add _lei_wq_eof callback Eric Wong
2021-04-28  7:51 ` [PATCH 05/11] lei-daemon: note FD count mismatch to client Eric Wong
2021-04-28  7:52 ` [PATCH 06/11] t/run.perl: add (GNU) tail and strace support Eric Wong
2021-04-28  7:52 ` [PATCH 07/11] lei: quiet down Eml-related warnings consistently Eric Wong
2021-04-28  7:52 ` [PATCH 08/11] lei: simple WQ workers use {wq1} field Eric Wong
2021-04-28  7:52 ` [PATCH 09/11] lei_view_text: improve attachment display Eric Wong
2021-04-28  7:52 ` [PATCH 10/11] lei_view_text: translate background colors from git Eric Wong
2021-04-28  7:52 ` Eric Wong [this message]

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: https://public-inbox.org/README

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

  git send-email \
    --in-reply-to=20210428075205.19440-12-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.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/public-inbox.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).