raco pkg show: add -l'/--long', and adjust the default mode

Make `raco pkg show` more readable by default by constraining the
output to 80 characters and adjusting the way some columns print.
This commit is contained in:
Matthew Flatt 2014-11-30 13:46:59 -07:00
parent 3cc1514a7d
commit 3638ee6129
11 changed files with 138 additions and 42 deletions

View File

@ -664,7 +664,9 @@ package is created.
@subcommand{@command/toc{show} @nonterm{option} ... --- Print information about currently installed packages.
By default, packages are shown for all @tech{package scopes}, but only for packages
not marked as auto-installed to fulfill dependencies.
not marked as auto-installed to fulfill dependencies. Unless @Flag{l} or @DFlag{long} is specified,
the output is roughly constrained to 80 columns or the number of columns specified by the @envvar{COLUMNS}
environment variable.
The @exec{show} sub-command accepts
the following @nonterm{option}s:
@ -672,6 +674,8 @@ package is created.
@itemlist[
@item{@Flag{a} or @DFlag{all} --- Includes auto-installed packages in the listing.}
@item{@Flag{l} or @DFlag{long} --- Show complete columns, instead of abbreviating to a width,
and use a more regular (but less human-readable) format for some columns.}
@item{@Flag{d} or @DFlag{dir} --- Adds a column in the output for the directory where the package is installed.}
@item{@DFlag{scope} @nonterm{scope} --- Shows only packages in @nonterm{scope}, which is one of
@ -686,7 +690,9 @@ package is created.
@item{@DFlag{scope-dir} @nonterm{dir} --- Shows only packages installed in @nonterm{dir}.}
@item{@DFlag{version} @nonterm{vers} or @Flag{v} @nonterm{vers} --- Show only user-specific packages for
the installation name/version @nonterm{vers}.}
]}
]
@history[#:changed "6.1.1.5" @elem{Added @Flag{l}/@DFlag{--long} and @envvar{COLUMNS} support.}]}
@subcommand{@command/toc{migrate} @nonterm{option} ... @nonterm{from-version}
--- Installs packages that were previously installed in @exec{user}

View File

@ -14,7 +14,7 @@
(shelly-case
"failure on remove"
$ "raco pkg install test-pkgs/pkg-test1.zip" =exit> 0
$ "raco pkg show -u -a -d" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source +Directory\npkg-test1 +[a-f0-9]+ .*pkg-test1\n"
$ "raco pkg show -l -u -a -d" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source +Directory\npkg-test1 +[a-f0-9]+ .*pkg-test1\"\n"
$ "racket -e '(require pkg-test1)'" =exit> 0
$ "racket -e '(file-or-directory-permissions (collection-path \"pkg-test1\") #o500)'"
$ "raco pkg remove pkg-test1" =exit> 1
@ -23,7 +23,7 @@
(shelly-case
"re-install must go to \"+1\""
$ "raco pkg install test-pkgs/pkg-test1.zip" =exit> 0
$ "raco pkg show -u -a -d" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source +Directory\npkg-test1 +[a-f0-9]+ .*pkg-test1[+]1\n"
$ "raco pkg show -l -u -a -d" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source +Directory\npkg-test1 +[a-f0-9]+ .*pkg-test1[+]1\"\n"
$ "racket -e '(require pkg-test1)'" =exit> 0
$ "raco pkg remove pkg-test1" =exit> 0
$ "racket -e '(require pkg-test1)'" =exit> 1)
@ -32,6 +32,6 @@
"re-install can go back to original place"
$ "racket -l racket/base -l setup/dirs -e '(file-or-directory-permissions (build-path (find-user-pkgs-dir) \"pkg-test1/pkg-test1\") #o700)'"
$ "raco pkg install test-pkgs/pkg-test1.zip" =exit> 0
$ "raco pkg show -u -a -d" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source +Directory\npkg-test1 +[a-f0-9]+ .*pkg-test1\n"
$ "raco pkg show -l -u -a -d" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source +Directory\npkg-test1 +[a-f0-9]+ .*pkg-test1\"\n"
$ "racket -e '(require pkg-test1)'" =exit> 0
$ "raco pkg remove pkg-test1" =exit> 0))))

