bash - how to center script output in the middle of the screen? -


here have binary clock outputs binary clock in 16 different colors , trying make appear in center of screen cant it. if have suggestions how please let me know. thanks

color=("0;30" "0;31" "0;32" "0;33" "0;34" "0;35" "0;36" "0;37" "1;30" "1;31" "1;32" "1;33" "1;34" "1;35" "1;36" "1;37") color2=${#color[*]} while true; clear echo -ne '\e['${color[$((random%color2))]}m hour=$(date +%h) minute=$(date +%m) second=$(date +%s) hour_binary=$(echo "ibase=10;obase=2;$hour" | bc) minute_binary=$(echo "ibase=10;obase=2;$minute" | bc) second_binary=$(echo "ibase=10;obase=2;$second" | bc) printf "%06d\n" "$hour_binary" printf "%06d\n" "$minute_binary" printf "%06d" "$second_binary" sleep 1 done 

if referring center of terminal window, columns , rows of terminal window with:

cols=$(tput cols) rows=$(tput lines) clockwidth=8 #i'm assuming hh:mm:ss format centercol=$((cols/2)) centercol=$((centercol-clockwidth)) centerrow=((rows/2)) 

and use tput command set cursor position with:

tput cup $centercol $centerrow 

see http://www.cyberciti.biz/tips/spice-up-your-unix-linux-shell-scripts.html example using tput , https://www.gnu.org/software/termutils/manual/termutils-2.0/html_chapter/tput_1.html more information tput command.


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -