From patchwork Fri Mar 20 14:09:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 20787 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 E092427BBEB; Fri, 20 Mar 2020 14:10:11 +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.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI 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 ESMTP id A684027BBEA for ; Fri, 20 Mar 2020 14:10:11 +0000 (GMT) Received: from localhost ([::1]:53408 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jFILj-0002gZ-74 for patchwork@mira.cbaines.net; Fri, 20 Mar 2020 10:10:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46626) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jFILb-0002gA-Rw for guix-patches@gnu.org; Fri, 20 Mar 2020 10:10:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jFILa-0003jW-OW for guix-patches@gnu.org; Fri, 20 Mar 2020 10:10:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:39355) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jFILa-0003j6-LL for guix-patches@gnu.org; Fri, 20 Mar 2020 10:10:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jFILa-0007OE-Gi for guix-patches@gnu.org; Fri, 20 Mar 2020 10:10:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#40149] [PATCH 2/5] ui: Add 'indented-string'. Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 20 Mar 2020 14:10:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 40149 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 40149@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= Received: via spool by 40149-submit@debbugs.gnu.org id=B40149.158471336828310 (code B ref 40149); Fri, 20 Mar 2020 14:10:02 +0000 Received: (at 40149) by debbugs.gnu.org; 20 Mar 2020 14:09:28 +0000 Received: from localhost ([127.0.0.1]:45319 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jFIL1-0007MY-MO for submit@debbugs.gnu.org; Fri, 20 Mar 2020 10:09:27 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59637) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jFIKz-0007M0-Ke for 40149@debbugs.gnu.org; Fri, 20 Mar 2020 10:09:26 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:51221) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1jFIKu-0003Ri-Ia; Fri, 20 Mar 2020 10:09:20 -0400 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=54272 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1jFIKt-0004AC-Uk; Fri, 20 Mar 2020 10:09:20 -0400 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Fri, 20 Mar 2020 15:09:07 +0100 Message-Id: <20200320140910.28439-2-ludo@gnu.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200320140910.28439-1-ludo@gnu.org> References: <20200320140910.28439-1-ludo@gnu.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 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 * guix/scripts/pull.scm (display-news-entry): Remove extra space in format string for 'indented-string'. (indented-string): Remove. (display-new/upgraded-packages)[pretty]: Pass #:initial-indent? to 'indented-string'. * guix/ui.scm (indented-string): New procedure. --- guix/scripts/pull.scm | 17 ++--------------- guix/ui.scm | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/guix/scripts/pull.scm b/guix/scripts/pull.scm index 51d4da209a..1db5ab7237 100644 --- a/guix/scripts/pull.scm +++ b/guix/scripts/pull.scm @@ -269,7 +269,7 @@ code, to PORT." (let ((body (or (assoc-ref body language) (assoc-ref body (%default-message-language)) ""))) - (format port " ~a~%" + (format port "~a~%" (indented-string (parameterize ((%text-width (- (%text-width) 4))) (string-trim-right @@ -523,19 +523,6 @@ true, display what would be built without actually building it." ;;; Queries. ;;; -(define (indented-string str indent) - "Return STR with each newline preceded by IDENT spaces." - (define indent-string - (make-list indent #\space)) - - (list->string - (string-fold-right (lambda (chr result) - (if (eqv? chr #\newline) - (cons chr (append indent-string result)) - (cons chr result))) - '() - str))) - (define profile-package-alist (mlambda (profile) "Return a name/version alist representing the packages in PROFILE." @@ -592,7 +579,7 @@ Return true when there is more package info to display." (define (pretty str column) (indented-string (fill-paragraph str (- (%text-width) 4) column) - 4)) + 4 #:initial-indent? #f)) (define concise/max-item-count ;; Maximum number of items to display when CONCISE? is true. diff --git a/guix/ui.scm b/guix/ui.scm index 6f1ca9c0b2..698111dd9a 100644 --- a/guix/ui.scm +++ b/guix/ui.scm @@ -103,6 +103,7 @@ read/eval read/eval-package-expression check-available-space + indented-string fill-paragraph %text-width texi->plain-text @@ -1163,6 +1164,23 @@ replacement if PORT is not Unicode-capable." (lambda () body ...))))) +(define* (indented-string str indent + #:key (initial-indent? #t)) + "Return STR with each newline preceded by IDENT spaces. When +INITIAL-INDENT? is true, the first line is also indented." + (define indent-string + (make-list indent #\space)) + + (list->string + (string-fold-right (lambda (chr result) + (if (eqv? chr #\newline) + (cons chr (append indent-string result)) + (cons chr result))) + '() + (if initial-indent? + (string-append (list->string indent-string) str) + str)))) + (define* (fill-paragraph str width #:optional (column 0)) "Fill STR such that each line contains at most WIDTH characters, assuming that the first character is at COLUMN.