View File

@ -22,12 +22,12 @@
'source
"http://localhost:9997/pkg-a-first.plt"))
$ "raco pkg install -u --deps search-auto pkg-b" =exit> 0
$ "raco pkg show -u -a" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-a\\* +[a-f0-9]+ \\(catalog pkg-a\\)\npkg-b +[a-f0-9]+ +\\(catalog pkg-b\\)\n"
$ "raco pkg show -l -u -a" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-a\\* +[a-f0-9]+ \\(catalog \"pkg-a\"\\)\npkg-b +[a-f0-9]+ +\\(catalog \"pkg-b\"\\)\n"
$ (~a "racket"
" -e \"(require racket/file setup/dirs)\""
" -e \"(copy-directory/files (build-path (find-system-path 'addon-dir) (get-installation-name))"
" (build-path (find-system-path 'addon-dir) (symbol->string 'other)))\"")
$ "raco pkg remove -u --auto pkg-b"
$ "raco pkg show -u -a" =stdout> " [none]\n"
$ "raco pkg show -l -u -a" =stdout> " [none]\n"
$ "raco pkg migrate -u other"
$ "raco pkg show -u -a" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-a\\* +[a-f0-9]+ \\(catalog pkg-a\\)\npkg-b +[a-f0-9]+ +\\(catalog pkg-b\\)\n")))
$ "raco pkg show -l -u -a" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-a\\* +[a-f0-9]+ \\(catalog \"pkg-a\"\\)\npkg-b +[a-f0-9]+ +\\(catalog \"pkg-b\"\\)\n")))

View File

