aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCiaran McCreesh <ciaranm@gentoo.org>2005-05-08 16:49:56 +0000
committerCiaran McCreesh <ciaranm@gentoo.org>2005-05-08 16:49:56 +0000
commitab56fc8eac2319b3da04bfea486671e83fa10e9d (patch)
treec90422bbf1ced25bd0c9d1a689f9844f2da73a9d
parentFix my broken whitespacing. Bad me! (diff)
downloadeselect-ab56fc8eac2319b3da04bfea486671e83fa10e9d.tar.gz
eselect-ab56fc8eac2319b3da04bfea486671e83fa10e9d.tar.bz2
eselect-ab56fc8eac2319b3da04bfea486671e83fa10e9d.zip
Add in highlighting for text
svn path=/trunk/; revision=63
-rw-r--r--ChangeLog6
-rw-r--r--doc/developer-guide.txt12
-rw-r--r--libs/core.bash.in1
-rw-r--r--libs/output.bash.in49
4 files changed, 59 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index d927970..fe84875 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
ChangeLog for eclectic
+2005-05-08 Ciaran McCreesh <ciaranm@gentoo.org>
+
+ * libs/output.bash.in, libs/core.bash.in: Add in somewhat experimental
+ text highlighting functionality.
+ * doc/developer-guide.txt: Document highlight function.
+
2005-05-08 Danny van Dyk <kugelfang@gentoo.org>
* modules/blas.eclectic: update -> scan transition complete.
diff --git a/doc/developer-guide.txt b/doc/developer-guide.txt
index 2d12236..722a664 100644
--- a/doc/developer-guide.txt
+++ b/doc/developer-guide.txt
@@ -209,6 +209,18 @@ The ``write_numbered_list`` function is a wrapper around
parameter passed is displayed as a numbered list item, the first with index 1,
the second with index 2 and so on.
+The ``highlight`` Utility Function
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+The ``highlight`` utility function can be used to emphasise some text which is
+to be displayed by any of the above functions. A typical invocation might look
+like: ::
+
+ write_list_start "This is $(highlight list) example"
+ write_kv_list_entry "First" "This is the first"
+ write_kv_list_entry "$(highlight Second)" "This is the $(highlight second) entry"
+ write_kv_list_entry "Third" "$(highlight The end)"
+
The ``space`` Utility Function
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/libs/core.bash.in b/libs/core.bash.in
index e4b46e2..02b6e82 100644
--- a/libs/core.bash.in
+++ b/libs/core.bash.in
@@ -23,6 +23,7 @@ COLOUR_LIST_LEFT="\033[0;1m"
COLOUR_LIST_RIGHT="\033[00m"
COLOUR_ERROR="\033[1;31m"
COLOUR_NORMAL="\033[00m"
+COLOUR_HI="\033[1;34m"
# die [-q] "Message" PUBLIC
# Display "Message" as an error. If -q is not provided, gives a stacktrace.
diff --git a/libs/output.bash.in b/libs/output.bash.in
index 7879408..1173572 100644
--- a/libs/output.bash.in
+++ b/libs/output.bash.in
@@ -24,35 +24,50 @@ write_error_msg() {
}
# write_list_start PUBLIC
-# Write a list heading
+# Write a list heading. Args may include text highlighting.
write_list_start() {
- echo -e "${COLOUR_LIST_HEADER}${*}${COLOUR_NORMAL}"
+ echo -n -e "${COLOUR_LIST_HEADER}"
+ echo -n -e $(apply_text_highlights "${COLOUR_LIST_HEADER}" "$*")
+ echo -n -e "${COLOUR_NORMAL}"
+ echo
}
# write_kv_list_entry PUBLIC
-# Write a key/value list entry with $1 on the left and $2 on the right
+# Write a key/value list entry with $1 on the left and $2 on the right.
+# Args may include text highlighting.
write_kv_list_entry() {
local n
- echo -n -e " ${COLOUR_LIST_LEFT}${1}${COLOUR_NORMAL} "
+ echo -n -e " ${COLOUR_LIST_LEFT}"
+ echo -n -e $(apply_text_highlights "${COLOUR_LIST_LEFT}" "$1")
+ echo -n -e "${COLOUR_NORMAL} "
for (( n = 1 ; n <= $(( 25 - ${#1} )) ; ++n )) ; do
echo -n " "
done
- echo -e "${COLOUR_LIST_RIGHT}${2}${COLOUR_NORMAL}"
+ echo -n -e "${COLOUR_LIST_RIGHT}"
+ echo -n -e $(apply_text_highlights "${COLOUR_LIST_RIGHT}" "$2")
+ echo -n -e "${COLOUR_NORMAL}"
+ echo
}
# write_numbered_list_entry PUBLIC
-# Write out a numbered list entry with index $1 and text $2
+# Write out a numbered list entry with index $1 and text $2. Args may
+# include text highlighting.
write_numbered_list_entry() {
local n
- echo -n -e " ${COLOUR_LIST_LEFT}[${1}]${COLOUR_NORMAL}"
+ echo -n -e " ${COLOUR_LIST_LEFT}"
+ echo -n -e $(apply_text_highlights "${COLOUR_LIST_LEFT}" "[$1]")
+ echo -n -e "${COLOUR_NORMAL}"
for (( n = 1 ; n <= $(( 4 - ${#1} )) ; ++n )) ; do
echo -n " "
done
- echo -e "${COLOUR_LIST_RIGHT}${2}${COLOUR_NORMAL}"
+ echo -n -e "${COLOUR_LIST_RIGHT}"
+ echo -n -e $(apply_text_highlights "${COLOUR_LIST_RIGHT}" "$2")
+ echo -n -e "${COLOUR_NORMAL}"
+ echo
}
# write_numbered_list PUBLIC
-# Write out a numbered list
+# Write out a numbered list. Args may include text highlighting.
write_numbered_list() {
local n=1
while [[ ${#@} -gt 0 ]] ; do
@@ -63,6 +78,22 @@ write_numbered_list() {
done
}
+# apply_text_highlights INTERNAL
+# Apply text highlights. First arg is the 'restore' colour, second arg
+# is the text.
+apply_text_highlights() {
+ local restore=${1} text=${2}
+ text="${text//\%%%HI%%%/${COLOUR_HI}}"
+ text="${text//\%%%RE%%%/${restore}}"
+ echo -n "${text}"
+}
+
+# highlight PUBLIC
+# Highlight all arguments. Text highlighting function.
+highlight() {
+ echo -n -e "%%%HI%%%${*}%%%RE%%%"
+}
+
# space PUBLIC
# Write $1 numbers of spaces
space() {