How i understand, u need something like this:
x=0;while [ $x -le 256 ]
do
t=$(tput sgr 0);r=$(tput setaf $x);echo -n "${r} $x ${t}";((x=$x+1))
done
U forgot to use echo -n (no new line)
Formatted version with columns:
#!/bin/bash
t=$(tput sgr 0)
for x in {0..255}; do
printf "%s%4s${t}" "$(tput setaf $x)" $x
if [ $((x % 15)) -eq 0 ]; then echo; fi;
done