@ -15,37 +15,37 @@
"promote"
$ "raco pkg config --set catalogs http://localhost:9990"
$ "raco pkg install --deps search-auto test-pkgs/pkg-test2.zip" =exit> 0
$ "raco pkg show -u -a" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-test1\\* +[a-f0-9]+ +\\(catalog pkg-test1\\)\npkg-test2 +[a-f0-9]+ +\\(file .+tests/pkg/test-pkgs/pkg-test2.zip\\)\n"
$ "raco pkg show -l -u -a" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-test1\\* +[a-f0-9]+ +\\(catalog \"pkg-test1\"\\)\npkg-test2 +[a-f0-9]+ +\\(file .+tests/pkg/test-pkgs/pkg-test2.zip\"\\)\n"
$ "raco pkg install test-pkgs/pkg-test2.zip" =exit> 1 =stderr> #rx"already installed"
$ "raco pkg install test-pkgs/pkg-test1.zip" =exit> 1 =stderr> #rx"already installed from a different source"
$ "raco pkg install pkg-test1" ; promote
$ "raco pkg show -u -a" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-test1 +[a-f0-9]+ +\\(catalog pkg-test1\\)\npkg-test2 +[a-f0-9]+ +\\(file .+tests/pkg/test-pkgs/pkg-test2.zip\\)\n"
$ "raco pkg show -l -u -a" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-test1 +[a-f0-9]+ +\\(catalog \"pkg-test1\"\\)\npkg-test2 +[a-f0-9]+ +\\(file .+tests/pkg/test-pkgs/pkg-test2.zip\"\\)\n"
$ "raco pkg install pkg-test1" =exit> 1 =stderr> #rx"already installed" ; redundant promote fails
$ "racket -e '(require pkg-test1)'" =exit> 0
$ "racket -e '(require pkg-test2)'" =exit> 0
$ "raco pkg remove --auto pkg-test1" =exit> 1 =stderr> #rx"cannot remove packages that are dependencies of other packages"
$ "raco pkg remove --auto pkg-test2"
$ "raco pkg show -u -a" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-test1 +[a-f0-9]+ +\\(catalog pkg-test1\\)"
$ "raco pkg show -l -u -a" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-test1 +[a-f0-9]+ +\\(catalog \"pkg-test1\"\\)"
$ "raco pkg remove --auto pkg-test1"
$ "raco pkg show -u -a" =stdout> " [none]\n")
$ "raco pkg show -l -u -a" =stdout> " [none]\n")
(shelly-case
"demote"
$ "raco pkg config --set catalogs http://localhost:9990"
$ "raco pkg install --deps search-auto test-pkgs/pkg-test2.zip" =exit> 0
$ "raco pkg show -u -a" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-test1\\* +[a-f0-9]+ +\\(catalog pkg-test1\\)\npkg-test2 +[a-f0-9]+ +\\(file .+tests/pkg/test-pkgs/pkg-test2.zip\\)\n"
$ "raco pkg show -l -u -a" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-test1\\* +[a-f0-9]+ +\\(catalog \"pkg-test1\"\\)\npkg-test2 +[a-f0-9]+ +\\(file .+tests/pkg/test-pkgs/pkg-test2.zip\"\\)\n"
$ "raco pkg remove --demote pkg-test2"
$ "raco pkg show -u -a" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-test1\\* +[a-f0-9]+ +\\(catalog pkg-test1\\)\npkg-test2\\* +[a-f0-9]+ +\\(file .+tests/pkg/test-pkgs/pkg-test2.zip\\)\n"
$ "raco pkg show -l -u -a" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-test1\\* +[a-f0-9]+ +\\(catalog \"pkg-test1\"\\)\npkg-test2\\* +[a-f0-9]+ +\\(file .+tests/pkg/test-pkgs/pkg-test2.zip\"\\)\n"
$ "racket -e '(require pkg-test1)'" =exit> 0
$ "racket -e '(require pkg-test2)'" =exit> 0
$ "raco pkg remove --auto"
$ "raco pkg show -u -a" =stdout> " [none]\n"))
$ "raco pkg show -l -u -a" =stdout> " [none]\n"))
(with-fake-root
(shelly-case
"demote+auto"
$ "raco pkg config --set catalogs http://localhost:9990"
$ "raco pkg install --deps search-auto test-pkgs/pkg-test2.zip" =exit> 0
$ "raco pkg show -u -a" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-test1\\* +[a-f0-9]+ +\\(catalog pkg-test1\\)\npkg-test2 +[a-f0-9]+ +\\(file .+tests/pkg/test-pkgs/pkg-test2.zip\\)\n"
$ "raco pkg show -l -u -a" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-test1\\* +[a-f0-9]+ +\\(catalog \"pkg-test1\"\\)\npkg-test2 +[a-f0-9]+ +\\(file .+tests/pkg/test-pkgs/pkg-test2.zip\"\\)\n"
$ "raco pkg remove --demote --auto pkg-test1" =exit> 0 ; should have no effect
$ "raco pkg show -u -a" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-test1\\* +[a-f0-9]+ +\\(catalog pkg-test1\\)\npkg-test2 +[a-f0-9]+ +\\(file .+tests/pkg/test-pkgs/pkg-test2.zip\\)\n"
$ "raco pkg show -l -u -a" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-test1\\* +[a-f0-9]+ +\\(catalog \"pkg-test1\"\\)\npkg-test2 +[a-f0-9]+ +\\(file .+tests/pkg/test-pkgs/pkg-test2.zip\"\\)\n"
$ "raco pkg remove --demote --auto pkg-test2"
$ "raco pkg show -u -a" =stdout> " [none]\n"))))
$ "raco pkg show -l -u -a" =stdout> " [none]\n"))))

View File

