From patchwork Sun Nov 29 16:43:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Geerinckx-Rice X-Patchwork-Id: 25426 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 638EE27BBF9; Sun, 29 Nov 2020 16:44:10 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS, T_DKIM_INVALID,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 1AE8C27BBF8 for ; Sun, 29 Nov 2020 16:44:09 +0000 (GMT) Received: from localhost ([::1]:49354 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kjPo0-0002xQ-BM for patchwork@mira.cbaines.net; Sun, 29 Nov 2020 11:44:08 -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 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" Reply-to: Tobias Geerinckx-Rice , Tobias Geerinckx-Rice via Guix-patches X-Patchwork-Original-From: Tobias Geerinckx-Rice via Guix-patches via From: Tobias Geerinckx-Rice X-getmail-retrieved-from-mailbox: Patches * 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 ()