aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Müller <ulm@gentoo.org>2009-09-19 05:42:06 +0000
committerUlrich Müller <ulm@gentoo.org>2009-09-19 05:42:06 +0000
commit9fd03936f3e3395d82d690fd7426425296f2a1c2 (patch)
tree06e5fa1c4a065e7f4dc1d7afc393dd3b3325dbb9
parentRename a variable. (diff)
downloadeselect-9fd03936f3e3395d82d690fd7426425296f2a1c2.tar.gz
eselect-9fd03936f3e3395d82d690fd7426425296f2a1c2.tar.bz2
eselect-9fd03936f3e3395d82d690fd7426425296f2a1c2.zip
New -m option for function write_numbered_list.
svn path=/trunk/; revision=661
-rw-r--r--ChangeLog8
-rw-r--r--doc/developer-guide.txt3
-rw-r--r--libs/output.bash.in20
-rw-r--r--modules/bashcomp.eselect18
-rw-r--r--modules/kernel.eselect19
5 files changed, 37 insertions, 31 deletions
diff --git a/ChangeLog b/ChangeLog
index c04bc87..2ee4ee4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
2009-09-18 Ulrich Mueller <ulm@gentoo.org>
+ * libs/output.bash.in (write_numbered_list): New -m option.
+ It is used to specify a negative report message that is output for
+ an empty list.
+ * doc/developer-guide.txt: Document it.
+ * modules/bashcomp.eselect (do_list):
+ * modules/kernel.eselect (do_list): Call write_numbered_list with
+ option -m, which simplifies the code.
+
* modules/modules.eselect (do_list): Add support for brief output
mode. For reasons of speed, don't source any modules in this case.
* libs/default.eselect.in (do_usage): Don't reset output mode.
diff --git a/doc/developer-guide.txt b/doc/developer-guide.txt
index 4aea47d..16152d6 100644
--- a/doc/developer-guide.txt
+++ b/doc/developer-guide.txt
@@ -264,7 +264,8 @@ used. The first parameter is the key, the second the value.
The ``write_numbered_list`` function is a wrapper around
``write_numbered_list_entry`` that handles the numbering automatically. Each
parameter passed is displayed as a numbered list item, the first with index 1,
-the second with index 2 and so on.
+the second with index 2 and so on. The -m option can be used to specify a
+negative report message that is output for an empty list.
If -p is passed as the first argument to these functions, 'plain' highlighting
is used.
diff --git a/libs/output.bash.in b/libs/output.bash.in
index c235246..1a297d1 100644
--- a/libs/output.bash.in
+++ b/libs/output.bash.in
@@ -168,20 +168,28 @@ write_numbered_list_entry() {
echo -n -e "${right}"
echo -n -e "$(apply_text_highlights "${right}" "$2")"
- echo -n -e "${normal}"
- echo
+ echo -e "${normal}"
}
# write_numbered_list PUBLIC
# Write out a numbered list. Args may include text highlighting.
+# If called with the -m option and an empty list, output a negative report.
write_numbered_list() {
- local n=1 p=
- if [[ ${1} == "-p" ]] ; then
- p="-p"
+ local n=1 m p
+ while [[ $1 == -* ]]; do
+ case $1 in
+ "-m") shift; m=$1 ;;
+ "-p") p="-p" ;;
+ "--") shift; break ;;
+ esac
shift
+ done
+
+ if [[ $# -eq 0 && -n ${m} && ${ESELECT_OUTPUT_MODE} != brief ]]; then
+ write_kv_list_entry ${p} "${m}" ""
fi
- while [[ ${#@} -gt 0 ]] ; do
+ while [[ $# -gt 0 ]] ; do
item=${1}
shift
if [[ ${item##*\\} == "" ]] ; then
diff --git a/modules/bashcomp.eselect b/modules/bashcomp.eselect
index 9692ce5..1eb1f74 100644
--- a/modules/bashcomp.eselect
+++ b/modules/bashcomp.eselect
@@ -47,7 +47,7 @@ describe_list_options() {
}
do_list() {
- local opts
+ local opts i
targets=( $(find_targets) )
write_list_start "Available completions:"
@@ -56,17 +56,11 @@ do_list() {
shift
fi
- if [[ -n "${targets[@]}" ]] ; then
- for (( n = 0 ; n < ${#targets[@]} ; ++n )) ; do
- is_enabled ${opts:-} ${targets[n]} \
- && targets[n]=$(highlight_marker "${targets[n]}")
- done
- write_numbered_list "${targets[@]}"
- elif [[ ${ESELECT_OUTPUT_MODE} != brief ]]; then
- write_kv_list_entry "(none found)" ""
- fi
-
- return 0
+ for (( i = 0; i < ${#targets[@]}; i++ )) ; do
+ is_enabled ${opts:-} ${targets[i]} \
+ && targets[i]=$(highlight_marker "${targets[i]}")
+ done
+ write_numbered_list -m "(none found)" "${targets[@]}"
}
### enable action ###
diff --git a/modules/kernel.eselect b/modules/kernel.eselect
index 819cd33..fa6c830 100644
--- a/modules/kernel.eselect
+++ b/modules/kernel.eselect
@@ -82,19 +82,14 @@ describe_list() {
}
do_list() {
- local targets=( $(find_targets) )
+ local i targets=( $(find_targets) )
write_list_start "Available kernel symlink targets:"
- if [[ ${#targets[@]} -gt 0 ]] ; then
- local i
- for (( i = 0; i < ${#targets[@]}; i++ )) ; do
- [[ ${targets[i]} = \
- $(basename "$(canonicalise "${EROOT}/usr/src/linux")") ]] \
- && targets[i]=$(highlight_marker "${targets[i]}")
- done
- write_numbered_list "${targets[@]}"
- elif [[ ${ESELECT_OUTPUT_MODE} != brief ]]; then
- write_kv_list_entry "(none found)" ""
- fi
+ for (( i = 0; i < ${#targets[@]}; i++ )) ; do
+ [[ ${targets[i]} = \
+ $(basename "$(canonicalise "${EROOT}/usr/src/linux")") ]] \
+ && targets[i]=$(highlight_marker "${targets[i]}")
+ done
+ write_numbered_list -m "(none found)" "${targets[@]}"
}
### set action ###