unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
* small hack to prettify output of list-installed
@ 2019-07-19  7:46 Robert Vollmert
  2019-07-19  8:32 ` Danny Milosavljevic
  0 siblings, 1 reply; 4+ messages in thread
From: Robert Vollmert @ 2019-07-19  7:46 UTC (permalink / raw)
  To: guix-devel

Hi,

here’s a small patch that calls “column -t” on the output of
`guix package --list-installed`. Probably not suitable for
inclusion since I assume the guix scripts shouldn’t depend
on `util-linux`, but I find it quite nice to have, so maybe
it’s useful to someone else.

Robert

From 1c6bf7e150445126448f1d5be4822889961f451f Mon Sep 17 00:00:00 2001
From: Robert Vollmert <rob@vllmrt.net>
Date: Fri, 19 Jul 2019 09:40:53 +0200
Subject: [PATCH] columnize list-installed and list-available

---
 guix/scripts/package.scm | 49 ++++++++++++++++++++++++----------------
 1 file changed, 30 insertions(+), 19 deletions(-)

diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm
index a43c96516f..ee7d16062b 100644
--- a/guix/scripts/package.scm
+++ b/guix/scripts/package.scm
@@ -43,6 +43,7 @@
                 #:select (directory-exists? mkdir-p))
   #:use-module (ice-9 format)
   #:use-module (ice-9 match)
+  #:use-module (ice-9 popen)
   #:use-module (ice-9 regex)
   #:use-module (ice-9 vlist)
   #:use-module (srfi srfi-1)
@@ -55,6 +56,7 @@
   #:autoload   (gnu packages base) (canonical-package)
   #:autoload   (gnu packages guile) (guile-2.2)
   #:autoload   (gnu packages bootstrap) (%bootstrap-guile)
+  #:autoload   (gnu packages linux) (util-linux)
   #:export (build-and-use-profile
             delete-generations
             delete-matching-generations
@@ -654,6 +656,11 @@ doesn't need it."
 ;;; Queries and actions.
 ;;;
 
+(define (columnize thunk)
+  (let ((port (open-output-pipe "column -t")))
+    (with-output-to-port port thunk)
+    (close-pipe port)))
+
 (define (process-query opts)
   "Process any query specified by OPTS.  Return #t when a query was actually
 processed, #f otherwise."
@@ -703,15 +710,17 @@ processed, #f otherwise."
               (manifest  (profile-manifest profile))
               (installed (manifest-entries manifest)))
          (leave-on-EPIPE
-          (for-each (match-lambda
-                      (($ <manifest-entry> 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)))
+          (columnize
+           (lambda ()
+             (for-each (match-lambda
+                         (($ <manifest-entry> 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)))))
          #t))
 
       (('list-available regexp)
@@ -734,16 +743,18 @@ 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 . _))
-                             (string<? name1 name2))))))
+          (columnize
+           (lambda ()
+             (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 . _))
+                                (string<? name1 name2))))))))
          #t))
 
       (('search _)
-- 
2.21.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: small hack to prettify output of list-installed
  2019-07-19  7:46 small hack to prettify output of list-installed Robert Vollmert
@ 2019-07-19  8:32 ` Danny Milosavljevic
  2019-07-19 16:21   ` Robert Vollmert
  0 siblings, 1 reply; 4+ messages in thread
From: Danny Milosavljevic @ 2019-07-19  8:32 UTC (permalink / raw)
  To: Robert Vollmert; +Cc: guix-devel

[-- Attachment #1: Type: text/plain, Size: 1277 bytes --]

Hi,

On Fri, 19 Jul 2019 09:46:15 +0200
Robert Vollmert <rob@vllmrt.net> wrote:

> here’s a small patch that calls “column -t” on the output of
> `guix package --list-installed`. Probably not suitable for
> inclusion since I assume the guix scripts shouldn’t depend
> on `util-linux`, but I find it quite nice to have, so maybe
> it’s useful to someone else.

For better or for worse we are on UNIX.  UNIX works best if programs
don't do weird special-processing like that by default - in order
not to break whatever pipe processing the user adds (IMO we do
way too much processing on our own already).

The user can always do

    guix ... | column -t

in a shell (or a guix wrapper shell script), right?

Moreover (and I can't believe I'm still arguing that), terminals have the
ability to set tab stops and there's no reason why the user wouldn't set
up tab stops.  Then this entire thing would be counterproductive.

I know, in practise almost nobody sets those up, but it's some strange NIH
stuff not to use those.  They are there, they are not broken, and they are
in order to make tables.

To set those up, use the "tabs" program.

$ tabs 1 10 50
$ echo -e 'hello\tbu\tba'
hello    bu                                      ba

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: small hack to prettify output of list-installed
  2019-07-19  8:32 ` Danny Milosavljevic
