From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id cAnWN33koWKigQEAbAwnHQ (envelope-from ) for ; Thu, 09 Jun 2022 14:15:57 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id qGy9N33koWK7IQAA9RJhRA (envelope-from ) for ; Thu, 09 Jun 2022 14:15:57 +0200 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 9C01417901 for ; Thu, 9 Jun 2022 14:15:56 +0200 (CEST) Received: from localhost ([::1]:40500 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nzH4t-0007hb-Mh for larch@yhetil.org; Thu, 09 Jun 2022 08:15:55 -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 Content-Type: multipart/mixed; boundary="=-=-=" 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+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1654776956; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:resent-cc:resent-from:resent-sender: resent-message-id:in-reply-to:in-reply-to:references:references: list-id:list-help:list-unsubscribe:list-subscribe:list-post: dkim-signature; bh=q8LROpIUUdholOVFd60B/NiHMdYji1JFntLJ2JyRJFY=; b=dvtl1rKa81LxfiBqVLwlm5VI2a9VXJb1N6/CLgqIIzxWsNDqzcHJiL1QwlrLz08/0wleQa uZamL0PVj/xVyuPpBOY/jATYiwGQSIB5eymhBpieYOAVxbkytwvEE7W6GKhlbgpV7org7O jUsbzz1N/p/gEJMOmCOrvM5BfOoD5r8XE6e53J6ER8f9XHV0+2Qfu6LWPayy6D81tR+Jho wtcSNGbXHCeT6Lo47Pj2CNBaVFUiiHRI1lA0bPpt2ISkKVc3un/f0L8/uI5NIqJVj4HO/m lckd2QdFBwCa8ZNb9FhBtILuYlUftP/ck8cMfY26BCENEmGowwleiur2xLIaFw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1654776956; a=rsa-sha256; cv=none; b=TcNJQuk+O+G6k8xac9/psXCHVgP1sFJ4CEdu4UDZ0n4r9vDat+2s92eikXIhlMnZNwREWa /mfa7d3nQeSFY1L5G71vK4QMMP27Vgr/dRzZYi6vRULcZ+KI9DezPWUDhF6z58JXCfG4CN DlSVzKbB8apwY3v6zXXYZBMo2wSQZHtkVcIUsWpHt/eUPFwLzsvhXtj3x08i/MEhuJcSle QA45UGzknev2sUhg4FbONFgS6aVmD/VNFx3gr0CSA0JUhdZhNx4rtLiifaCchUwNqIPoIm 7hZobqOCNzDPoq5sFWwCe4m0hchSUB2GfSi1mG0cde5zeFFIBCgz6ZYXcgcUbw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=taiju-info.20210112.gappssmtp.com header.s=20210112 header.b=jTaKVu3E; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: 2.19 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=taiju-info.20210112.gappssmtp.com header.s=20210112 header.b=jTaKVu3E; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 9C01417901 X-Spam-Score: 2.19 X-Migadu-Scanner: scn0.migadu.com X-TUID: oVj00xzQIB14 --=-=-= Content-Type: text/plain 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. --=-=-= Content-Type: text/x-patch; charset=iso-8859-1 Content-Disposition: attachment; filename=v2-0001-ui-Improve-pager-selection-logic-when-less-is-not.patch Content-Transfer-Encoding: quoted-printable Content-Description: v2-patch >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 pag= er. (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 =A9 2020 Arun Isaac ;;; Copyright =A9 2020 Maxim Cournoyer ;;; Copyright =A9 2018 Steve Sprang +;;; Copyright =A9 2022 Taiju HIGASHI ;;; ;;; This file is part of GNU Guix. ;;; @@ -1672,11 +1673,20 @@ (define* (pager-wrapped-port #:optional (port (curr= ent-output-port))) (_ #f))) =20 +(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-por= t 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 =A9 2013, 2014, 2015, 2016, 2017, 2019, 2020 Ludovic Court= =E8s +;;; Copyright =A9 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"))))))) =20 +(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 speci= fied 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 speci= fied 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 speci= fied 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") --=20 2.36.1 --=-=-= Content-Type: text/plain Please check it out. Regards, -- Taiju --=-=-=--