Merge lp:~jamesodhunt/byobu/ulevel-a11y-and-permissive-options into lp:byobu

Proposed by James Hunt
Status: Merged
Merged at revision: 1301
Proposed branch: lp:~jamesodhunt/byobu/ulevel-a11y-and-permissive-options
Merge into: lp:byobu
Diff against target: 267 lines (+76/-26)
3 files modified
debian/changelog (+6/-4)
usr/bin/byobu-ugraph (+3/-2)
usr/bin/byobu-ulevel (+67/-20)
To merge this branch: bzr merge lp:~jamesodhunt/byobu/ulevel-a11y-and-permissive-options
Reviewer Review Type Date Requested Status
Dustin Kirkland  Pending
Review via email: mp+49935@code.launchpad.net

Description of the change

* usr/bin/byobu-ulevel:
  - Added new options:
    - '-p' (permissive mode): makes script tolerate
      current value over max/under min (needed for byobu-ugraph for
      example when specifying an arbitrary maximum for system load).
    - '-a' (accessibility mode): Disabled UTF-8 output in favour of
      ASCII. Also enabled if variable BYOBU_A11Y set.
    - '-e': allows the specification of the number of decimal places.
      (only appropriate when used with '-a').
  - show_theme_entry(): Now calculates a proper percentage and passes
    this to show_rating_theme().
* usr/bin/byobu-ugraph:
  - usage(): Added missing '-m' value + comment to example.
  - main: Added '-p' (permissive) option to byobu-ulevel call.

To post a comment you must log in.
Revision history for this message
Dustin Kirkland  (kirkland) wrote :

On Wed, Feb 16, 2011 at 3:39 AM, James Hunt <email address hidden> wrote:
> +    # Note: we need to specify what we consider to be a "reasonable" maximum load
> +    $script_name -m 3.0 -f \$file

