user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH 10/11] lei_view_text: translate background colors from git
  2021-04-28  7:51  6% [PATCH 00/11] lei: misc fixes, more lcat color support Eric Wong
@ 2021-04-28  7:52  7% ` Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2021-04-28  7:52 UTC (permalink / raw)
  To: meta

This seems to work with or without attributes.  We'll deal with
256-color terminal colors when/if somebody cares for it, but the
usual 16 ought to be more than enough.
---
 lib/PublicInbox/LeiViewText.pm | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/lib/PublicInbox/LeiViewText.pm b/lib/PublicInbox/LeiViewText.pm
index 5d649840..e0d62c0d 100644
--- a/lib/PublicInbox/LeiViewText.pm
+++ b/lib/PublicInbox/LeiViewText.pm
@@ -36,8 +36,11 @@ my %DEFAULT_COLOR = (
 	context => undef,
 );
 
+my $COLOR = qr/(?:bright)?
+		(?:normal|black|red|green|yellow|blue|magenta|cyan|white)/x;
+
 sub my_colored {
-	my ($self, $slot) = @_; # $_[2] = buffer
+	my ($self, $slot, $buf) = @_;
 	my $val = $self->{"color.$slot"} //=
 			$self->{-leicfg}->{"color.$slot"} //
 			$self->{-gitcfg}->{"color.diff.$slot"} //
@@ -45,11 +48,19 @@ sub my_colored {
 			$DEFAULT_COLOR{$slot};
 	$val = $val->[-1] if ref($val) eq 'ARRAY';
 	if (defined $val) {
+		$val = lc $val;
 		# git doesn't use "_", Term::ANSIColor does
-		$val =~ s/\Abright([^_])/bright_$1/i;
-		${$self->{obuf}} .= Term::ANSIColor::colored($_[2], lc $val);
+		$val =~ s/\Abright([^_])/bright_$1/ig;
+
+		# git: "green black" => T::A: "green on_black"
+		$val =~ s/($COLOR)(.+?)($COLOR)/$1$2on_$3/;
+
+		# FIXME: convert git #XXXXXX to T::A-compatible colors
+		# for 256-color terminals
+
+		${$self->{obuf}} .= colored($buf, $val);
 	} else {
-		${$self->{obuf}} .= $_[2];
+		${$self->{obuf}} .= $buf;
 	}
 }
 

^ permalink raw reply related	[relevance 7%]

* [PATCH 00/11] lei: misc fixes, more lcat color support
@ 2021-04-28  7:51  6% Eric Wong
  2021-04-28  7:52  7% ` [PATCH 10/11] lei_view_text: translate background colors from git Eric Wong
  0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2021-04-28  7:51 UTC (permalink / raw)
  To: meta

I'm seeing some odd test failures in "make check-run"
(but not "make check") that I haven't diagnosed, yet.
So there's some diagnostic changes and some golfing
to make internals more consistent.

Eric Wong (11):
  t/lei-p2q: add diagnostics
  tests: restore CWD with "lei -C" and run_script
  view_diff: minor coding style fixes
  lei_p2q: add _lei_wq_eof callback
  lei-daemon: note FD count mismatch to client
  t/run.perl: add (GNU) tail and strace support
  lei: quiet down Eml-related warnings consistently
  lei: simple WQ workers use {wq1} field
  lei_view_text: improve attachment display
  lei_view_text: translate background colors from git
  lei (lcat|q): support --no-color and --color

 lib/PublicInbox/LEI.pm         | 30 ++++++++++++++++++++---------
 lib/PublicInbox/LeiBlob.pm     |  9 +--------
 lib/PublicInbox/LeiConvert.pm  |  3 +--
 lib/PublicInbox/LeiImport.pm   | 10 +++-------
 lib/PublicInbox/LeiLsSearch.pm |  2 +-
 lib/PublicInbox/LeiMirror.pm   |  4 ++--
 lib/PublicInbox/LeiP2q.pm      |  6 ++----
 lib/PublicInbox/LeiStore.pm    |  1 -
 lib/PublicInbox/LeiTag.pm      |  9 ++-------
 lib/PublicInbox/LeiViewText.pm | 35 +++++++++++++++++++++++-----------
 lib/PublicInbox/LeiXSearch.pm  |  1 -
 lib/PublicInbox/TestCommon.pm  | 12 ++++++++----
 lib/PublicInbox/ViewDiff.pm    |  9 ++++-----
 script/lei                     |  4 ++--
 t/lei-externals.t              |  5 -----
 t/lei-p2q.t                    |  4 ++--
 t/lei-q-save.t                 |  4 ----
 t/run.perl                     |  7 +++++++
 t/solver_git.t                 |  5 -----
 19 files changed, 80 insertions(+), 80 deletions(-)

^ permalink raw reply	[relevance 6%]

Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2021-04-28  7:51  6% [PATCH 00/11] lei: misc fixes, more lcat color support Eric Wong
2021-04-28  7:52  7% ` [PATCH 10/11] lei_view_text: translate background colors from git Eric Wong

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).