From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 3EB0B1FD5C for ; Wed, 28 Apr 2021 07:52:06 +0000 (UTC) From: Eric Wong 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 Message-Id: <20210428075205.19440-12-e@80x24.org> In-Reply-To: <20210428075205.19440-1-e@80x24.org> References: <20210428075205.19440-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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");