Changeset 40548 in project


Ignore:
Timestamp:
09/14/21 00:47:13 (12 days ago)
Author:
Jim Ursetto
Message:

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

File:
1 edited

Legend:

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

    r40541 r40548  
    156156      (string-append "--" x)))
    157157 
     158(define (spaces n)
     159  (make-string n #\space))
     160
    158161;; O is an args:option
    159162;; Join together option names in O with commas, and append the
    160163;; argument type and name
    161 (define (spaces n)
    162   (let loop ((ls '()) (n n))
    163     (if (<= n 0)
    164         (list->string ls)
    165         (loop (cons #\space ls)
    166               (- n 1)))))
    167 
    168164(define (commify o)   ;; more at home in Stalin?
    169165  (let ((arg-type (lambda (args:o o-name)
     
    200196;;; parameter: args:width
    201197;; We don't auto-format the left column (the option keys) based on the length of the longest
    202 ;; option, but you can override it manually.
    203 ;;
     198;; option, but you can override it manually. The formatter maintains at least 2 spaces between
     199;; the option keys and the option docstrings; if there is not enough space, the docstring
     200;; will start on the next line. The 2 spaces of padding are included in args:width.
     201;; The indent does not get counted in args:width. So, the docstrings always begin at
     202;; column `args:width + args:indent`.
     203
    204204;; Example: (parameterize ((args:width 40)) (args:usage opts))
    205205(define args:width (make-parameter 25))
     
    212212;; O is an args:option
    213213(define (usage-line o)
    214   (let ((option-string (commify o)))
     214  (let ((option-string (commify o))
     215        (kvpad 2)) ; minimum padding between option and docstring, included in args:width
    215216    (string-append (spaces (args:indent))
    216                   (if (>= (+ (args:indent) (string-length option-string))
     217                   (if (> (+ kvpad (string-length option-string))
    217218                          (args:width))
    218                       (string-append option-string "\n"
    219                                      (string-pad-right "" (+ (args:width)
    220                                                              (args:indent)))
    221                                      (args:option-docstring o) "\n")
    222                       (string-append
    223                        (string-pad-right option-string (args:width))
    224                        (args:option-docstring o) "\n")))))
     219                       (string-append option-string "\n"
     220                                      (spaces (+ (args:width)
     221                                                 (args:indent)))
     222                                      (args:option-docstring o) "\n")
     223                       (string-append
     224                        (string-pad-right option-string (args:width))
     225                        (args:option-docstring o) "\n")))))
    225226
    226227;;; procedure: (args:usage OPTION-LIST)
Note: See TracChangeset for help on using the changeset viewer.