Similar issue was discussed here and it should help. so basically, problem is, \[ and \] are required to tell bash not to count the escape sequences to the prompt width.
e.g.
MAGENTA="\\[$(tput setaf 5)\\]"