From 238d56a8dc7614813af3ed36bc6e5c51a6290c15 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 31 May 2015 11:52:46 -0600 Subject: libremessages:flag: support sub-headings in the list of flags. This changes libremessages:flag to treat would-be flagnames ending with ':' specially--as a sub-heading in the list of flags. The next argument is taken to be the next flag, not a description. --- src/lib/libremessages | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/lib/libremessages b/src/lib/libremessages index 151674b..528d9b6 100755 --- a/src/lib/libremessages +++ b/src/lib/libremessages @@ -110,16 +110,20 @@ bullet() { # the descriptions are all alligned together. flag() { [[ $# == $(($#/2*2)) ]] || panic - local args=("$@") + declare -i flaglen=0 - declare -i i=0 - while [[ $i -lt $# ]]; do - if [[ ${#args[i]} -gt $flaglen ]]; then - flaglen=${#args[$i]} + while [[ $# -gt 0 ]]; do + if [[ $1 == *: ]]; then + shift 1 + else + if [[ ${#1} -gt $flaglen ]]; then + flaglen=${#1} + fi + shift 2 fi - i+=2 done + set -- "${args[@]}" # Unless the $flaglen is extra-wide, the $desc should start at # column 16 (that is two literal-tabs). If $flaglen is wide, @@ -140,14 +144,19 @@ flag() { printf -v fmt1 " %-${indent}s %%s\n" '' while [[ $# -gt 0 ]]; do - local flag=$1 - local desc="$(_ "$(whitespace_collapse <<<"$2")")" - shift 2 - - local lines - IFS=$'\n' lines=($(fmt -u -w $((71-indent)) <<<"$desc")) - printf -- "$fmt2" "$flag" "${lines[0]}" - [[ ${#lines[@]} -lt 2 ]] || printf -- "$fmt1" "${lines[@]:1}" + if [[ $1 == *: ]]; then + printf -- ' %s\n' "$(_ "$1")" + shift + else + local flag=$1 + local desc="$(_ "$(whitespace_collapse <<<"$2")")" + shift 2 + + local lines + IFS=$'\n' lines=($(fmt -u -w $((71-indent)) <<<"$desc")) + printf -- "$fmt2" "$flag" "${lines[0]}" + [[ ${#lines[@]} -lt 2 ]] || printf -- "$fmt1" "${lines[@]:1}" + fi done } -- cgit v1.2.2