From 632b094c4bc338feb415dd1ff5b06c6495038cc9 Mon Sep 17 00:00:00 2001
From: Eric Wong <e@80x24.org>
Date: Thu, 1 Jul 2021 11:31:32 +0000
Subject: [PATCH] lei inspect: support automatic pager in output

All commands which output non-trivial amounts of data to
the terminal should support this.
---
 lib/PublicInbox/LeiInspect.pm | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/lib/PublicInbox/LeiInspect.pm b/lib/PublicInbox/LeiInspect.pm
index 30714764..9a7900c7 100644
--- a/lib/PublicInbox/LeiInspect.pm
+++ b/lib/PublicInbox/LeiInspect.pm
@@ -155,9 +155,6 @@ sub inspect1 ($$$) {
 
 sub lei_inspect {
 	my ($lei, @argv) = @_;
-	$lei->{1}->autoflush(0);
-	my $multi = scalar(@argv) > 1;
-	$lei->out('[') if $multi;
 	$lei->{json} = ref(PublicInbox::Config::json())->new->utf8->canonical;
 	$lei->{lse} = ($lei->{opt}->{external} // 1) ? do {
 		my $sto = $lei->_lei_store;
@@ -166,6 +163,10 @@ sub lei_inspect {
 	if ($lei->{opt}->{pretty} || -t $lei->{1}) {
 		$lei->{json}->pretty(1)->indent(2);
 	}
+	$lei->start_pager if -t $lei->{1};
+	$lei->{1}->autoflush(0);
+	my $multi = scalar(@argv) > 1;
+	$lei->out('[') if $multi;
 	while (defined(my $x = shift @argv)) {
 		inspect1($lei, $x, scalar(@argv)) or return;
 	}
-- 
2.50.0