Message ID | 1425309514-30184-2-git-send-email-rep.dot.nop@gmail.com |
---|---|
State | Accepted |
Delegated to: | Stephen Finucane |
Headers | show |
Hi Bernhard, On Mon, 2 Mar 2015 16:18:34 +0100 Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> wrote: > > Use the PAGER of the environment to view patches It would be nice if PAGER was not used when stdout is not a terminal so that piping the output works naturally.
On 2 March 2015 at 22:34, Stephen Rothwell <sfr@canb.auug.org.au> wrote: > Hi Bernhard, > > On Mon, 2 Mar 2015 16:18:34 +0100 Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> wrote: >> >> Use the PAGER of the environment to view patches > > It would be nice if PAGER was not used when stdout is not a terminal so > that piping the output works naturally. IIRC that works fine for me with PAGER=less LESS=-IM pwclient view 1 2 3 > /tmp/foo (say). http://git.busybox.net/busybox/tree/miscutils/less.c#n1647 I guess the big less should work fine too, the busybox more(1) does the same FWIW. thanks,
Jeremy, ping ^1 thanks, On 2 March 2015 at 22:43, Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> wrote: > On 2 March 2015 at 22:34, Stephen Rothwell <sfr@canb.auug.org.au> wrote: >> Hi Bernhard, >> >> On Mon, 2 Mar 2015 16:18:34 +0100 Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> wrote: >>> >>> Use the PAGER of the environment to view patches >> >> It would be nice if PAGER was not used when stdout is not a terminal so >> that piping the output works naturally. > > IIRC that works fine for me with PAGER=less LESS=-IM pwclient view 1 2 > 3 > /tmp/foo (say). > > http://git.busybox.net/busybox/tree/miscutils/less.c#n1647 > > I guess the big less should work fine too, the busybox more(1) does > the same FWIW. > > thanks,
diff --git a/apps/patchwork/bin/pwclient b/apps/patchwork/bin/pwclient index 2a80981..e6ee3c5 100755 --- a/apps/patchwork/bin/pwclient +++ b/apps/patchwork/bin/pwclient @@ -665,10 +665,25 @@ def main(): action_states(rpc) elif action == 'view': - for patch_id in non_empty(h, patch_ids): - s = rpc.patch_get_mbox(patch_id) - if len(s) > 0: - print unicode(s).encode("utf-8") + pager = os.environ.get('PAGER') + if pager: + pager = subprocess.Popen( + pager.split(), stdin=subprocess.PIPE + ) + if pager: + i = list() + for patch_id in non_empty(h, patch_ids): + s = rpc.patch_get_mbox(patch_id) + if len(s) > 0: + i.append(unicode(s).encode("utf-8")) + if len(i) > 0: + pager.communicate(input="\n".join(i)) + pager.stdin.close() + else: + for patch_id in non_empty(h, patch_ids): + s = rpc.patch_get_mbox(patch_id) + if len(s) > 0: + print unicode(s).encode("utf-8") elif action == 'info': for patch_id in non_empty(h, patch_ids):
Use the PAGER of the environment to view patches Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> --- apps/patchwork/bin/pwclient | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-)