From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id cCK+ItrPw19LdwAA0tVLHw (envelope-from ) for ; Sun, 29 Nov 2020 16:44:10 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id 4GyPHtrPw1/gdgAAB5/wlQ (envelope-from ) for ; Sun, 29 Nov 2020 16:44:10 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 46E1E940481 for ; Sun, 29 Nov 2020 16:44:10 +0000 (UTC) Received: from localhost ([::1]:49354 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kjPo1-0002xQ-0N for larch@yhetil.org; Sun, 29 Nov 2020 11:44:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39686) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kjPnu-0002x4-6X for guix-patches@gnu.org; Sun, 29 Nov 2020 11:44:02 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:40839) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kjPnt-0000Us-UY for guix-patches@gnu.org; Sun, 29 Nov 2020 11:44:01 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kjPnt-0002RF-SW for guix-patches@gnu.org; Sun, 29 Nov 2020 11:44:01 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#44663] [PATCH v2] ui: Handle multiword and empty $PAGER values. References: <20201115184726.29944-1-me@tobias.gr> In-Reply-To: <20201115184726.29944-1-me@tobias.gr> Resent-From: Tobias Geerinckx-Rice Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 29 Nov 2020 16:44:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 44663 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 44663@debbugs.gnu.org Received: via spool by 44663-submit@debbugs.gnu.org id=B44663.16066682259344 (code B ref 44663); Sun, 29 Nov 2020 16:44:01 +0000 Received: (at 44663) by debbugs.gnu.org; 29 Nov 2020 16:43:45 +0000 Received: from localhost ([127.0.0.1]:52385 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kjPnc-0002Qe-IT for submit@debbugs.gnu.org; Sun, 29 Nov 2020 11:43:44 -0500 Received: from tobias.gr ([80.241.217.52]:38036) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kjPnY-0002QT-Or for 44663@debbugs.gnu.org; Sun, 29 Nov 2020 11:43:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tobias.gr; s=2018; bh=bY1af1f81MCGv099uR3oGNc5XYQP7kod275b3nb91D8=; h=date:subject:to: from; b=VOwZP40YUaIRrpCoa6lcAdlHB8Q599PCnHr4Myb/7Hm7Sb0XWPZ0RLqHGq5udg 8NGlDMdm67aw3Jfr6LXI6nl4mdBoiz5F4t3ezAQ+71JRbUmV35OkBHheU3VaW7vUmU9+1E assz/By5SUF7woSpRM7vbaa9Y752MPk1ldSp8ZkuwHXHNORRxgUn47KUjMF4q3ydpo45nQ mmDFn3fgkcIegzk8l2B8p2TrSSFDkmFIPyYiOsEbmJaUKSlpmZq637FRGxOQTsvEgzLsm6 5ZbAXhoNJ+s0zTnFYdpT6Lqc4xdWaQWlDo9iRZIDDzhNcuVC0bedMHrrkJeURpN0/r13eg == Received: by submission.tobias.gr (OpenSMTPD) with ESMTPSA id c0256940 (TLSv1.2:ECDHE-ECDSA-AES256-GCM-SHA384:256:NO) for <44663@debbugs.gnu.org>; Sun, 29 Nov 2020 16:43:50 +0000 (UTC) Date: Sun, 29 Nov 2020 17:43:28 +0100 Message-Id: <20201129164328.18776-1-me@tobias.gr> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Spam-Score: -3.3 (---) X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" Reply-to: Tobias Geerinckx-Rice , Tobias Geerinckx-Rice via Guix-patches From: Tobias Geerinckx-Rice via Guix-patches via X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -1.78 X-Scanner: ns3122888.ip-94-23-21.eu Authentication-Results: aspmx1.migadu.com; dkim=fail (headers rsa verify failed) header.d=tobias.gr header.s=2018 header.b=VOwZP40Y; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-TUID: sl5JrZqo06MJ * guix/ui.scm (call-with-paginated-output-port): Empty PAGER values disable paging. Non-empty ones are split into command arguments. Reported by Daniel Brooks . --- guix/ui.scm | 47 ++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/guix/ui.scm b/guix/ui.scm index a59be74ecd..37099eac7b 100644 --- a/guix/ui.scm +++ b/guix/ui.scm @@ -12,7 +12,7 @@ ;;; Copyright © 2018 Kyle Meyer ;;; Copyright © 2018 Ricardo Wurmus ;;; Copyright © 2019 Chris Marusich -;;; Copyright © 2019 Tobias Geerinckx-Rice +;;; Copyright © 2019, 2020 Tobias Geerinckx-Rice ;;; Copyright © 2019 Simon Tournier ;;; Copyright © 2020 Arun Isaac ;;; Copyright © 2020 Maxim Cournoyer @@ -1675,24 +1675,33 @@ zero means that PACKAGE does not match any of REGEXPS." (define* (call-with-paginated-output-port proc #:key (less-options "FrX")) - (if (isatty?* (current-output-port)) - ;; Set 'LESS' so that 'less' exits if everything fits on the screen (F), - ;; lets ANSI escapes through (r), does not send the termcap - ;; initialization string (X). Set it unconditionally because some - ;; distros set it to something that doesn't work here. - ;; - ;; For things that produce long lines, such as 'guix processes', use 'R' - ;; instead of 'r': this strips hyperlinks but allows 'less' to make a - ;; good estimate of the line length. - (let ((pager (with-environment-variables `(("LESS" ,less-options)) - (open-pipe* OPEN_WRITE - (or (getenv "GUIX_PAGER") (getenv "PAGER") - "less"))))) - (dynamic-wind - (const #t) - (lambda () (proc pager)) - (lambda () (close-pipe pager)))) - (proc (current-output-port)))) + (let ((pager-command-line (or (getenv "GUIX_PAGER") + (getenv "PAGER") + "less"))) + ;; Setting PAGER to the empty string conventionally disables paging. + (if (and (not (string-null? pager-command-line)) + (isatty?* (current-output-port))) + ;; Set 'LESS' so that 'less' exits if everything fits on the screen + ;; (F), lets ANSI escapes through (r), does not send the termcap + ;; initialization string (X). Set it unconditionally because some + ;; distros set it to something that doesn't work here. + ;; + ;; For things that produce long lines, such as 'guix processes', use + ;; 'R' instead of 'r': this strips hyperlinks but allows 'less' to + ;; make a good estimate of the line length. + (let* ((pager (with-environment-variables `(("LESS" ,less-options)) + (apply open-pipe* OPEN_WRITE + ;; Split into arguments. Treat runs of multiple + ;; whitespace characters as one. libpipeline- + ;; style "cmd one\ arg" escaping is unsupported. + (remove "" + (string-split pager-command-line + char-set:whitespace)))))) + (dynamic-wind + (const #t) + (lambda () (proc pager)) + (lambda () (close-pipe pager)))) + (proc (current-output-port))))) (define-syntax with-paginated-output-port (syntax-rules () -- 2.29.2