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-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 F07091FA00 for ; Sat, 20 Mar 2021 10:04:07 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 3/5] lei q: put keywords on one line in --pretty output Date: Sat, 20 Mar 2021 19:04:05 +0900 Message-Id: <20210320100407.15713-4-e@80x24.org> In-Reply-To: <20210320100407.15713-1-e@80x24.org> References: <20210320100407.15713-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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. --- lib/PublicInbox/LeiOverview.pm | 5 ++++- t/lei-q-kw.t | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) 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;