From: Eric Wong Date: Sat, 20 Mar 2021 10:04:05 +0000 (+0900) Subject: lei q: put keywords on one line in --pretty output X-Git-Tag: v1.7.0~946 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=bcf5a733206b14f82cc151c702fd554cd08481ff;p=public-inbox.git lei q: put keywords on one line in --pretty output Don't waste precious terminal space when there are only a small number of possible keywords supported/reserved for JMAP. In the future, we may implement more sophisticated wrapping for labels, but it we'll cross tha bridge when we come to it. --- diff --git a/lib/PublicInbox/LeiOverview.pm b/lib/PublicInbox/LeiOverview.pm index 48237f8a..521bca50 100644 --- a/lib/PublicInbox/LeiOverview.pm +++ b/lib/PublicInbox/LeiOverview.pm @@ -176,7 +176,10 @@ sub _json_pretty { $pair =~ s/(null|"),"/$1, "/g; $pair; } @$v) . ']'; - } else { # references + } elsif ($k eq 'kw') { # keywords are short, one-line + $v = $json->encode($v); + $v =~ s/","/", "/g; + } else { # refs, labels, ... $v = '[' . join($sep, map { substr($json->encode([$_]), 1, -1); } @$v) . ']'; diff --git a/t/lei-q-kw.t b/t/lei-q-kw.t index e7e14221..de2c775a 100644 --- a/t/lei-q-kw.t +++ b/t/lei-q-kw.t @@ -144,7 +144,7 @@ lei_ok(qw(q -o), "mboxrd:$o", "m:$m", @inc); # emulate MUA marking mboxrd message as unread open my $fh, '<', $o or BAIL_OUT; my $s = do { local $/; <$fh> }; -$s =~ s/^Status: OR\n/Status: O\nX-Status: A\n/sm or +$s =~ s/^Status: OR\n/Status: O\nX-Status: AF\n/sm or fail "failed to clear R flag in $s"; open $fh, '>', $o or BAIL_OUT; print $fh $s or BAIL_OUT; @@ -156,7 +156,10 @@ lei_ok(qw(q -o), "mboxrd:$o", "m:$m", @inc); open $fh, '<', $o or BAIL_OUT; $s = do { local $/; <$fh> }; like($s, qr/^Status: O\n/ms, 'seen keyword gone in mbox'); -like($s, qr/^X-Status: A\n/ms, 'answered flag set'); +like($s, qr/^X-Status: AF\n/ms, 'answered + flagged set'); +lei_ok(qw(q --pretty), "m:$m", @inc); +like($lei_out, qr/^ "kw": \["answered", "flagged"\],\n/sm, + '--pretty JSON output shows kw: on one line'); }); # test_lei done_testing;