characters stick at the beginning of CLI When I press arrow up to search through the command history, some characters always remain at the beginning of the command line. Does anyone know what's going on ? How can I fix it?

for example, I ping google.com, it looks like this:


then I press up arrow a few times and down arrow a few times, some characters stick at the beginning of the command line like this:

those characters can't be removed or highlight, and I can still use the CLI normally, like this:
and move between directory despite the leading characters:
Your Bash prompt is not properly escaped for non-printing characters, so it thinks the prompt is longer than it truly is (and doesn't delete some of the characters). To fix it, add \[ and \] around the invisible parts.

You need to change it to:

export PS1='\[\e[31m\]\W\[\e[0m\] '