From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 2JGbMUbK72C/VAAAgWs5BA (envelope-from ) for ; Thu, 15 Jul 2021 07:40:22 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id WHOQK0bK72DDHAAAB5/wlQ (envelope-from ) for ; Thu, 15 Jul 2021 05:40:22 +0000 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 0E4942A856 for ; Thu, 15 Jul 2021 07:40:22 +0200 (CEST) Received: from localhost ([::1]:54666 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m3u6f-0007lv-4V for larch@yhetil.org; Thu, 15 Jul 2021 01:40:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46626) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3u6M-0007kO-DC for guix-patches@gnu.org; Thu, 15 Jul 2021 01:40:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:34804) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m3u6M-0004DU-53 for guix-patches@gnu.org; Thu, 15 Jul 2021 01:40:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1m3u6M-0007hp-1e for guix-patches@gnu.org; Thu, 15 Jul 2021 01:40:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#30053] [PATCH 1/3] Improve appearance of tabular output. Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 15 Jul 2021 05:40:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 30053 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) Cc: 30053@debbugs.gnu.org, Steve Sprang , Roel Janssen Received: via spool by 30053-submit@debbugs.gnu.org id=B30053.162632759329602 (code B ref 30053); Thu, 15 Jul 2021 05:40:01 +0000 Received: (at 30053) by debbugs.gnu.org; 15 Jul 2021 05:39:53 +0000 Received: from localhost ([127.0.0.1]:46350 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m3u67-0007hI-52 for submit@debbugs.gnu.org; Thu, 15 Jul 2021 01:39:53 -0400 Received: from mail-qt1-f173.google.com ([209.85.160.173]:35337) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m3u64-0007h4-Up for 30053@debbugs.gnu.org; Thu, 15 Jul 2021 01:39:45 -0400 Received: by mail-qt1-f173.google.com with SMTP id g12so3751231qtb.2 for <30053@debbugs.gnu.org>; Wed, 14 Jul 2021 22:39:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=QxXRht1xYEdI83acVjJyDPZZ6wX6zybB1f6h5FuECog=; b=RylD4aiWMrvofizr1Q09kuO5ERjT0jK2yPH7soqXAjnzqyshlaoUyWwbZgtCZPLi5N Ir3LsiUIlKJch7rU4+aM402zs1JpEuCJgrl+loGwurHZ0QCKTEjPJJfnv6IftBHAOTy8 D5kv6osZcoWNLOlY8DZgtVgNhVaRYqhJvetjoSeKhBLTT6fMy3WnSM7OfPh824Io4PHl m6UFdpvVUJCbnu5z+OMyevb0Y0E3ocJBXxZru0KYibzoKW2KEyGgAynqG/EoezNwDkSp R8HKhSzGrU9enrAkpKtdu2qNfTdWKaKdCGeeedi9KY0cL6laXhGszkqx1IN2VDd26utN nsxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=QxXRht1xYEdI83acVjJyDPZZ6wX6zybB1f6h5FuECog=; b=VxgElpTH+oRUhdg2Zhjygh2u1gxHEKpe9Pjq/E+lCsIs6yI8GKZxGIkMRty+Q/gHr1 oxzw9nCcLult+GC7QBF6TN4mBEUcLWxMUz5MxtHCUFqJiTNDimlCQdgcaoOoax+98aAQ xfSPppvvfU+NZh98dxvRSIFw9BWcspS+MOGfnqF62gENNbK//TcAWHYTLOhc6FHmFIfk dXxW4kqVD3u3Pn/zBnv1yLBB/bf48546HcyFB4FXOu0yIE1ZuX0TSnc6m31Kp1BiRUPB mDYA7hy1GP//piewZjIoheIRgmyNCYJSEzRDU9vb0GIK49v7X2777I1glV91F3MOwQHa HPSQ== X-Gm-Message-State: AOAM5326qhZt8g1DDJeJ7E6z4I0ZQ0LaoUwukW/2wZtPvpGCdqvbb9Rj l66ep6OssQsHipC+wA/lmpg= X-Google-Smtp-Source: ABdhPJzDqhEdlcKYeedKizevm3q8zBUmzbu9vMNTU9ailF3Zwes35towJuH/feE6oAWO72KpIOZDzA== X-Received: by 2002:ac8:7207:: with SMTP id a7mr2306091qtp.32.1626327579241; Wed, 14 Jul 2021 22:39:39 -0700 (PDT) Received: from hurd (dsl-159-138.b2b2c.ca. [66.158.159.138]) by smtp.gmail.com with ESMTPSA id t74sm2069614qka.56.2021.07.14.22.39.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 22:39:38 -0700 (PDT) From: Maxim Cournoyer References: <878td4nksy.fsf@gnu.org> <87fu7b2old.fsf@gnu.org> <87zi5d6g8f.fsf@gnu.org> Date: Thu, 15 Jul 2021 01:39:36 -0400 In-Reply-To: <87zi5d6g8f.fsf@gnu.org> ("Ludovic =?UTF-8?Q?Court=C3=A8s?="'s message of "Tue, 16 Jan 2018 15:16:48 +0100") Message-ID: <87im1cnnjb.fsf_-_@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1626327622; 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=7LJR34pXKN/GKFuB2mY2SRD7rR2or1SuN2rBZIvOIqg=; b=FnGsMEmU+XTURQIDjq6kOZd2RwBkCN5F1lqX8AUjdHN4klj20+RH/aQIzTrbpniZpvK5b5 W5XjeQnUSneA2kjtoL5eDHggTZvzQCPr/sxPhzOEmOTF5AY1d8eK7Kl+uuuQYcEBg3JLDt s1zpDwTvQAV9oEToCsfeAIJAdAURFgy28z6reFMIsIzA7qh23Hm5u0U85/EpfzjZRzRxOU AHsgWwdAdp/qhOS8TKkjTuNAHorFxGLV8tXh7btwK6X1R9oxOBlya0B6reMeAUuk9OsPi6 n2PoWsgCne1o6taYXdsR6r1wQGWQ++EK99JXz8jHgVkXzz9krp3LnHVV+u0m3Q== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1626327622; a=rsa-sha256; cv=none; b=OtM/mFx78ND16rPK3BPj51KfCzJk26cAigkRTxC5JSvqwriSyKOL467cbIJqny3vs/Tf8a Iquyj77uTKIqODQdsbrtDXQ9QDk8xS+Ru2sBR020aasgyFTCcV8UbOF4zdJsjtWaIDz6NY lzftl64VJbf56uSeIGylVjqr6NzRQWB0rfOG+aoHs6QTQMn8Rylmb4yWg2klAqNk41Wcvg QBtx/Dwp3r5//dQHFfsqtVcByAHiv9VspYy2uBJE8ktjvLcWyegpjdFcMWSoKO1f1eW9hA JvcdAD5sgKsd/DLKl62TJDbHKy48NSd6TIwq9Wf9z5NRFz83zq4EcPzwJEikoA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20161025 header.b=RylD4aiW; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Spam-Score: 0.20 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20161025 header.b=RylD4aiW; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: 0E4942A856 X-Spam-Score: 0.20 X-Migadu-Scanner: scn0.migadu.com X-TUID: 1s3e3nTcs3hP --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hello! ludo@gnu.org (Ludovic Court=C3=A8s) writes: > Steve Sprang skribis: > >> On Fri, Jan 12, 2018 at 5:28 AM, Roel Janssen wrote: >>> If we use GNU awk instead of cut, I think any whitespace will work: >>> $ guix package -A | awk '{ print $1 "@" $2 }' >>> >>> And then we can optimize the output reading experience for our users >>> instead of for the 'cut' program. >> >> I like this proposal, unless there is a strong reason to prefer 'cut'? > > Again a matter of taste, but =E2=80=98cut=E2=80=99 looks to me both easie= r and simpler > than awk (since it=E2=80=99s a full language). > > But anyway, as Danny write, if your patches retain tabs (in addition to > spaces), presumably it=E2=80=99s OK even for those of us who prefer =E2= =80=98cut=E2=80=99, > right? > > Thanks, > Ludo=E2=80=99. I rebased this set of patch, and modified them slightly (attached). One thing that got my attention is the performance. For short lists of packages, it's invisible, but it takes noticeably longer for 'guix package -A', for example. I'm not sure where the time gets spent (see: https://paste.debian.net/1204412/). This is for guix package -A: --8<---------------cut here---------------start------------->8--- % cumulative self=20=20=20=20=20=20=20=20=20=20=20=20=20 time seconds seconds procedure 17.28 37.22 3.61 guix/memoization.scm:100:0 9.52 2.25 1.99 set-procedure-property! 4.23 1.14 0.89 ice-9/vlist.scm:539:0:vhash-assq 3.70 0.77 0.77 ice-9/popen.scm:183:0:reap-pipes 3.00 0.63 0.63 ice-9/eval.scm:604:6 2.82 0.66 0.59 open-output-string 2.65 1.36 0.55 srfi/srfi-1.scm:1028:0:lset-intersection 2.29 0.48 0.48 write-char 2.12 0.44 0.44 display 1.94 0.44 0.41 ice-9/boot-9.scm:2217:0:%load-announce 1.59 0.33 0.33 hash-ref 1.59 0.33 0.33 hashq 1.41 0.41 0.30 ice-9/vlist.scm:449:0:vhash-cons 1.23 3.58 0.26 ice-9/format.scm:113:2:format:format-work 1.23 2.99 0.26 ice-9/format.scm:39:0:format 1.23 0.33 0.26 srfi/srfi-1.scm:1033:17 1.06 0.30 0.22 guix/packages.scm:924:6:mproc 1.06 0.22 0.22 string=3D? 1.06 0.22 0.22 hash-set! 1.06 0.22 0.22 procedure? 1.06 0.22 0.22 ice-9/boot-9.scm:3569:0:autoload-done-or-in-pro= gress? 1.06 0.22 0.22 append 1.06 0.22 0.22 reverse! 0.88 2.80 0.18 guix/build-system/cargo.scm:246:0:lower 0.88 0.37 0.18 ice-9/eval.scm:297:11 0.88 0.18 0.18 list? 0.71 43.08 0.15 ice-9/eval.scm:292:11 0.71 24.34 0.15 guix/packages.scm:926:16 0.71 0.18 0.15 make-string 0.53 246.72 0.11 ice-9/threads.scm:388:4 0.53 32.97 0.11 guix/packages.scm:924:6 0.53 2.07 0.11 ice-9/eval.scm:159:9 0.53 1.33 0.11 ice-9/format.scm:759:2:format:out-obj-padded 0.53 0.15 0.11 get-output-string 0.53 0.11 0.11 ice-9/eval.scm:126:12 0.53 0.11 0.11 reverse [...] --- Sample count: 567 Total time: 20.913633405 seconds (12.747006885 seconds in GC) --8<---------------cut here---------------end--------------->8--- Without the change 'guix package -A' runs in about 2 seconds. With the change it runs in about 12 seconds here. Danny's suggestion to use 'guix package -A | columns -t' works too, but it's not convenient nor discoverable. Any opinions? Otherwise I might throw a coin, as I'm 50/50 on this. --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: attachment; filename=0001-utils-Add-a-procedure-for-pretty-printing-tabular-da.patch Content-Transfer-Encoding: quoted-printable >From faf27c47211281628dc5e216b316583da503dcd1 Mon Sep 17 00:00:00 2001 From: Steve Sprang Date: Tue, 9 Jan 2018 14:00:11 -0800 Subject: [PATCH 1/4] utils: Add a procedure for pretty printing tabular dat= a. * guix/utils.scm (pretty-print-table): New procedure. Co-authored-by: Maxim Cournoyer Signed-off-by: Maxim Cournoyer --- guix/utils.scm | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/guix/utils.scm b/guix/utils.scm index 05af86fc37..d43ff8d719 100644 --- a/guix/utils.scm +++ b/guix/utils.scm @@ -10,6 +10,8 @@ ;;; Copyright =C2=A9 2020 Efraim Flashner ;;; Copyright =C2=A9 2021 Simon Tournier ;;; Copyright =C2=A9 2021 Chris Marusich +;;; Copyright =C2=A9 2018 Steve Sprang +;;; Copyright =C2=A9 2021 Maxim Cournoyer ;;; ;;; This file is part of GNU Guix. ;;; @@ -123,7 +125,9 @@ canonical-newline-port =20 string-distance - string-closest)) + string-closest + + pretty-print-table)) =20 ;;; @@ -935,6 +939,27 @@ according to THRESHOLD, then #f is returned." #f +inf.0 tests))) =20 + +;;; +;;; Prettified output. +;;; + +(define (pretty-print-table rows) + "Print ROWS in neat columns. All rows should be lists of strings and ea= ch +row should have the same length. The columns are separated by a tab +character, and aligned using spaces." + (let* ((number-of-columns-to-pad (if (null? rows) 0 (1- (length (first r= ows))))) + ;; Ignore the last column as it is left aligned and doesn't need + ;; padding; this prevents printing extraneous trailing spaces. + (column-widths (fold (lambda (row maximums) + (map max (map string-length row) maximums)) + ;; Initial max width is 0 for each column. + (make-list number-of-columns-to-pad 0) + (map (cut drop-right <> 1) rows))) + (column-formats (map (cut format #f "~~~da" <>) column-widths)) + (fmt (string-append (string-join column-formats "\t") "\t~a"))) + (map (cut format #t "~?~%" fmt <>) rows))) + ;;; Local Variables: ;;; eval: (put 'call-with-progress-reporter 'scheme-indent-function 1) ;;; End: --=20 2.32.0 --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: attachment; filename=0002-package-Improve-output-appearance-when-listing-packa.patch Content-Transfer-Encoding: quoted-printable >From 81d7ada26c30effede23926fb85b2b8ed59778af Mon Sep 17 00:00:00 2001 From: Steve Sprang Date: Tue, 9 Jan 2018 14:10:04 -0800 Subject: [PATCH 2/4] package: Improve output appearance when listing packag= es. * guix/scripts/package.scm (process-query): Use pretty-print-table when listing installed and available packages. Modified-by: Maxim Cournoyer Signed-off-by: Maxim Cournoyer --- guix/scripts/package.scm | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm index 694959d326..a34ecdcb54 100644 --- a/guix/scripts/package.scm +++ b/guix/scripts/package.scm @@ -9,6 +9,7 @@ ;;; Copyright =C2=A9 2019 Tobias Geerinckx-Rice ;;; Copyright =C2=A9 2020 Ricardo Wurmus ;;; Copyright =C2=A9 2020 Simon Tournier +;;; Copyright =C2=A9 2018 Steve Sprang ;;; ;;; This file is part of GNU Guix. ;;; @@ -831,15 +832,14 @@ processed, #f otherwise." (map profile-manifest profiles))) (installed (manifest-entries manifest))) (leave-on-EPIPE - (for-each (match-lambda - (($ name version output path _) - (when (or (not regexp) - (regexp-exec regexp name)) - (format #t "~a\t~a\t~a\t~a~%" - name (or version "?") output path)))) - - ;; Show most recently installed packages last. - (reverse installed)))) + (let ((rows (filter-map + (match-lambda + (($ name version output path _) + (and (regexp-exec regexp name) + (list name (or version "?") output path)))) + installed))) + ;; Show most recently installed packages last. + (pretty-print-table (reverse rows))))) #t) =20 (('list-available regexp) @@ -862,16 +862,15 @@ processed, #f otherwise." result)) '()))) (leave-on-EPIPE - (for-each (match-lambda - ((name version outputs location) - (format #t "~a\t~a\t~a\t~a~%" - name version - (string-join outputs ",") - (location->string location)))) - (sort available - (match-lambda* - (((name1 . _) (name2 . _)) - (stringstring location)))) + (sort available + (match-lambda* + (((name1 . _) (name2 . _)) + (stringFrom 43a99413e4a59ed32887b8b0552353637f2b7304 Mon Sep 17 00:00:00 2001 From: Steve Sprang Date: Tue, 9 Jan 2018 14:20:12 -0800 Subject: [PATCH 3/4] ui: Improve output appearance when listing generations. * guix/ui.scm (display-profile-content-diff): Use pretty-print-table to for= mat output. (display-profile-content): Likewise. --- guix/ui.scm | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/guix/ui.scm b/guix/ui.scm index 26a437e904..1428c254b3 100644 --- a/guix/ui.scm +++ b/guix/ui.scm @@ -16,6 +16,7 @@ ;;; Copyright =C2=A9 2019, 2021 Simon Tournier ;;; Copyright =C2=A9 2020 Arun Isaac ;;; Copyright =C2=A9 2020 Maxim Cournoyer +;;; Copyright =C2=A9 2018 Steve Sprang ;;; ;;; This file is part of GNU Guix. ;;; @@ -1889,10 +1890,10 @@ DURATION-RELATION with the current time." (define (equal-entry? first second) (string=3D (manifest-entry-item first) (manifest-entry-item second))) =20 - (define (display-entry entry prefix) + (define (make-row entry prefix) (match entry (($ name version output location _) - (format #t " ~a ~a\t~a\t~a\t~a~%" prefix name version output locati= on)))) + (list (format #f " ~a ~a" prefix name) version output location)))) =20 (define (list-entries number) (manifest-entries (profile-manifest (generation-file-name profile numb= er)))) @@ -1903,8 +1904,8 @@ DURATION-RELATION with the current time." equal-entry? (list-entries new) (list-entries old))) (removed (lset-difference equal-entry? (list-entries old) (list-entries new)))) - (for-each (cut display-entry <> "+") added) - (for-each (cut display-entry <> "-") removed) + (pretty-print-table (append (map (cut make-row <> "+") added) + (map (cut make-row <> "-") removed))) (newline))) =20 (display-diff profile gen1 gen2)) @@ -1932,15 +1933,17 @@ already taken." (define (display-profile-content profile number) "Display the packages in PROFILE, generation NUMBER, in a human-readable way." - (for-each (match-lambda - (($ name version output location _) - (format #t " ~a\t~a\t~a\t~a~%" - name version output location))) - - ;; Show most recently installed packages last. - (reverse - (manifest-entries - (profile-manifest (generation-file-name profile number)))))) + + (define entry->row + (match-lambda + (($ name version output location _) + (list (string-append " " name) version output location)))) + + (let* ((manifest (profile-manifest (generation-file-name profile number)= )) + (entries (manifest-entries manifest)) + (rows (map entry->row entries))) + ;; Show most recently installed packages last. + (pretty-print-table (reverse rows)))) =20 (define (display-generation-change previous current) (format #t (G_ "switched from generation ~a to ~a~%") previous current)) --=20 2.32.0 --=-=-= Content-Type: text/plain Thanks, Maxim --=-=-=--