From: "Ludovic Courtès" <ludo@gnu.org>
To: 53909@debbugs.gnu.org
Cc: "Ludovic Courtès" <ludo@gnu.org>
Subject: [bug#53909] [PATCH 2/4] ui: 'with-paginated-output-port' gives access to the wrapped port.
Date: Wed, 9 Feb 2022 23:17:10 +0100 [thread overview]
Message-ID: <20220209221712.8724-2-ludo@gnu.org> (raw)
In-Reply-To: <20220209221712.8724-1-ludo@gnu.org>
* 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 @@ (define-module (guix ui)
file-hyperlink
location->hyperlink
+ pager-wrapped-port
with-paginated-output-port
relevance
package-relevance
@@ -1665,6 +1666,20 @@ (define (package-relevance package 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 @@ (define* (call-with-paginated-output-port proc
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)))))
--
2.34.0
next prev parent reply other threads:[~2022-02-09 22:23 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-09 22:12 [bug#53909] [PATCH 0/4] 'guix pull -l' no longer displays package lists by default Ludovic Courtès
2022-02-09 22:17 ` [bug#53909] [PATCH 1/4] pull: '--list-generations' doesn't list package changes " Ludovic Courtès
2022-02-09 22:17 ` Ludovic Courtès [this message]
2022-02-09 22:17 ` [bug#53909] [PATCH 3/4] ui: 'display-generation' uses color when talking to a pager Ludovic Courtès
2022-02-09 22:17 ` [bug#53909] [PATCH 4/4] pull: '--list-generations' pipes its output to the pager Ludovic Courtès
2022-02-10 17:21 ` [bug#53909] [PATCH 0/4] 'guix pull -l' no longer displays package lists by default zimoun
2022-02-14 14:56 ` bug#53909: " Ludovic Courtès
2022-02-14 17:28 ` [bug#53909] " zimoun
2022-02-10 17:51 ` zimoun
2022-02-14 12:56 ` Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220209221712.8724-2-ludo@gnu.org \
--to=ludo@gnu.org \
--cc=53909@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.