Load is relative the number of cpus. Note that we have a status
script that counts CPUs ;-)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2011-02-05 05:09:29 +0000
3+++ debian/changelog 2011-02-16 09:39:12 +0000
4@@ -12,11 +12,13 @@
5
6 [ James Hunt <james.hunt@ubuntu.com> ]
7 * usr/lib/byobu/time_binary: New UTF-8 notification showing time in binary
8- (requires bash) (LP: #705037).
9- * usr/lib/byobu/byobu-ugraph: New UTF-8 notification utility showing
10- historical byobu-ugraph data (required bash).
11+ (requires bash for UTF-8 handling) (LP: #705037).
12+ * usr/bin/byobu-ugraph: New UTF-8 notification utility showing
13+ historical byobu-ugraph data (required bash for UTF-8 handling).
14 * usr/bin/byobu-ulevel: New UTF-8 notification utility which displays
15- some 'level' using various unicode characters (requires bash)
16+ some 'level' using various unicode characters (requires bash for
17+ UTF-8 handling). Also has an accessibility mode using an option or
18+ environment variable to display all values as percentages in ASCII.
19 (LP: #705032).
20 * usr/lib/byobu/trash: New ASCII+UTF-8 notification indicating
21 contents of trash.
22
23=== modified file 'usr/bin/byobu-ugraph'
24--- usr/bin/byobu-ugraph 2011-02-05 05:09:29 +0000
25+++ usr/bin/byobu-ugraph 2011-02-16 09:39:12 +0000
26@@ -83,7 +83,8 @@
27
28 file=/tmp/load.dat
29 awk '{ print \$1}' /proc/loadavg >> \$file
30- $script_name -f \$file
31+ # Note: we need to specify what we consider to be a "reasonable" maximum load
32+ $script_name -m 3.0 -f \$file
33
34 Notes:
35
36@@ -208,5 +209,5 @@
37
38 for datum in $data
39 do
40- byobu-ulevel -n -m $min -x $max -c $datum -t $theme
41+ byobu-ulevel -n -m $min -x $max -p -c $datum -t $theme
42 done
43
44=== modified file 'usr/bin/byobu-ulevel'
45--- usr/bin/byobu-ulevel 2011-02-05 05:09:29 +0000
46+++ usr/bin/byobu-ulevel 2011-02-16 09:39:12 +0000
47@@ -90,6 +90,9 @@
48
49 #------------------------------
50
51+default_decimal_places=2
52+a11y=n
53+a11y_variable=BYOBU_A11Y
54 debug_enabled=n
55 newline=
56 list=n
57@@ -102,6 +105,7 @@
58 width_default=5
59 zero_as_space=n
60 theme_default=vbars_8
61+permissive=n
62
63 debug()
64 {
65@@ -121,6 +125,13 @@
66 exit 1
67 }
68
69+check_a11y()
70+{
71+ eval result="\$$a11y_variable"
72+ [ ! -z "$result" ] && a11y=y
73+}
74+
75+# return 1 if expression specified is true (no return if false)
76 bc_test()
77 {
78 expr="$*"
79@@ -152,16 +163,22 @@
80
81 Options:
82
83+ -a : Accessibility mode: only output ASCII.
84+ (Also enabled if variable '$a11y_variable' set).
85 -b : Display current value as space if zero, rather than lowest
86 'value' of theme.
87 -c <num> : Current value of your indicator.
88 -d : Enable debug output.
89+ -e <int> : Number of decimal places to use for accessibility mode
90+ (default=$default_decimal_places).
91 -h : Show this help.
92 -i : Invert colour scheme (rating themes only).
93 -l : List available themes. If '-t' also specified,
94 show all values for specified theme.
95 -m <num> : Minimum value (default=$min_default).
96 -n : Supress output of newline character.
97+ -p : Permissive mode - if current value out of bounds, set it
98+ to the nearest bound (min or max).
99 -q : Suppress messages (requires '-t').
100 -r : Reverse 'direction' of display (rating theme only).
101 -t <theme> : Name of theme (default=$theme_default).
102@@ -181,6 +198,10 @@
103 # Example showing floating-point and negative values.
104 $script_name -c 1.100001 -m -5.00234 -x 2.71828 -t dice_6
105
106+ # Use accessibility mode to display a percentage value
107+ # (rounded to nearest percentage)
108+ $script_name -m -22.613 -x 5.00212 -c 0.10203 -a -e 0
109+
110 # Display value using a "rating theme" (displayed left-to-right).
111 $script_name -c 83 -t stars_2
112
113@@ -221,7 +242,7 @@
114 min="$2"
115 max="$3"
116 current="$4"
117- quotient="$5"
118+ percent="$5"
119
120 if [ $invert = n ]
121 then
122@@ -232,7 +253,6 @@
123 off=1
124 fi
125
126- percent=$(echo "$quotient * 100"|bc -l)
127 debug "width=$width"
128 debug "percent=$percent"
129
130@@ -280,16 +300,27 @@
131 range=$(echo "($max - $min)"|bc -l)
132
133 quotient=$(echo "scale=4;((${current} - ${min})/${range})"|bc -l)
134+ percent=$(echo "$quotient * 100"|bc -l)
135
136 glyph_count=$(echo $theme|awk -F\_ '{print $NF}')
137
138 debug "range=$range"
139 debug "quotient=$quotient"
140+ debug "percent=$percent"
141 debug "glyph_count=$glyph_count"
142
143+ # just ASCII please
144+ if [ $a11y = y ]
145+ then
146+ [ -z "$decimal_places" ] && decimal_places=$default_decimal_places
147+ val=$(echo|awk -v p=$percent -v dp=$decimal_places '{printf("%.*f", dp, p)}')
148+ echo $newline "$val"
149+ return
150+ fi
151+
152 if [ $glyph_count -eq 2 ]
153 then
154- show_rating_theme "$theme" "$min" "$max" "$current" "$quotient"
155+ show_rating_theme "$theme" "$min" "$max" "$current" "$percent"
156 return
157 fi
158
159@@ -358,67 +389,77 @@
160 return 0
161 }
162
163+check_a11y
164+
165 # XXX: the seemingly pointless 'tr' calls translate unicode dashes (look
166 # closely!) into ASCII dashes. This is required since 'bc' borks on
167 # unicode and it is easy to mistakenly pass unicode dashes if you paste
168 # characters from another application, such as a web-browser.
169-while getopts "bc:dhilm:nqrt:u:w:x:" opt
170+while getopts "abc:de:hilm:npqrt:u:w:x:" opt
171 do
172 case "$opt" in
173- b)
174+ a)
175+ a11y=y
176+ ;;
177+
178+ b)
179 zero_as_space=y
180 ;;
181
182- c)
183+ c)
184 current=$(echo $OPTARG|tr '−' '-')
185 ;;
186
187- d)
188+ d)
189 debug_enabled=y
190 ;;
191
192- h)
193+ e)
194+ decimal_places=$OPTARG
195+ ;;
196+
197+ h)
198 usage
199 exit 0
200 ;;
201
202- i)
203+ i)
204 invert=y
205 ;;
206
207- l)
208+ l)
209 list=y
210 ;;
211
212- m)
213+ m)
214 min=$(echo $OPTARG|tr '−' '-')
215 ;;
216
217- n)
218+ n)
219 newline=-n
220 ;;
221
222- q)
223+ q)
224 quiet=y
225 ;;
226
227- r)
228+ r)
229 reverse=y
230 ;;
231
232- t)
233+ t)
234 theme=$OPTARG
235 ;;
236
237- u)
238+ u)
239 user_theme="$OPTARG"
240 ;;
241
242- w)
243+ w)
244 width=$OPTARG
245 ;;
246
247- x)
248+ x)
249 max=$(echo $OPTARG|tr '−' '-')
250 ;;
251 esac
252@@ -469,8 +510,14 @@
253 exit 1
254 fi
255
256-assert "$current >= $min" "current ($current) < minimum ($min)"
257-assert "$current <= $max" "current ($current) > maximum ($max)"
258+if [ $permissive = n ]
259+then
260+ assert "$current >= $min" "current ($current) < minimum ($min)"
261+ assert "$current <= $max" "current ($current) > maximum ($max)"
262+else
263+ [ ! -z "$(bc_test "$current < $min")" ] && current=$min
264+ [ ! -z "$(bc_test "$current > $max")" ] && current=$max
265+fi
266
267 [ -z "$theme" ] && theme=$theme_default
268

Subscribers

People subscribed via source and target branches