From patchwork Thu Jun 9 09:52:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Taiju HIGASHI X-Patchwork-Id: 39811 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 5DE3527BBEA; Thu, 9 Jun 2022 13:16:36 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id B20B327BBE9 for ; Thu, 9 Jun 2022 13:16:35 +0100 (BST) Received: from localhost ([::1]:40500 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nzH5W-0007hb-PR for patchwork@mira.cbaines.net; Thu, 09 Jun 2022 08:16:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53280) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzEqc-0007VZ-RO for guix-patches@gnu.org; Thu, 09 Jun 2022 05:53:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:51126) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nzEqc-000507-Il for guix-patches@gnu.org; Thu, 09 Jun 2022 05:53:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nzEqc-0000fE-HW for guix-patches@gnu.org; Thu, 09 Jun 2022 05:53:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#55845] [PATCH 1/1] ui: Improve pager selection logic when less is not installed. Resent-From: Taiju HIGASHI Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 09 Jun 2022 09:53:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 55845 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Maxime Devos , me@tobias.gr Cc: 55845@debbugs.gnu.org Received: via spool by 55845-submit@debbugs.gnu.org id=B55845.16547683442491 (code B ref 55845); Thu, 09 Jun 2022 09:53:02 +0000 Received: (at 55845) by debbugs.gnu.org; 9 Jun 2022 09:52:24 +0000 Received: from localhost ([127.0.0.1]:45020 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nzEq0-0000e7-5o for submit@debbugs.gnu.org; Thu, 09 Jun 2022 05:52:24 -0400 Received: from mail-pj1-f50.google.com ([209.85.216.50]:55256) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nzEpy-0000dq-Jt for 55845@debbugs.gnu.org; Thu, 09 Jun 2022 05:52:23 -0400 Received: by mail-pj1-f50.google.com with SMTP id j7so20910222pjn.4 for <55845@debbugs.gnu.org>; Thu, 09 Jun 2022 02:52:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=taiju-info.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=q8LROpIUUdholOVFd60B/NiHMdYji1JFntLJ2JyRJFY=; b=jTaKVu3EtGawIj6jmkou7PLXQoPSu0pAZul7RRgHbYy54xD90paeg7j+jshu4Na1+X Ssfa6DxmEEu8lme2xetMye42viVJTqcprMoLXIyeN5yhkThzMDayOo69Kov+bJAC4CzI 70v6FmKRx+DLElhMQfB22l/K89sTZoILlxQlRHmyinwDrlI2RKc+S6SzVY0sqJFd5plj x5oNdq1mX0CpOnsIrKJND+pdZR+BylWJx2ZAxYxFb8ahyX1440FUNZv4NLpyoiTbyTD3 QlflvYxcnE2OlYUIZ7V8itB25Bmz1SRa4qRXrp4VfH0bxrfD9z/l+xhut0FQ698LYGLw D9fA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=q8LROpIUUdholOVFd60B/NiHMdYji1JFntLJ2JyRJFY=; b=yRu1koX8kEQN7djPIGnvZthNnr3EjU7f1Q78BhYSQsGmtO9xvB2j8eAulGzJksz3XM pWt7QSQVQeTlhzPt3SI/qMZpSKKUbq+BD9NzYDJw+MCCoOpe9dc22BnDb670c67y7net aAhljmW4fiDV1H4Gtp/5VX4viHI4/KpdG4sCPgmH+IWScDHa7dhfF4KiEIdrXwvPgiAM SLFMbFYao1MvrD6ITVdOaWBLIDkESKasXq1IlrnZJoHjsreGtDMDVUeyChqtMi0ethUO ZsGHMG27eb07SnUCfJs4RrC2xMkqwIIXQpgDBBXU2ap+GOd31fpQyAess7nkR+C+4e5W lqTw== X-Gm-Message-State: AOAM530wKA+PjvOjavWY9qBi+k3jihAXxQuw1bIDKRKceUaL8pqM0ENW XJ+Myat6YGFUe6GTo2RAtN7Rr6zu5gkR4pcc X-Google-Smtp-Source: ABdhPJzKX7ux5BY5yap+Gk2xWsX5jo7CBTLRzpO9utjDkKM/T9kqFrgmKBNzvxn3EEXoT4FGypBUKQ== X-Received: by 2002:a17:902:a404:b0:166:1f9b:c63a with SMTP id p4-20020a170902a40400b001661f9bc63amr39122174plq.26.1654768336288; Thu, 09 Jun 2022 02:52:16 -0700 (PDT) Received: from Taix ([240b:253:ec40:2400:b7d1:436e:2d61:e925]) by smtp.gmail.com with ESMTPSA id b4-20020a17090a9bc400b001e86be34c98sm8603730pjw.13.2022.06.09.02.52.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jun 2022 02:52:14 -0700 (PDT) From: Taiju HIGASHI References: <20220608102124.14865-1-higashi@taiju.info> <20220608102257.15042-1-higashi@taiju.info> <87leu72sbo.fsf@taiju.info> <55fe6cdbed891707aca419ff4eedd7c37ef3eb03.camel@telenet.be> Date: Thu, 09 Jun 2022 18:52:11 +0900 In-Reply-To: <55fe6cdbed891707aca419ff4eedd7c37ef3eb03.camel@telenet.be> (Maxime Devos's message of "Wed, 08 Jun 2022 17:08:13 +0200") Message-ID: <87fskexiyc.fsf@taiju.info> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.1 (gnu/linux) 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" X-getmail-retrieved-from-mailbox: Patches Hi, I have created a v2 patch and have attached it to this email and also added a unit test for the find-available-pager. Please check it out. Regards, From a65818b99ea1b327313fea08cf2db229c55e4b21 Mon Sep 17 00:00:00 2001 From: Taiju HIGASHI Date: Wed, 8 Jun 2022 18:50:28 +0900 Subject: [PATCH v2] ui: Improve pager selection logic when less is not installed. * guix/ui.scm (find-available-pager): New procedure. Return a available pager. (call-with-paginated-output-port): Change to use find-available-pager to select pager. * tests/ui.scm: Add tests for find-available-pager. --- guix/ui.scm | 16 ++++++++++++--- tests/ui.scm | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 3 deletions(-) diff --git a/guix/ui.scm b/guix/ui.scm index cb68a07c6c..93707a7a4b 100644 --- a/guix/ui.scm +++ b/guix/ui.scm @@ -17,6 +17,7 @@ ;;; Copyright © 2020 Arun Isaac ;;; Copyright © 2020 Maxim Cournoyer ;;; Copyright © 2018 Steve Sprang +;;; Copyright © 2022 Taiju HIGASHI ;;; ;;; This file is part of GNU Guix. ;;; @@ -1672,11 +1673,20 @@ (define* (pager-wrapped-port #:optional (port (current-output-port))) (_ #f))) +(define (find-available-pager) + "Returns the program name or path of an available pager. +If neither less nor more is installed, return an empty string so that +call-with-paginated-output-port will not call pager." + (or (getenv "GUIX_PAGER") + (getenv "PAGER") + (which "less") + (which "more") + "" ;; Returns an empty string so that call-with-paginated-output-port does not call pager. + )) + (define* (call-with-paginated-output-port proc #:key (less-options "FrX")) - (let ((pager-command-line (or (getenv "GUIX_PAGER") - (getenv "PAGER") - "less"))) + (let ((pager-command-line (find-available-pager))) ;; Setting PAGER to the empty string conventionally disables paging. (if (and (not (string-null? pager-command-line)) (isatty?* (current-output-port))) diff --git a/tests/ui.scm b/tests/ui.scm index 3dc6952e1f..41de3c63da 100644 --- a/tests/ui.scm +++ b/tests/ui.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2019, 2020 Ludovic Courtès +;;; Copyright © 2022 Taiju HIGASHI ;;; ;;; This file is part of GNU Guix. ;;; @@ -24,6 +25,7 @@ (define-module (test-ui) #:use-module (guix derivations) #:use-module ((gnu packages) #:select (specification->package)) #:use-module (guix tests) + #:use-module (guix utils) #:use-module (srfi srfi-1) #:use-module (srfi srfi-11) #:use-module (srfi srfi-19) @@ -292,4 +294,60 @@ (define guile-2.0.9 (>0 (package-relevance libb2 (map rx '("crypto" "library"))))))) +(define make-dummy-file + (compose + close-port + open-output-file + (cut string-append <> "/" <>))) + +(test-equal "find-available-pager, All environment variables are specified and both less and more are installed" + "guix-pager" + (call-with-temporary-directory + (lambda (dir) + (with-environment-variables + `(("PATH" ,dir) + ("GUIX_PAGER" "guix-pager") + ("PAGER" "pager")) + (make-dummy-file dir "less") + (make-dummy-file dir "more") + ((@@ (guix ui) find-available-pager)))))) + +(test-equal "find-available-pager, GUIX_PAGER is not specified" + "pager" + (call-with-temporary-directory + (lambda (dir) + (with-environment-variables + `(("PATH" ,dir) + ("PAGER" "pager")) + (make-dummy-file dir "less") + (make-dummy-file dir "more") + ((@@ (guix ui) find-available-pager)))))) + +(test-equal "find-available-pager, All environment variables are not specified and both less and more are installed" + "less" + (call-with-temporary-directory + (lambda (dir) + (with-environment-variables + `(("PATH" ,dir)) + (make-dummy-file dir "less") + (make-dummy-file dir "more") + (basename ((@@ (guix ui) find-available-pager))))))) + +(test-equal "find-available-pager, All environment variables are not specified and more is installed" + "more" + (call-with-temporary-directory + (lambda (dir) + (with-environment-variables + `(("PATH" ,dir)) + (make-dummy-file dir "more") + (basename ((@@ (guix ui) find-available-pager))))))) + +(test-equal "find-available-pager, All environment variables are not specified and both less and more are not installed" + "" + (call-with-temporary-directory + (lambda (dir) + (with-environment-variables + `(("PATH" ,dir)) + ((@@ (guix ui) find-available-pager)))))) + (test-end "ui") -- 2.36.1