Changeset 40551 in project


Ignore:
Timestamp:
09/14/21 00:49:32 (9 days ago)
Author:
Jim Ursetto
Message:

4/args: Ensure long option wrapping works when args:indent != 1

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release/4/args/trunk/args.scm

    r40540 r40551  
    150150      (string-append "--" x)))
    151151 
     152(define (spaces n)
     153  (make-string n #\space))
     154
    152155;; O is an args:option
    153156;; Join together option names in O with commas, and append the
    154157;; argument type and name
    155 (define (spaces n)
    156   (let loop ((ls '()) (n n))
    157     (if (<= n 0)
    158         (list->string ls)
    159         (loop (cons #\space ls)
    160               (- n 1)))))
    161 
    162158(define (commify o)   ;; more at home in Stalin?
    163159  (let ((arg-type (lambda (args:o o-name)
     
    194190;;; parameter: args:width
    195191;; We don't auto-format the left column (the option keys) based on the length of the longest
    196 ;; option, but you can override it manually.
    197 ;;
     192;; option, but you can override it manually. The formatter maintains at least 2 spaces between
     193;; the option keys and the option docstrings; if there is not enough space, the docstring
     194;; will start on the next line. The 2 spaces of padding are included in args:width.
     195;; The indent does not get counted in args:width. So, the docstrings always begin at
     196;; column `args:width + args:indent`.
     197
    198198;; Example: (parameterize ((args:width 40)) (args:usage opts))
    199199(define args:width (make-parameter 25))
     
    206206;; O is an args:option
    207207(define (usage-line o)
    208   (let ((option-string (commify o)))
     208  (let ((option-string (commify o))
     209        (kvpad 2)) ; minimum padding between option and docstring, included in args:width
    209210    (string-append (spaces (args:indent))
    210                   (if (>= (+ (args:indent) (string-length option-string))
     211                   (if (> (+ kvpad (string-length option-string))
    211212                          (args:width))
    212                       (string-append option-string "\n"
    213                                      (string-pad-right "" (+ (args:width)
    214                                                              (args:indent)))
    215                                      (args:option-docstring o) "\n")
    216                       (string-append
    217                        (string-pad-right option-string (args:width))
    218                        (args:option-docstring o) "\n")))))
     213                       (string-append option-string "\n"
     214                                      (spaces (+ (args:width)
     215                                                 (args:indent)))
     216                                      (args:option-docstring o) "\n")
     217                       (string-append
     218                        (string-pad-right option-string (args:width))
     219                        (args:option-docstring o) "\n")))))
    219220
    220221;;; procedure: (args:usage OPTION-LIST)
Note: See TracChangeset for help on using the changeset viewer.