Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed alignment of options in descriptions. #21

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 40 additions & 20 deletions unix-opts.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -394,37 +394,57 @@ to `nil')"
prefixed with PADDING spaces. If NEWLINE is non-NIL, newline character will
be prepended to the text making it start on the next line with padding
applied to every single line."
(let ((pad (make-string padding :initial-element #\Space)))
(let ((pad (make-string padding :initial-element #\Space))
(pad-next-lines (make-string (max 0 (1- padding)) :initial-element #\Space)))
(with-output-to-string (s)
(when newline
(format s "~&~a" pad))
(format s "~%~a" pad))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This used to only output a newline when the output wasn't already at a newline, however as this is an empyt stream (we just created it on line 399) this would never output a newline.

(map nil
(lambda (x)
(write-char x s)
(when (char= x #\Newline)
(write pad :stream s :escape nil)))
(write pad-next-lines :stream s :escape nil)))
str))))

(defun print-opts (&optional (stream *standard-output*))
"Print info about defined options to STREAM. Every option get its own line
with description."
(dolist (opt *options*)
(with-slots (short long description required arg-parser meta-var) opt
(let ((opts-and-meta
(concatenate
'string
(if short (format nil "-~c" short) "")
(if (and short long) ", " "")
(if long (format nil "--~a" long) "")
(if arg-parser (format nil " ~a" meta-var) "")
(if required (format nil " (Required)") ""))))
(format stream " ~25a~a~%"
opts-and-meta
(add-text-padding
description
:padding 27
:newline (>= (length opts-and-meta) 25))))))
(terpri stream))
(flet ((pad-right (string max-size)
(concatenate 'string
string
(make-string (- max-size
(length string))
:initial-element #\Space))))
(let ((max-opts-length -1)
(all-opts-meta ())
(all-opts-descriptions ()))
(dolist (opt *options*)
(with-slots (short long description required arg-parser meta-var) opt
(let ((opts-and-meta
(concatenate
'string
(if short (format nil "-~c" short) "")
(if (and short long) ", " "")
(if long (format nil "--~a" long) "")
(if arg-parser (format nil " ~a" meta-var) "")
(if required (format nil " (Required)") ""))))
(push opts-and-meta all-opts-meta)
(push description all-opts-descriptions)
(when (> (length opts-and-meta)
max-opts-length)
(setf max-opts-length
(length opts-and-meta))))))
(setf max-opts-length (+ 1 max-opts-length))
(loop
for opt-meta in all-opts-meta
for opt-description in all-opts-descriptions do
(format stream " ~a~a~%"
(pad-right opt-meta max-opts-length)
(add-text-padding opt-description
:padding (+ 2 max-opts-length)
:newline (>= (length opt-meta)
25))))
(terpri stream))))

(defun print-opts* (margin)
"Return a string containing info about defined options. All options are
Expand Down