Re: [dev] wmii unicode in the status?

From: Patrick Haller <201009-suckless_AT_haller.ws>
Date: Sun, 23 Jan 2011 16:46:02 +0800

On Sat, Jan 22, 2011 at 11:28:20AM -0500, Eitan Goldshtrom wrote:
> Hi. I'm trying to print out a progress bar sort of thing that
> represents my remaining battery life.

Why use python? dc and printf suffice.

Patrick

percent=$1
buckets=10
# annoying math
decimal=$( dc -e "5 k $buckets $percent * 100 / p")
count=$( dc -e "0 k $decimal 1 / p" )
remainder=$( dc -e "5 k $decimal $count - p" )
offset=$( dc -e "0 k $remainder 8 * 1 / p" )
char_hex="0000200A" # unicode space
test $offset != 0 && {
        # see http://www.fileformat.info/info/unicode/char/258f/index.htm
        char_dec=$( dc -e "0 k 9616 $offset - p" )
        char_hex=$( printf "%08x" $char_dec )
}

for y in $( yes | head -n $count) ; do
        $( which printf ) "\U00002588"
done
$( which printf ) "\U${char_hex}\n"
Received on Sun Jan 23 2011 - 09:46:02 CET

This archive was generated by hypermail 2.2.0 : Sun Jan 23 2011 - 10:00:05 CET