]> git.ozlabs.org Git - patchwork/commitdiff
pwclient: honor PAGER for view
authoraldot <rep.dot.nop@gmail.com>
Mon, 2 Mar 2015 15:18:34 +0000 (16:18 +0100)
committerJeremy Kerr <jk@ozlabs.org>
Sun, 3 May 2015 05:40:02 +0000 (13:40 +0800)
Use the PAGER of the environment to view patches

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
apps/patchwork/bin/pwclient

index 0a477c26aa612345e3ac35ffec1b368bfe4f26b5..8d1f4766c0bfe7b594e1b118c7348ba4f06af9d5 100755 (executable)
@@ -684,10 +684,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):