chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Make the args egg stop truncating long options in args:usage


From: T . Kurt Bond
Subject: Make the args egg stop truncating long options in args:usage
Date: Thu, 09 Sep 2021 16:00:53 -0400
User-agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (Gojō) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.2 (x86_64-apple-darwin18.7.0) MULE/6.0 (HANACHIRUSATO)

[Should I be asking this question on chicken-hackers instead of here?]

Right now, when you use the args egg's args:usage function to display
a usage message, it truncates long option displays.  For instance,
here's the output of args:usage for a program I'm working on now:

========== args:usage output ==================================================
 -c, --complications=NUMBEnumber of complications (Default: 1)
 -h, --help               Display this text
 -n, --number=NUMBER      generate NUMBER ideas (Default: 1)
 -p, --plot-map           Output plot map mission instead of simple mission.
                          (Default: OFF/NO)
 -S, --separator-length=NUlength of separator (Default: 72)
 -s, --separator          Toggle separator between missions. (Default: ON/YES)
 -R, --randomness         Add extra randomness to plot map. (Default: OFF/NO)
 -r, --rest               Toggle output as reStructuredText. (Default: OFF/NO)
========== End of args:usage output ===========================================

Notice that on the lines that start with -c and -S the option display
is truncated.

I know that you can parameterize args:width to change the width of the
options display, but wouldn't it be better to NOT truncate things if
args:width is too narrow, and instead output the whole option display,
end the line, and then output the docstring on the next line, like
this:

========== better args:usage output ===========================================
 -c, --complications=NUMBER
                          number of complications (Default: 1)
 -h, --help               Display this text
 -n, --number=NUMBER      generate NUMBER ideas (Default: 1)
 -p, --plot-map           Output plot map mission instead of simple mission.
                          (Default: OFF/NO)
 -S, --separator-length=NUMBER
                          length of separator (Default: 72)
 -s, --separator          Toggle separator between missions. (Default: ON/YES)
 -R, --randomness         Add extra randomness to plot map. (Default: OFF/NO)
 -r, --rest               Toggle output as reStructuredText. (Default: OFF/NO)
========== End of better args:usage output ====================================


Here's a possible patch:

========== wide-options-display.patch =========================================
Index: args.scm
===================================================================
--- args.scm    (revision 40507)
+++ args.scm    (working copy)
@@ -213,8 +213,15 @@
 (define (usage-line o)
   (let ((option-string (commify o)))
     (string-append (spaces (args:indent))
-                   (string-pad-right option-string (args:width))
-                   (args:option-docstring o) "\n")))
+                  (if (>= (+ (args:indent) (string-length option-string))
+                          (args:width))
+                      (string-append option-string "\n"
+                                     (string-pad-right "" (+ (args:width)
+                                                             (args:indent)))
+                                     (args:option-docstring o) "\n")
+                      (string-append
+                       (string-pad-right option-string (args:width))
+                       (args:option-docstring o) "\n")))))
 
 ;;; procedure: (args:usage OPTION-LIST)
 ;; Generate a formatted list of options from OPTION-LIST,
========== End of wide-options-display.patch ==================================


-- 
T. Kurt Bond, tkurtbond@gmail.com, tkurtbond.github.io and tkb.tx0.org



reply via email to

[Prev in Thread] Current Thread [Next in Thread]