(requires bash for UTF-8 handling) (LP: #705037).

* usr/bin/byobu-ugraph: New UTF-8 notification utility showing
historical byobu-ugraph data (required bash for UTF-8 handling).
some 'level' using various unicode characters (requires bash for
UTF-8 handling). Also has an accessibility mode using an option or
environment variable to display all values as percentages in ASCII.
This commit is contained in:
Dustin Kirkland 2011-02-22 07:54:04 -06:00
commit 7e868c2d30
3 changed files with 76 additions and 26 deletions

10
debian/changelog vendored
View file

@ -17,11 +17,13 @@ byobu (3.28) unreleased; urgency=low
[ James Hunt <james.hunt@ubuntu.com> ] [ James Hunt <james.hunt@ubuntu.com> ]
* usr/lib/byobu/time_binary: New UTF-8 notification showing time in binary * usr/lib/byobu/time_binary: New UTF-8 notification showing time in binary
(requires bash) (LP: #705037). (requires bash for UTF-8 handling) (LP: #705037).
* usr/lib/byobu/byobu-ugraph: New UTF-8 notification utility showing * usr/bin/byobu-ugraph: New UTF-8 notification utility showing
historical byobu-ugraph data (required bash). historical byobu-ugraph data (required bash for UTF-8 handling).
* usr/bin/byobu-ulevel: New UTF-8 notification utility which displays * usr/bin/byobu-ulevel: New UTF-8 notification utility which displays
some 'level' using various unicode characters (requires bash) some 'level' using various unicode characters (requires bash for
UTF-8 handling). Also has an accessibility mode using an option or
environment variable to display all values as percentages in ASCII.
(LP: #705032). (LP: #705032).
* usr/lib/byobu/trash: New ASCII+UTF-8 notification indicating * usr/lib/byobu/trash: New ASCII+UTF-8 notification indicating
contents of trash. contents of trash.

View file

@ -83,7 +83,8 @@ Examples:
file=/tmp/load.dat file=/tmp/load.dat
awk '{ print \$1}' /proc/loadavg >> \$file awk '{ print \$1}' /proc/loadavg >> \$file
$script_name -f \$file # Note: we need to specify what we consider to be a "reasonable" maximum load
$script_name -m 3.0 -f \$file
Notes: Notes:
@ -208,5 +209,5 @@ data=$(get_data)
for datum in $data for datum in $data
do do
byobu-ulevel -n -m $min -x $max -c $datum -t $theme byobu-ulevel -n -m $min -x $max -p -c $datum -t $theme
done done

View file

@ -90,6 +90,9 @@ theme_list=\
#------------------------------ #------------------------------
default_decimal_places=2
a11y=n
a11y_variable=BYOBU_A11Y
debug_enabled=n debug_enabled=n
newline= newline=
list=n list=n
@ -102,6 +105,7 @@ max_default=100
width_default=5 width_default=5
zero_as_space=n zero_as_space=n
theme_default=vbars_8 theme_default=vbars_8
permissive=n
debug() debug()
{ {
@ -121,6 +125,13 @@ die()
exit 1 exit 1
} }
check_a11y()
{
eval result="\$$a11y_variable"
[ ! -z "$result" ] && a11y=y
}
# return 1 if expression specified is true (no return if false)
bc_test() bc_test()
{ {
expr="$*" expr="$*"
@ -152,16 +163,22 @@ Usage: $script_name [options] -c <current_num>
Options: Options:
-a : Accessibility mode: only output ASCII.
(Also enabled if variable '$a11y_variable' set).
-b : Display current value as space if zero, rather than lowest -b : Display current value as space if zero, rather than lowest
'value' of theme. 'value' of theme.
-c <num> : Current value of your indicator. -c <num> : Current value of your indicator.
-d : Enable debug output. -d : Enable debug output.
-e <int> : Number of decimal places to use for accessibility mode
(default=$default_decimal_places).
-h : Show this help. -h : Show this help.
-i : Invert colour scheme (rating themes only). -i : Invert colour scheme (rating themes only).
-l : List available themes. If '-t' also specified, -l : List available themes. If '-t' also specified,
show all values for specified theme. show all values for specified theme.
-m <num> : Minimum value (default=$min_default). -m <num> : Minimum value (default=$min_default).
-n : Supress output of newline character. -n : Supress output of newline character.
-p : Permissive mode - if current value out of bounds, set it
to the nearest bound (min or max).
-q : Suppress messages (requires '-t'). -q : Suppress messages (requires '-t').
-r : Reverse 'direction' of display (rating theme only). -r : Reverse 'direction' of display (rating theme only).
-t <theme> : Name of theme (default=$theme_default). -t <theme> : Name of theme (default=$theme_default).
@ -181,6 +198,10 @@ Examples:
# Example showing floating-point and negative values. # Example showing floating-point and negative values.
$script_name -c 1.100001 -m -5.00234 -x 2.71828 -t dice_6 $script_name -c 1.100001 -m -5.00234 -x 2.71828 -t dice_6
# Use accessibility mode to display a percentage value
# (rounded to nearest percentage)
$script_name -m -22.613 -x 5.00212 -c 0.10203 -a -e 0
# Display value using a "rating theme" (displayed left-to-right). # Display value using a "rating theme" (displayed left-to-right).
$script_name -c 83 -t stars_2 $script_name -c 83 -t stars_2
@ -221,7 +242,7 @@ show_rating_theme()
min="$2" min="$2"
max="$3" max="$3"
current="$4" current="$4"
quotient="$5" percent="$5"
if [ $invert = n ] if [ $invert = n ]
then then
@ -232,7 +253,6 @@ show_rating_theme()
off=1 off=1
fi fi
percent=$(echo "$quotient * 100"|bc -l)
debug "width=$width" debug "width=$width"
debug "percent=$percent" debug "percent=$percent"
@ -280,16 +300,27 @@ show_theme_entry()
range=$(echo "($max - $min)"|bc -l) range=$(echo "($max - $min)"|bc -l)
quotient=$(echo "scale=4;((${current} - ${min})/${range})"|bc -l) quotient=$(echo "scale=4;((${current} - ${min})/${range})"|bc -l)
percent=$(echo "$quotient * 100"|bc -l)
glyph_count=$(echo $theme|awk -F\_ '{print $NF}') glyph_count=$(echo $theme|awk -F\_ '{print $NF}')
debug "range=$range" debug "range=$range"
debug "quotient=$quotient" debug "quotient=$quotient"
debug "percent=$percent"
debug "glyph_count=$glyph_count" debug "glyph_count=$glyph_count"
# just ASCII please
if [ $a11y = y ]
then
[ -z "$decimal_places" ] && decimal_places=$default_decimal_places
val=$(echo|awk -v p=$percent -v dp=$decimal_places '{printf("%.*f", dp, p)}')
echo $newline "$val"
return
fi
if [ $glyph_count -eq 2 ] if [ $glyph_count -eq 2 ]
then then
show_rating_theme "$theme" "$min" "$max" "$current" "$quotient" show_rating_theme "$theme" "$min" "$max" "$current" "$percent"
return return
fi fi
@ -358,13 +389,19 @@ theme_valid()
return 0 return 0
} }
check_a11y
# XXX: the seemingly pointless 'tr' calls translate unicode dashes (look # XXX: the seemingly pointless 'tr' calls translate unicode dashes (look
# closely!) into ASCII dashes. This is required since 'bc' borks on # closely!) into ASCII dashes. This is required since 'bc' borks on
# unicode and it is easy to mistakenly pass unicode dashes if you paste # unicode and it is easy to mistakenly pass unicode dashes if you paste
# characters from another application, such as a web-browser. # characters from another application, such as a web-browser.
while getopts "bc:dhilm:nqrt:u:w:x:" opt while getopts "abc:de:hilm:npqrt:u:w:x:" opt
do do
case "$opt" in case "$opt" in
a)
a11y=y
;;
b) b)
zero_as_space=y zero_as_space=y
;; ;;
@ -377,6 +414,10 @@ do
debug_enabled=y debug_enabled=y
;; ;;
e)
decimal_places=$OPTARG
;;
h) h)
usage usage
exit 0 exit 0
@ -469,8 +510,14 @@ then
exit 1 exit 1
fi fi
assert "$current >= $min" "current ($current) < minimum ($min)" if [ $permissive = n ]
assert "$current <= $max" "current ($current) > maximum ($max)" then
assert "$current >= $min" "current ($current) < minimum ($min)"
assert "$current <= $max" "current ($current) > maximum ($max)"
else
[ ! -z "$(bc_test "$current < $min")" ] && current=$min
[ ! -z "$(bc_test "$current > $max")" ] && current=$max
fi
[ -z "$theme" ] && theme=$theme_default [ -z "$theme" ] && theme=$theme_default