This code generates a horizontal coloured real time bargraph generator anim for a Macbook Pro 13 inch, OSX 10.7.5, using the default standard Terminal only.
It is UNTESTED on Linux variants but I would like any successful Linux tryers to make a comment in the comments section and tags will be added accordingly otherwise I will assume it does NOT work on other UNIX like variants.
It is a derivative of my 7 bit bargraph generator for Python on this site elsewhere.
The Terminal colours WILL be changed on running but it is simple to return it back to its original state.
Read the code for more information.
Enjoy, (and a Happy New Year)...
Bazza, G0LCU...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | #!/bin/bash
#
# Bargraph_Generator.sh
#
# A DEMO 6 bit coloured bargraph animation for a default Bash and Terminal window on OSX 10.7.5...
# A simple Shell script to display an _AT_A_GLANCE_ real time analogue bargraph generator. It
# starts off with GREEN for OK, then YELLOW for warning and finally ending with RED for danger
# with a critical beep for values 61 to 63 inclusive.
# It assumes an 8 bit value being injected into the script which is then divided by 4 to give
# a 6 bit value which is 64 spaces width inside the Terminal. The DEMO uses a random number
# generator to give a representation of an 8 bit value so you can see it working...
#
# A shell derivative of my Python code:-
# http://code.activestate.com/recipes/577612-seven-bit-colored-analogue-bar-graph-generator-dem/?in=user-4177147
#
# To run, ensure the script is executable and change if required, then type from a Terminal:-
#
# xxxxx$ /full/path/to/Bargrapth_Generator.sh<CR>
#
# And away you go...
#
# Written in such a way that kids and newbies can understand what is going on.
#
# Originally written for a Macbook Pro 13 inch, OSX 10.7.5 using the default Terminal.
# It MIGHT work on some Linux variants but WAS intended for MacOS OSX 10.7.x and above only.
#
# The Terminal colours WILL be changed to Black background and Various foreground colours.
# It will NOT be returned back to its original state although it can be easily. If you
# need to rerturn back to default state then there are a couple of easy methods the
# simplest being type:-
#
# xxxxx$ reset<CR>
#
# And all will be corrected...
#
# Issued entirely as Public Domain and you may do with it as you please
#
# $VER Bargraph_Generator.sh_Version_0.00.10_(C)2012_B.Walker_G0LCU.
#
# Enjoy finding simple solutions to often very difficult problems...
# The required _varibales_ for ease of coding, these are the colours...
# White On Black.
WOB="\x1B[1;37;40m"
# Black On Green.
BOG="\x1B[1;30;42m"
# Black On Yellow.
BOY="\x1B[1;30;43m"
# Black On red.
BOR="\x1B[1;30;41m"
# Green On Black.
GOB="\x1B[1;32;40m"
# Yellow On Black.
YOB="\x1B[1;33;40m"
# Red On Black.
ROB="\x1B[1;31;40m"
# Set the pseudo 6 bit value to zero.
SIX_BIT_DEPTH=0
# Do a clear screen to White On Black.
printf $WOB
clear
while true
do
# Set up the screen per scan and prepare for the bargraph.
clear
printf $WOB"\n \$VER: Bargraph_Generator.sh_Version_0.00.10_(C)2012_B.Walker_G0LCU.\n\n"
printf " A horizontal, at a glance, coloured, analogue bargraph display for\n"
printf " a default Terminal inside OSX 10.7.5..\n\n\n\n\n"
printf " 0 10 20 30 40 50 60"
printf $GOB"\n +----+----+----+----+----+----+----+----+----+"$YOB"----+----+"$ROB"----+--\n"
printf $GOB" (| "$ROB")\n"
printf $GOB" +----+----+----+----+----+----+----+----+----+"$YOB"----+----+"$ROB"----+--\n\n\n\n"
# If the 6 bit value is 0, zero, do no more until printing the 6 bit value and generating another 6 bit value...
# Anything greater than or equal to 1 enters this conditional branch.
if [ "$SIX_BIT_DEPTH" -ge "1" ]
then
# If the 6 bit value is less than or equal to 46 then _plot_ the green section only.
# The '\x1B[12;8f' is the ANSI 'Esc' code that forces the print position to 12 lines by 8 columns.
if [ "$SIX_BIT_DEPTH" -le "46" ]
then
BARGRAPH=$GOB"\x1B[12;8f("$BOG
for green in $(seq 1 "$SIX_BIT_DEPTH")
do
BARGRAPH=$BARGRAPH" "
done
fi
# If the 6 bit value is greater than or equal to 47 then print the green section and _plot_ the yellow section.
if [ "$SIX_BIT_DEPTH" -ge "47" ]
then
BARGRAPH=$GOB"\x1B[12;8f("$BOG" "$BOY
for yellow in $(seq 47 "$SIX_BIT_DEPTH")
do
BARGRAPH=$BARGRAPH" "
done
fi
# If the 6 bit value is greater than or equal to 57 then print the green and yellow section and _plot_ the red section.
if [ "$SIX_BIT_DEPTH" -ge "57" ]
then
BARGRAPH=$GOB"\x1B[12;8f("$BOG" "$BOY" "$BOR
for red in $(seq 57 "$SIX_BIT_DEPTH")
do
BARGRAPH=$BARGRAPH" "
done
fi
printf "$BARGRAPH"$GOB"\n\n\n\n\n"
fi
# When the 6 bit value is greater than or equal to 61 sound a system error beep.
if [ "$SIX_BIT_DEPTH" -ge "61" ]
then
printf "\a"
fi
# Print the 6 bit value in White On Black...
printf $WOB" Random number generated "$SIX_BIT_DEPTH"...\n\n"
printf " Press Ctrl-C to stop the program...\n\n"
# Generate another 6 bit value as though from an 8 bit value...
SIX_BIT_DEPTH=$[($RANDOM % (256/4))]
# A practical lower limit for the sleep command is 'sleep 0.05'...
sleep 1
done
# End of Bargraph_Generator.sh DEMO.
# Enjoy finding simple solutions to often very difficult problems... ;o)
|
I don't expect this to be viewed and/or downloaded much but those that do and run Linux too please leave a comment if it successfully works in your Terminal...
TIA...
Bazza, G0LCU...
Now tested on PCLinuxOS 2009 and Debian 6.0.x without any nodification using all of the Shells/Terminals supplied on the default installs.
Bazza, G0LCU...
Revision 2 is merely changing the shebang line from a comment to a proper shebang.