@ -20,7 +20,7 @@
(shelly-case
"remove and show"
(shelly-case "remove of not installed package fails"
$ "raco pkg show -u -a" =stdout> " [none]\n"
$ "raco pkg show -l -u -a" =stdout> " [none]\n"
$ "raco pkg remove not-there" =exit> 1)
(shelly-case "remove of bad name"
$ "raco pkg remove bad/" =exit> 1
@ -35,12 +35,12 @@
"pkg-test1 pkg-test1")
(shelly-install "remove of dep fails"
"test-pkgs/pkg-test1.zip"
$ "raco pkg show -u -a" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-test1 +[a-f0-9]+ +\\(file .+tests/pkg/test-pkgs/pkg-test1.zip\\)\n"
$ "raco pkg show -l -u -a" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-test1 +[a-f0-9]+ +\\(file .+tests/pkg/test-pkgs/pkg-test1.zip\"\\)\n"
$ "raco pkg install test-pkgs/pkg-test2.zip"
$ "raco pkg show -u -a" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-test1 +[a-f0-9]+ +\\(file .+tests/pkg/test-pkgs/pkg-test1.zip\\)\npkg-test2 +[a-f0-9]+ +\\(file .+tests/pkg/test-pkgs/pkg-test2.zip\\)\n"
$ "raco pkg show -l -u -a" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-test1 +[a-f0-9]+ +\\(file .+tests/pkg/test-pkgs/pkg-test1.zip\"\\)\npkg-test2 +[a-f0-9]+ +\\(file .+tests/pkg/test-pkgs/pkg-test2.zip\"\\)\n"
$ "raco pkg remove pkg-test1" =exit> 1 =stderr> #rx"pkg-test1 \\(required by: \\(pkg-test2\\)\\)"
$ "raco pkg remove pkg-test2"
$ "raco pkg show -u -a" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-test1 +[a-f0-9]+ +\\(file .+tests/pkg/test-pkgs/pkg-test1.zip\\)\n")
$ "raco pkg show -l -u -a" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-test1 +[a-f0-9]+ +\\(file .+tests/pkg/test-pkgs/pkg-test1.zip\"\\)\n")
(shelly-install "remove of dep can be forced"
"test-pkgs/pkg-test1.zip"
$ "raco pkg install test-pkgs/pkg-test2.zip"
@ -68,22 +68,22 @@
$ "racket -e '(require pkg-test1)'" =exit> 1
$ "racket -e '(require pkg-test2)'" =exit> 1
$ "raco pkg install --deps search-auto test-pkgs/pkg-test2.zip" =exit> 0
$ "raco pkg show -u -a" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-test1\\* +[a-f0-9]+ +\\(catalog pkg-test1\\)\npkg-test2 +[a-f0-9]+ +\\(file .+tests/pkg/test-pkgs/pkg-test2.zip\\)\n"
$ "raco pkg show -l -u -a" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-test1\\* +[a-f0-9]+ +\\(catalog \"pkg-test1\"\\)\npkg-test2 +[a-f0-9]+ +\\(file .+tests/pkg/test-pkgs/pkg-test2.zip\"\\)\n"
$ "racket -e '(require pkg-test1)'" =exit> 0
$ "racket -e '(require pkg-test2)'" =exit> 0
$ "racket -e '(require pkg-test2/contains-dep)'" =exit> 0
$ "raco pkg remove pkg-test2"
$ "raco pkg show -u -a" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-test1\\* +[a-f0-9]+ +\\(catalog pkg-test1\\)\n"
$ "raco pkg show -l -u -a" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-test1\\* +[a-f0-9]+ +\\(catalog \"pkg-test1\"\\)\n"
$ "racket -e '(require pkg-test1)'" =exit> 0
$ "raco pkg remove --auto"
$ "raco pkg show -u -a" =stdout> " [none]\n"
$ "raco pkg show -l -u -a" =stdout> " [none]\n"
$ "racket -e '(require pkg-test1)'" =exit> 1
$ "racket -e '(require pkg-test2)'" =exit> 1)
(shelly-case
"single-step autoremove"
$ "raco pkg install --deps search-auto test-pkgs/pkg-test2.zip" =exit> 0
$ "raco pkg remove --auto pkg-test2"
$ "raco pkg show -u -a" =stdout> " [none]\n"
$ "raco pkg show -l -u -a" =stdout> " [none]\n"
$ "racket -e '(require pkg-test1)'" =exit> 1
$ "racket -e '(require pkg-test2)'" =exit> 1)
(shelly-case
@ -92,7 +92,7 @@
$ "racket -e '(require pkg-cycle1)'" =exit> 0
$ "racket -e '(require pkg-cycle2)'" =exit> 0
$ "raco pkg remove --auto pkg-cycle1"
$ "raco pkg show -u -a" =stdout> " [none]\n"
$ "raco pkg show -l -u -a" =stdout> " [none]\n"
$ "racket -e '(require pkg-cycle1)'" =exit> 1
$ "racket -e '(require pkg-cycle2)'" =exit> 1))
(with-fake-root

View File

@ -48,12 +48,12 @@
'source
"http://localhost:9997/pkg-a-first.plt"))
$ "raco pkg install --deps search-auto pkg-b" =exit> 0 <input= "y\n"
$ "raco pkg show -u -a" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-a\\* +[a-f0-9]+ \\(catalog pkg-a\\)\npkg-b +[a-f0-9]+ +\\(catalog pkg-b\\)\n"
$ "raco pkg show -l -u -a" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-a\\* +[a-f0-9]+ \\(catalog \"pkg-a\"\\)\npkg-b +[a-f0-9]+ +\\(catalog \"pkg-b\"\\)\n"
$ "racket -e '(require pkg-b)'" =exit> 43
$ "racket -e '(require pkg-a)'" =exit> 0
;; remove auto doesn't do anything because everything is needed
$ "raco pkg remove -u --auto"
$ "raco pkg show -u -a" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-a\\* +[a-f0-9]+ \\(catalog pkg-a\\)\npkg-b +[a-f0-9]+ +\\(catalog pkg-b\\)\n"
$ "raco pkg show -l -u -a" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-a\\* +[a-f0-9]+ \\(catalog \"pkg-a\"\\)\npkg-b +[a-f0-9]+ +\\(catalog \"pkg-b\"\\)\n"
$ "racket -e '(require pkg-b)'" =exit> 43
$ "racket -e '(require pkg-a)'" =exit> 0
;; pkg-a is now an auto
@ -65,9 +65,9 @@
$ "raco pkg update -a" =exit> 0
$ "racket -e '(require pkg-a)'" =exit> 43
$ "raco pkg remove pkg-b"
$ "raco pkg show -u -a" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-a\\* +[a-f0-9]+ +\\(catalog pkg-a\\)\n"
$ "raco pkg show -l -u -a" =stdout> #rx"Package\\[\\*=auto\\] +Checksum +Source\npkg-a\\* +[a-f0-9]+ +\\(catalog \"pkg-a\"\\)\n"
$ "racket -e '(require pkg-b)'" =exit> 1
;; pkg-a is now not needed
$ "raco pkg remove --auto"
$ "raco pkg show -u -a" =stdout> " [none]\n"
$ "raco pkg show -l -u -a" =stdout> " [none]\n"
$ "racket -e '(require pkg-a)'" =exit> 1)))

View File

@ -118,6 +118,7 @@
[pkg-show
(->* (string?)
(#:directory? boolean?
#:long? boolean?
#:auto? boolean?)
void?)]
[pkg-install

View File

@ -373,8 +373,11 @@
;; ----------------------------------------
[show
"Show information about installed packages"
#:usage-help
"Set the COLUMNS environment variable to configure the output without `-l'."
#:once-each
[#:bool all ("-a") "Show auto-installed packages, too"]
[#:bool long ("-l") "Show full column content"]
[#:bool dir ("-d") "Show the directory where the package is installed"]
#:once-any
scope-flags ...
@ -410,6 +413,7 @@
(with-pkg-lock/read-only
(pkg-show (if only-mode "" " ")
#:auto? all
#:long? long
#:directory? dir)))))]
;; ----------------------------------------
[migrate

View File

@ -272,7 +272,7 @@
" Your current installation is a directory link, and the directory might\n"
" be a Git repostory checkout, but the package system doesn't know that.\n"
" If so, try\n"
" cd " (normalize-path
" cd " (simple-form-path
(path->complete-path (cadr current-orig-pkg) (pkg-installed-dir)))
"\n"
" raco pkg update --clone . <repository-URL>")]

View File

@ -998,7 +998,7 @@
" package name: ~a\n"
" package source: ~a")
pkg-name
(normalize-path
(simple-form-path
(path->complete-path orig-pkg-dir (pkg-installed-dir))))
null)]
[`(dir ,_)

View File

@ -3,14 +3,17 @@
racket/match
racket/format
racket/function
racket/path
"../path.rkt"
"dirs.rkt"
"pkg-db.rkt")
(provide pkg-show)
(define (pkg-show indent
#:directory? [dir? #f]
#:auto? [show-auto? #f])
#:auto? [show-auto? #f]
#:long? [long? #t])
(let ()
(define db (read-pkg-db))
(define pkgs (sort (hash-keys db) string-ci<=?))
@ -18,6 +21,11 @@
(printf " [none]\n")
(begin
(table-display
long?
(append '(right right middle)
(if dir?
'(left)
'()))
(list*
(append
(list (format "~aPackage~a"
@ -37,10 +45,28 @@
indent
pkg
(if auto? "*" ""))
(format "~a" checksum)
(format "~a" orig-pkg))
(if (or checksum long?)
(format "~a" checksum)
"")
(let ([src (case (car orig-pkg)
[(link static-link clone)
(list* (car orig-pkg)
(path->string
(simple-form-path
(path->complete-path (cadr orig-pkg)
(pkg-installed-dir))))
(cddr orig-pkg))]
[else orig-pkg])])
(if long?
(~s src)
(apply ~a #:separator " " src))))
(if dir?
(list (~a (pkg-directory* pkg #:db db)))
(let ([p (path->string
(simple-form-path
(pkg-directory* pkg #:db db)))])
(list (if long?
(~s p)
(~a p))))
empty)))))
(unless show-auto?
(define n (for/sum ([pkg (in-list pkgs)]
@ -52,18 +78,77 @@
n
(if (= n 1) "" "s"))))))))
(define (table-display l)
(define (table-display long? dots-poses l)
(define how-many-cols (length (first l)))
(define max-widths
(define full-max-widths
(for/list ([col (in-range how-many-cols)])
(apply max (map (compose string-length (curryr list-ref col)) l))))
(define sep (if long? 4 2))
(define COLUMNS (or (cond
[long? 80]
[(getenv "COLUMNS")
=> (lambda (s)
(define v (string->number s))
(and (exact-positive-integer? v) v))]
[else #f])
80))
(define max-widths
(cond
[(or long?
((apply + full-max-widths) . < . (- COLUMNS (* sep (sub1 how-many-cols)))))
full-max-widths]
[else
(define avail (- COLUMNS
(car full-max-widths)
(* sep (sub1 how-many-cols))))
(cons (car full-max-widths)
(for/list ([c (in-list (cdr full-max-widths))]
[i (in-naturals 1)])
(define frac
;; Give last column twice the space:
(if (= i (sub1 how-many-cols))
(/ 2 how-many-cols)
(/ 1 how-many-cols)))
(max 3
(floor (* avail frac)))))]))
(for ([row (in-list l)])
(for ([col (in-list row)]
[i (in-naturals 1)]
[width (in-list max-widths)])
[width (in-list max-widths)]
[dots-pos (in-list dots-poses)])
(define col-width (string-length col))
(printf "~a~a"
col
(if (col-width . <= . width)
col
(case dots-pos
[(right)
;; Checksum: show prefix:
(~a (substring col 0 (- width 3))
"...")]
[(middle)
;; Source
;; To start "..." at a space:
(define m (regexp-match-positions #rx" " col))
(define left
(cond
[(and m
((caar m) . < . (- width 3)))
;; Dots at space:
(caar m)]
[else
;; Put dots in middle:
(quotient (- width 3) 2)]))
(~a (substring col 0 left)
"..."
(substring col (+ (- col-width width)
3 left)))]
[(left)
;; Put dots at start:
(~a "..."
(substring col (min col-width (- col-width width -3))))]))
(if (= i how-many-cols)
""
(make-string (+ (- width (string-length col)) 4) #\space))))
(let ([len (min (string-length col)
width)])
(make-string (+ (- width len) sep) #\space)))))
(printf "\n")))