title: Using custom colors in zsh PS1 (prompt) env var causes problems with whitespace
body: <p>My setup:</p>
  <ul>
  <li>zsh 5.7.1 (x86_64-apple-darwin19.0)</li>
  <li>macOS Catalina 10.15.5</li>
  </ul>
  <p>Here's the standard PS1 var: <code>PS1=&quot;%n@%m %~ %# &quot;</code></p>
  <p>Problems arise when I try adding text coloring using either ANSI colors or tput. Example (without terminating the color, it behaves oddly regardless of that):</p>
  <p><code>PS1=&quot;%n@%m \e[38;5;197m%~ %# &quot;</code></p>
  <p>Here's what happens when I use Ctrl+R (reverse search):
  <a href="https://i.stack.imgur.com/AuXhh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AuXhh.png" alt="weird indents" /></a></p>
  <p>What could be the reason for this indent?</p>
  <p>Second problem happens when a long string in the prompt goes to the newline - new character after newline overlaps the first line and I can't see the latter. This happens only with the first newline, third one appears normally (but in second place).</p>
  <p>I tried using <a href="https://stackoverflow.com/questions/17306348/long-lines-overlap-in-bash-ps1-prompt">this answer</a> but the solution can't get parsed by the shell: <code>rombez@MacBook-Pro \[\e[38;5;197m\]~</code></p>