From 434dbea55773bbdcf903d22c08d6963c061ccdfb Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 1 Jul 2014 16:11:45 -0400 Subject: libremessages: tidy up --- src/lib/libremessages | 18 ++++++++---------- src/lib/libremessages.1.ronn | 14 +++++++------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/lib/libremessages b/src/lib/libremessages index db2fdde..f75bd4a 100755 --- a/src/lib/libremessages +++ b/src/lib/libremessages @@ -47,7 +47,7 @@ panic() { exit 1 } -# Usage: print MESG ARG1 ARG2... +# Usage: print MESG [ARGS...] # Like printf, but gettext-aware, and prints a trailing newline print() { [[ $# -ge 1 ]] || panic @@ -58,28 +58,28 @@ print() { # Do HTML-style whitespace collapsing on standard IO. # It considers newline, tab, and space to be whitespace. -_html_whitespace_collapse() { +_libremessages_html_whitespace_collapse() { [[ $# == 0 ]] || panic tr '\n' ' ' | sed -r -e 's/\t/ /g' -e 's/ +/ /g' } -# Usage: prose MESG +# Usage: prose MESG [ARGS...] # Do HTML-style whitespace collapsing on the first argument, translate it # (gettext), then word-wrap it to 75 columns. # This is useful for printing a paragraph of prose in --help text. prose() { [[ $# -ge 1 ]] || panic - local mesg="$(_ "$(_html_whitespace_collapse <<<"$1")")"; shift + local mesg="$(_ "$(_libremessages_html_whitespace_collapse <<<"$1")")"; shift printf -- "$mesg" "$@" | fmt -u } -# Usage: bullet MESG +# Usage: bullet MESG [ARGS...] # Like prose, but print a bullet "-" before the first line, and indent the # remaining lines. bullet() { [[ $# -ge 1 ]] || panic - local mesg="$(_ "$(_html_whitespace_collapse <<<"$1")")"; shift + local mesg="$(_ "$(_libremessages_html_whitespace_collapse <<<"$1")")"; shift # Wrap the text to 71 columns; 75 (the default) minus a 4 column indent printf -- "$mesg" "$@" | fmt -u -w 71 | sed -e '1s/^/ - /' -e '2,$s/^/ /' } @@ -96,7 +96,7 @@ bullet() { flag() { [[ $# == 2 ]] || panic local flag=$1 - local desc="$(_ "$(_html_whitespace_collapse <<<"$2")")" + local desc="$(_ "$(_libremessages_html_whitespace_collapse <<<"$2")")" declare -i indent=13 while [[ $indent -le ${#flag} ]]; do @@ -162,7 +162,5 @@ setup_traps() { if [[ "${0##*/}" == libremessages ]]; then set -euE - _libremessages_cmd=$1 - shift - "$_libremessages_cmd" "$@" + "$@" fi diff --git a/src/lib/libremessages.1.ronn b/src/lib/libremessages.1.ronn index 6f1ecf5..daafd2f 100644 --- a/src/lib/libremessages.1.ronn +++ b/src/lib/libremessages.1.ronn @@ -71,8 +71,8 @@ Unless otherwise noted, these do not implicitly call `gettext`. using the default handler (which is good for most purposes), it will call with the arguments ` [...]`, where - is a `printf`(1)-formatted string, and - are its arguments. + is a `printf`(1)-formatted string that is fed through + `gettext`, and are its arguments. ### PROSE ROUTINES @@ -81,10 +81,6 @@ word-wrapped prose. For each of these, is fed through `gettext` automatically. - * `print` [...]: - Like `printf`(1), but `gettext`-aware, and automatically prints a - trailing newline. - * `prose` [...]: Takes a `printf`(1)-formatted string, collapses whitespace (HTML-style), and then word-wraps it. @@ -114,7 +110,7 @@ any arguments. Each of these print to stderr, not stdout. For each of these, is fed through `gettext` automatically. * `plain` [...]: - Prints "plain" message in bold, indented with 4 spaces. + Prints a "plain" message in bold, indented with 4 spaces. * `msg` [...]: Prints a top-level priority notification. @@ -134,6 +130,10 @@ For each of these, is fed through `gettext` automatically. * `stat_done`: Prints a "done" type message to terminate `stat_busy`. + * `print` [...]: + Like `printf`(1), but `gettext`-aware, and automatically prints a + trailing newline. + * `term_title` [...]: Sets the terminal title to the specified message. -- cgit v1.2.2