Centring text that contains colouring / bold / standout... escape sequences would be more complicated. Easiest would probably be to remove them before getting the width of the string. For instance, with zsh, using that approach to determine string width (and handling 0-width or double-width characters).
varwidth() (( ${(P)#1} * 3 - ${#${(ml[${(P)#1} * 2])${(P)1}}} ))
functions -Ms varwidth
varwidth_noescape() {
set -o localoptions -o extendedglob
local s=${(P)1//$'\e'\[[0-9;]#m}
(( varwidth(s) ))
}
functions -Ms varwidth_noescape
center() for 1 do
print -r -- ${(l[(COLUMNS-varwidth_noescape(1))/2])}$1
done
center $'\e[31mred\e[1;39mbold\e[m'