Terminal wraps long $PS1 prompt line over itself
I found that when $PROMPT_COMMAND or $PS1 are set with grouped colours, e.g. in ~/.bash_profile:
export PS1='\u@\h \[\e[33m\]\w\[\e[37m\] some text \$ \[\e[m\]'
and when the prompt string is very long (e.g. when the working dir is long), then if the line breaks on some sweet spot within (or on or directly next to) the \[grouping brackets\] the line will not wrap around to the next line, but stay on the current line and incorrectly overwrite the first characters of the prompt and possibly incorrectly colour following characters. The problem doesn't occur consistently, but the more colours you add to the prompt string, the easier they seem to occur.
I use posh-git-sh, which dynamically changes $PS1 to contain a prefix, a coloured Git string (if in a Git repo) and a suffix. I thought it was an issue with the implementation of some piece of code within that repo, so I opened and issue: see here. There I've posted screenshots too. Together with de repo's dev I've almost certainly ruled out posh-git-sh being the cause, but instead it could be the MacOS Terminal. The reason I mention it here is because posh-git-sh uses quite a lot of colours and if the line wraps somewhere near the end of the posh git string, the problem occurs. Try it out for yourself and resize the Terminal window, you'll see what happens (use clear after resizing).
I've searched the forums here and found that other people who modified their $PROMPT_COMMAND or $PS1 variables have similar issues when they type in long commands. This is not the problem I'm experiencing! I haven't found anyone mentioning the prompt itself being wrapped incorrectly.
MacBook Pro with Retina display, macOS Sierra (10.12.1), Terminal 2.7.1 (387), bash-4.4.5(1)