diff options
author | 2005-10-19 11:21:22 +0000 | |
---|---|---|
committer | 2005-10-19 11:21:22 +0000 | |
commit | 54dd54da3321fa31d802e40788e14a58a1c5d088 (patch) | |
tree | 4e6675de252490f6a8b9587b0f16a82cc8ebef79 | |
parent | Added --global as a possible option for the 'list' action. (diff) | |
download | eselect-54dd54da3321fa31d802e40788e14a58a1c5d088.tar.gz eselect-54dd54da3321fa31d802e40788e14a58a1c5d088.tar.bz2 eselect-54dd54da3321fa31d802e40788e14a58a1c5d088.zip |
Modified write_kv_list_entry to properly wrap (and indent) lines that are longer than the current terminal width.
svn path=/trunk/; revision=233
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | libs/output.bash.in | 44 |
2 files changed, 49 insertions, 4 deletions
@@ -1,5 +1,14 @@ ChangeLog for eselect +2005-10-19 Aaron Walker <ka0ttic@gentoo.org> + + * libs/output.bash.in: Modified write_kv_list_entry to properly wrap + lines that are longer than the current terminal width. + * man/bashcomp.eselect.5: Added --global as a possible option for the + 'list' action. + * modules/env.eselect: Added describe_update_options and + describe_update_parameters. + 2005-10-18 Aaron Walker <ka0ttic@gentoo.org> * modules/rc.eselect: Added missing space after the '1' in diff --git a/libs/output.bash.in b/libs/output.bash.in index 5ffcb10..a752684 100644 --- a/libs/output.bash.in +++ b/libs/output.bash.in @@ -69,20 +69,45 @@ write_list_start() { # highlighting rather than bold. write_kv_list_entry() { local n text left="${COLOUR_LIST_LEFT}" right="${COLOUR_LIST_RIGHT}" + if [[ ${1} == "-p" ]] ; then left= right= shift fi + echo -n -e " ${left}" echo -n -e $(apply_text_highlights "${left}" "$1") echo -n -e "${COLOUR_NORMAL} " + text=${1//\%%%??%%%/} - space $(( 25 - ${#text} )) + n=$(( 25 - ${#text} )) + space ${n} echo -n -e "${right}" - echo -n -e $(apply_text_highlights "${right}" "$2") - echo -n -e "${COLOUR_NORMAL}" - echo + n=$(( ${n} + ${#text} + 2 )) # +2 for the inital " " in the first echo + + local cols=$(get_column_width) \ + cwords="$(apply_text_highlights "${right}" "${2}")" + # only go through the trouble if we have to + text=${2//\%%%??%%%/} + if [[ $(( ${n} + ${#text} )) -ge ${cols} ]] ; then + local i=0 indent="$(space 28)" + cwords=(${cwords}) + for text in ${2} ; do + text=${text//\%%%??%%%/} + if [[ $(( ${n} + ${#text} )) -lt ${cols} ]] ; then + echo -n -e "${cwords[i]} " + n=$(( ${n} + ${#text} + 1 )) + else + echo -n -e "\n${indent}${cwords[i]} " + n=$(( 28 + ${#text} + 1 )) + fi + i=$(( ${i} + 1 )) + done + echo -e "${COLOUR_NORMAL}" + else + echo -e "${cwords}${COLOUR_NORMAL}" + fi } # write_numbered_list_entry PUBLIC @@ -126,6 +151,17 @@ write_numbered_list() { done } +# get_column_width INTERNAL +# Get current column width +get_column_width() { + if [[ -z "${COLS}" ]] ; then + COLS=( $(stty size 2>/dev/null) ) + is_number "${COLS[1]}" && COLS=${COLS[1]} || COLS=79 + fi + + echo -n ${COLS} +} + # apply_text_highlights INTERNAL # Apply text highlights. First arg is the 'restore' colour, second arg # is the text. |