I have an array with 252 times this character: █
I want to display the whole array on the screen so that when I resize the terminal window it always displays a multiple of 3 █ on each line. For example, by making the terminal window smaller, only 50 characters fit on each line, so I want to display 48, 48, 48, 48, 48, 48, 48 and 12 on each respective line so that there are multiples of 3 on every line.
To do this I am trying to use $(tput cols) to calculate the width of the screen and subtract 7 units to have a margin to the right of the terminal. Also, my tam_total variable contains the number of █ in the array, in this case it contains a 252. The variable r contains the value of the line being written - 1.
Finally, in the last row of the terminal I want to add the value of $tam_total, which works perfectly for me.
tamanopantalla=$(tput cols)
let "tam_pantalla_usable=tamanopantalla-7"
for ((r=0;r<${#array[@]};r++)){
if [[ $r -eq 0 ]]
then
if [[ $tam_total -le $tam_pantalla_usable ]]
then
echo -e "${array[$r]}""T=$tam_total"
else
echo -e "${array[$r]}"
fi
else
let "ult_linea=r+1"
if [[ $tam_total -ge $tam_pantalla_usable ]] && [[ $ult_linea = ${#array[@]} ]]
then
echo -e "${array[$r]}""T=$tam_total"
else
echo -e "${array[$r]}"
fi
fi
}
What I would like to know is if there is an easy way to show multiples of 3 █ in all my lines.