about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-04-28 07:52:03 +0000
committerEric Wong <e@80x24.org>2021-04-28 19:30:58 +0000
commitcbe901a5175849c30980e100f2e212e24072684b (patch)
tree98530f0ada304e9a636e7cbc2a4e8573fdb86e1b /lib
parenteee88c0967d741686e1d14a01bc34c55167213e4 (diff)
downloadpublic-inbox-cbe901a5175849c30980e100f2e212e24072684b.tar.gz
Support setting a color to distinguish from user-supplied text.
We'll also put the $BLOB:$IDX identifier on a separate line and
just put the entire corresponding lei command in the form of:
"[-- lei blob $BLOB:$IDX --]" to teach users how to access it.
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/LeiViewText.pm14
1 files changed, 8 insertions, 6 deletions
diff --git a/lib/PublicInbox/LeiViewText.pm b/lib/PublicInbox/LeiViewText.pm
index 6f5fca49..5d649840 100644
--- a/lib/PublicInbox/LeiViewText.pm
+++ b/lib/PublicInbox/LeiViewText.pm
@@ -25,6 +25,7 @@ my %DEFAULT_COLOR = (
         quoted => 'blue',
         hdrdefault => 'cyan',
         status => 'bright_cyan', # smsg stuff
+        attachment => 'bright_red',
 
         # git names and defaults, falls back to ~/.gitconfig
         new => 'green',
@@ -113,20 +114,21 @@ sub hdr_buf ($$) {
 sub attach_note ($$$$;$) {
         my ($self, $ct, $p, $fn, $err) = @_;
         my ($part, $depth, $idx) = @$p;
-        my $obuf = $self->{obuf};
         my $nl = $idx eq '1' ? '' : "\n"; # like join("\n", ...)
-        $$obuf .= <<EOF if $err;
+        my $abuf = $err ? <<EOF : '';
 [-- Warning: decoded text below may be mangled, UTF-8 assumed --]
 EOF
-        my $blob = $self->{-smsg}->{blob} // '';
-        $blob .= ':' if $blob ne '';
-        $$obuf .= "[-- Attachment $blob$idx ";
+        $abuf .= "[-- Attachment #$idx: ";
         _xs($ct);
         my $size = length($part->body);
         my $ts = "Type: $ct, Size: $size bytes";
         my $d = $part->header('Content-Description') // $fn // '';
         _xs($d);
-        $$obuf .= $d eq '' ? "$ts --]\n" : "$d --]\n[-- $ts --]\n";
+        $abuf .= $d eq '' ? "$ts --]\n" : "$d --]\n[-- $ts --]\n";
+        if (my $blob = $self->{-smsg}->{blob}) {
+                $abuf .= "[-- lei blob $blob:$idx --]\n";
+        }
+        $self->{-colored}->($self, 'attachment', $abuf);
         hdr_buf($self, $part) if $part->{is_submsg};
 }