From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.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 mCHvBgeBpGICgQAAbAwnHQ (envelope-from ) for ; Sat, 11 Jun 2022 13:48:23 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id GHWtBgeBpGLzFwEAauVa8A (envelope-from ) for ; Sat, 11 Jun 2022 13:48:23 +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 8575A134E2 for ; Sat, 11 Jun 2022 13:48:22 +0200 (CEST) Received: from localhost ([::1]:59966 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nzzbJ-0006U9-IX for larch@yhetil.org; Sat, 11 Jun 2022 07:48:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48846) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzzGg-0004au-Td for guix-patches@gnu.org; Sat, 11 Jun 2022 07:27:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:58135) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nzzGg-00061G-K0 for guix-patches@gnu.org; Sat, 11 Jun 2022 07:27:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nzzGg-0002nc-GP for guix-patches@gnu.org; Sat, 11 Jun 2022 07:27: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: Sat, 11 Jun 2022 11:27: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 Cc: 55845@debbugs.gnu.org, me@tobias.gr Received: via spool by 55845-submit@debbugs.gnu.org id=B55845.165494678910715 (code B ref 55845); Sat, 11 Jun 2022 11:27:02 +0000 Received: (at 55845) by debbugs.gnu.org; 11 Jun 2022 11:26:29 +0000 Received: from localhost ([127.0.0.1]:52031 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nzzG5-0002me-EX for submit@debbugs.gnu.org; Sat, 11 Jun 2022 07:26:29 -0400 Received: from mail-pg1-f182.google.com ([209.85.215.182]:45878) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nzzG3-0002mR-GG for 55845@debbugs.gnu.org; Sat, 11 Jun 2022 07:26:25 -0400 Received: by mail-pg1-f182.google.com with SMTP id 184so1426766pga.12 for <55845@debbugs.gnu.org>; Sat, 11 Jun 2022 04:26:23 -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=Ia3Hp9ldNdrnzilBtr9/oTMxC8MihM51qxyWs4LrRwA=; b=lqpQhIspDErcq0siFFms8Ad8wYsvQPy6KdYUWK1PVJOOD9HnGlxZLvGbp/+OJGfB/k 8CXfCkfMTzYTtZWuKTRKrP/UPG1dxMBU5qZZ1bl30soFMQNxjbRJonrKSsLOeDRt0oyi u7KOLhZa2YftBJpx7EXhWzplJVeuHrpgCuvx9FWoPRn9syLFQQxKXU3GMHPaEi/KrkFx +y8VUXkeSF5nOugMYjTr2j8kR6Uko9VOusl/p8+xwE14wMPMXYadjQgXalAZ4hGKv2yR +vA9ypLSCP99ldEo3eUIYehL8/tNGeJkTuSNKH/jalmSgBhcvvlYFO6k8oHZEkkTrJyL 4uFQ== 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=Ia3Hp9ldNdrnzilBtr9/oTMxC8MihM51qxyWs4LrRwA=; b=ZPjzBDm3z0oX85E4CqSQo04lhhpW68gwOcjo/SkGWHUnHUlEf+4vr50UP7fY1xH7yV Q1ZNnBuG+WY19r5LMQyx+7ioRpZWL4yMnkN+y357Z5ZXr3nsjNj2OYv8KlfUE1pk7zqV YT3VDdHpRo0fvo/Gd2+9JX2peqiJJ4txEGe46VKDRY8Pf/JDNrnMFRI1DqO7d78GapeX CTtBIb/fdFdgsWYWBwM0a8PmGCbbigtdMs2AdeBdCJQW0slwmEF6IHd4Qrr4s8dRRlHp fibMbu6rZb4EzFok3aP1WPYdcbZ0U+ZC/D45526otMsi9aJAl89pZU8gOWfXe6pRTE0H PDDQ== X-Gm-Message-State: AOAM530mw8HE/wv4onqK4VagG+Ag37W05l6/rXzCiz0OOX8PJTe90tpm i2DSXN/2R5JmN5Mh6ym8XVCDf2ZMusYOe0bK X-Google-Smtp-Source: ABdhPJwlgXa5CzHKVgsAHvwd2ucRVmdb/f9gvo/v2gViMk7TRNDxcm0wOXb6wmDW86gXtWeB/jHNlg== X-Received: by 2002:aa7:94a6:0:b0:51b:ddb8:1fcf with SMTP id a6-20020aa794a6000000b0051bddb81fcfmr44337612pfl.23.1654946777196; Sat, 11 Jun 2022 04:26:17 -0700 (PDT) Received: from Taix ([240b:253:ec40:2400:b7d1:436e:2d61:e925]) by smtp.gmail.com with ESMTPSA id l73-20020a63914c000000b003fe4da67980sm1333330pge.68.2022.06.11.04.26.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Jun 2022 04:26:15 -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> <87fskexiyc.fsf@taiju.info> <874k0uxhif.fsf@taiju.info> <5ccb68a4dc80a02baaf6d19fd782145b6b62e7b5.camel@telenet.be> <87a6alwdvn.fsf@taiju.info> <87r13wvrlz.fsf@taiju.info> <8250aad90dcf563aba4103127df95084a25fbd5d.camel@telenet.be> Date: Sat, 11 Jun 2022 20:26:12 +0900 In-Reply-To: <8250aad90dcf563aba4103127df95084a25fbd5d.camel@telenet.be> (Maxime Devos's message of "Fri, 10 Jun 2022 17:08:57 +0200") Message-ID: <87bkuzsap7.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=1654948102; 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=Ia3Hp9ldNdrnzilBtr9/oTMxC8MihM51qxyWs4LrRwA=; b=L4ORaGLrIm55sP/bRHmiSuQm09lnMvcsnckjo0BFBrXLxJJns6sMniF+fJP8IyQoWfVMYa Vr63tT56CKo46ErK5D/3LMZNx7kZycwb+ShTaf5QVlxYxLV5a6oWuOBW9SRx1tOV4R0NGw hLN54tdY+FLzoyx0I0IX+YzPF9D6pTJiwEcAe8AO/HO34uDs+tlPzJP8M+FIxFH+7Tb935 hP8VgblcfYgupLA6CkZCBaBU+V/ECbMFKuMkoKWCSEqzA1KUP0bbVTcSdIicjIUfOO/Yr6 C7sP/qAql9n3MH2rN057yrBvPPiJ5ynF4oVSUQ/fqV3LsnwvXuu9fjvylh2MVA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1654948102; a=rsa-sha256; cv=none; b=Vhrt6hKAuTt9O1gkhBCl54rONBJxjE8lxSOZJ1QD/xw4LCCgxI5sUdcFl6MjNmhO9LmXxm S8MC/t1d78DJ7TMJ2NoPD8wjvMd8M9o6CD5q++2je1pPbBALbZxuRF9U+oBvnOS8dve6Jx 4RFVdY2gzCzDuJoGVVuUzq1j4dYRmnfifo2G1TMW3rjg5wZ/o4QEIdUhfQJekfvy7Vyiw6 awOdM7pKRMFNAvGnLO4J8OazC9igY+e7SGknS3iwMPN2EiV59VIeNOOeG84YRaaAjH/mvu zn6OP0JXPHs7Z1fzNeXti198atzLb7AXjTXIGosqKUflHjXL1hyDfqbED7n61g== 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=lqpQhIsp; 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: 0.22 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=taiju-info.20210112.gappssmtp.com header.s=20210112 header.b=lqpQhIsp; 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: 8575A134E2 X-Spam-Score: 0.22 X-Migadu-Scanner: scn0.migadu.com X-TUID: EfD0iHFoIUyJ --=-=-= Content-Type: text/plain Hi Maxime, >> Sorry, I easily used with-environment-variable*s* because the interface >> looked convenient, but perhaps I should have used >> with-environment-variable defined in guix/tests.scm. >> However, using this one does not seem to solve the problem. Should I >> modify with-environment-variable*s*? > > I didn't know about 'with-environment-variable' (it already does the > unsetenv!). Just use whatever works (a nested with-environment-variable > or a modified with-environment-variables), though FWIW I would expect > using the modified with-environment-variables to result in more compact > code. I have attached the v4 patch. --=-=-= Content-Type: text/x-patch; charset=iso-8859-1 Content-Disposition: attachment; filename=v4-0001-ui-Improve-pager-selection-logic-when-less-is-not.patch Content-Transfer-Encoding: quoted-printable Content-Description: v4 patch >From bf557600c549e22a06ccfb288b89b1a0736b0500 Mon Sep 17 00:00:00 2001 From: Taiju HIGASHI Date: Wed, 8 Jun 2022 18:50:28 +0900 Subject: [PATCH v4] 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. * guix/utils.scm (call-with-environment-variables): Allow clearing of specified environment variables. * tests/ui.scm: Add tests for find-available-pager. --- guix/ui.scm | 16 +++++++++-- guix/utils.scm | 3 ++ tests/ui.scm | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 90 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/guix/utils.scm b/guix/utils.scm index 37b2e29800..5c36b15cfe 100644 --- a/guix/utils.scm +++ b/guix/utils.scm @@ -13,6 +13,7 @@ ;;; Copyright =A9 2021 Chris Marusich ;;; Copyright =A9 2021 Maxime Devos ;;; Copyright =A9 2018 Steve Sprang +;;; Copyright =A9 2022 Taiju HIGASHI ;;; ;;; This file is part of GNU Guix. ;;; @@ -158,6 +159,8 @@ (define (call-with-environment-variables variables thun= k) (dynamic-wind (lambda () (for-each (match-lambda + ((variable #false) + (unsetenv variable)) ((variable value) (setenv variable value))) variables)) diff --git a/tests/ui.scm b/tests/ui.scm index 3dc6952e1f..ff83e66a7e 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,76 @@ (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 in-vicinity <> <>))) + +(define (assert-equals-find-available-pager expected) + (define used-command "") + (mock ((ice-9 popen) open-pipe* + (lambda (mode command . args) + (unless (string-null? used-command) + (error "open-pipe* should only be called once")) + (set! used-command command) + (%make-void-port ""))) + (mock ((ice-9 popen) close-pipe (const 'ok)) + (mock ((guix colors) isatty?* (const #t)) + (with-paginated-output-port port 'ok) + (string=3D? expected used-command))))) + + +(test-assert "find-available-pager, All environment variables are specifie= d and both less and more are installed" + (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") + (assert-equals-find-available-pager "guix-pager"))))) + +(test-assert "find-available-pager, GUIX_PAGER is not specified" + (call-with-temporary-directory + (lambda (dir) + (with-environment-variables + `(("PATH" ,dir) + ("GUIX_PAGER" #false) + ("PAGER" "pager")) + (make-dummy-file dir "less") + (make-dummy-file dir "more") + (assert-equals-find-available-pager "pager"))))) + +(test-assert "find-available-pager, All environment variables are not spec= ified and both less and more are installed" + (call-with-temporary-directory + (lambda (dir) + (with-environment-variables + `(("PATH" ,dir) + ("GUIX_PAGER" #false) + ("PAGER" #false)) + (make-dummy-file dir "less") + (make-dummy-file dir "more") + (assert-equals-find-available-pager (in-vicinity dir "less")))))) + +(test-assert "find-available-pager, All environment variables are not spec= ified and more is installed" + (call-with-temporary-directory + (lambda (dir) + (with-environment-variables + `(("PATH" ,dir) + ("GUIX_PAGER" #false) + ("PAGER" #false)) + (make-dummy-file dir "more") + (assert-equals-find-available-pager (in-vicinity dir "more")))))) + +(test-assert "find-available-pager, All environment variables are not spec= ified and both less and more are not installed" + (call-with-temporary-directory + (lambda (dir) + (with-environment-variables + `(("PATH" ,dir) + ("GUIX_PAGER" #false) + ("PAGER" #false)) + (assert-equals-find-available-pager ""))))) + (test-end "ui") --=20 2.36.1 --=-=-= Content-Type: text/plain I decided to fix with-environment-variables. Also, the problem of find-available-pager tests being tests for unexported functions has been changed to tests that use the exported with-paginated-output-port to verify that the command is passed to open-pipe* as expected. Regards, -- Taiju --=-=-=--