@ 2019-07-19 16:21   ` Robert Vollmert
  2019-07-22 14:25     ` Danny Milosavljevic
  0 siblings, 1 reply; 4+ messages in thread
From: Robert Vollmert @ 2019-07-19 16:21 UTC (permalink / raw)
  To: Danny Milosavljevic; +Cc: guix-devel

Hi Danny,

I don’t particularly care about this interface improvement making
it in, I’m ok with leaving things as they are. I do however feel
that some of the points made against deserve a reply.

On 19. Jul 2019, at 10:32, Danny Milosavljevic <dannym@scratchpost.org> wrote:
> On Fri, 19 Jul 2019 09:46:15 +0200
> Robert Vollmert <rob@vllmrt.net> wrote:
> 
>> here’s a small patch that calls “column -t” on the output of
>> `guix package --list-installed`. Probably not suitable for
>> inclusion since I assume the guix scripts shouldn’t depend
>> on `util-linux`, but I find it quite nice to have, so maybe
>> it’s useful to someone else.
> 
> For better or for worse we are on UNIX.  UNIX works best if programs
> don't do weird special-processing like that by default - in order
> not to break whatever pipe processing the user adds (IMO we do
> way too much processing on our own already).
> 
> The user can always do
> 
>    guix ... | column -t
> 
> in a shell (or a guix wrapper shell script), right?

Writing a shell script is tricky because that would involve argument
parsing. This shouldn’t apply to all guix subcommands, or even the
whole of “guix package”.

I can tell you how the “guix … | column -t” suggestion works out at best:
Users run “guix --list-installed”, see that the output is a mess, and run
it a second time, piping it into “column -t”. Then two weeks later, when
they do some package management things again, they go through the same
process again.

Hmm. What do you think about patching /bin/ls to not offer columnized
output, to encourage users to learn about /bin/column and friends?

> Moreover (and I can't believe I'm still arguing that), terminals have the
> ability to set tab stops and there's no reason why the user wouldn't set
> up tab stops.  Then this entire thing would be counterproductive.
> 
> I know, in practise almost nobody sets those up, but it's some strange NIH
> stuff not to use those.  They are there, they are not broken, and they are
> in order to make tables.
> 
> To set those up, use the "tabs" program.
> 
> $ tabs 1 10 50
> $ echo -e 'hello\tbu\tba'
> hello    bu                                      ba

That’s an interesting bit of shell / terminal knowledge, thanks for sharing!

Cheers
Robert

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: small hack to prettify output of list-installed
  2019-07-19 16:21   ` Robert Vollmert
@ 2019-07-22 14:25     ` Danny Milosavljevic
  0 siblings, 0 replies; 4+ messages in thread
From: Danny Milosavljevic @ 2019-07-22 14:25 UTC (permalink / raw)
  To: Robert Vollmert; +Cc: guix-devel

[-- Attachment #1: Type: text/plain, Size: 1125 bytes --]

Hi Robert,

> Hmm. What do you think about patching /bin/ls to not offer columnized
> output, to encourage users to learn about /bin/column and friends?

/bin/ls does turn off columnized output as soon as stdout is a pipe,
for composability.  Maybe that's a good middle ground (if a little
magical).

The power of UNIX (if there is any) comes from the composability of simple
tools so that you can build pipelines of stuff, in order to make the whole
do more than the parts.

Stuffing unrelated things into one executable flow breaks that paradigm
(if it can't be disabled).
Even when it can be disabled, it's kinda dirty to have to modeswitch each tool.

The downside of UNIX is that the stdout outputs have to be machine-readable
(and -parseable) by default, otherwise composition won't work right.

The terminal is supposed to do all of: soft wrapping, tabulation, line editing,
scrolling, windowing.  See also http://rtfm.etla.org/xterm/ctlseq.html

In the end it's not so bad to do it manually, but there are reasons it was
designed the way it is, and over the years those seem to be forgotten.

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-07-22 14:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-19  7:46 small hack to prettify output of list-installed Robert Vollmert
2019-07-19  8:32 ` Danny Milosavljevic
2019-07-19 16:21   ` Robert Vollmert
2019-07-22 14:25     ` Danny Milosavljevic

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).