guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

07/16: ui: 'with-paginated-output-port' gives access to the wrapped port


From: guix-commits
Subject: 07/16: ui: 'with-paginated-output-port' gives access to the wrapped port.
Date: Mon, 14 Feb 2022 09:53:40 -0500 (EST)

civodul pushed a commit to branch master
in repository guix.

commit 7ffcee1937671cbb318491076164fba4ef0b109c
Author: Ludovic Court├Ęs <ludo@gnu.org>
AuthorDate: Wed Feb 9 22:21:58 2022 +0100

    ui: 'with-paginated-output-port' gives access to the wrapped port.
    
    * guix/ui.scm (pager-port-mapping): New variable.
    (pager-wrapped-port): New procedure.
    (call-with-paginated-output-port): Parameterize 'pager-port-mapping'.
---
 guix/ui.scm | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/guix/ui.scm b/guix/ui.scm
index 093de1b4ab..d1f92ce7be 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -124,6 +124,7 @@
             file-hyperlink
             location->hyperlink
 
+            pager-wrapped-port
             with-paginated-output-port
             relevance
             package-relevance
@@ -1665,6 +1666,20 @@ score, the more relevant OBJ is to REGEXPS."
 zero means that PACKAGE does not match any of REGEXPS."
   (relevance package regexps %package-metrics))
 
+(define pager-port-mapping
+  ;; If a pager is being used, via 'with-paginated-output-port', this maps the
+  ;; pager port (pipe) to the underlying output port.
+  (make-parameter #f))
+
+(define* (pager-wrapped-port #:optional (port (current-output-port)))
+  "If PORT is a pipe to a pager created by 'with-paginated-output-port',
+return the underlying port.  Otherwise return #f."
+  (match (pager-port-mapping)
+    ((pager . wrapped)
+     (and (eq? pager port) wrapped))
+    (_
+     #f)))
+
 (define* (call-with-paginated-output-port proc
                                           #:key (less-options "FrX"))
   (let ((pager-command-line (or (getenv "GUIX_PAGER")
@@ -1691,7 +1706,10 @@ zero means that PACKAGE does not match any of REGEXPS."
                                                      char-set:whitespace))))))
           (dynamic-wind
             (const #t)
-            (lambda () (proc pager))
+            (lambda ()
+              (parameterize ((pager-port-mapping
+                              (cons pager (current-output-port))))
+                (proc pager)))
             (lambda () (close-pipe pager))))
         (proc (current-output-port)))))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]