-
Notifications
You must be signed in to change notification settings - Fork 749
Description
When a Python virtual environment is activated, by default it puts the virtual environment's name to the left of the prompt in a shell session. E.g.:
~$ source myenv/bin/activate
(myenv) ~$This causes Pygments to fail to detect the prompt in the console/shell-session lexer. Compare:
Without the virtual environment:
$ pygmentize -l console -f html <<<"[~/project]$ foo -h"
<div class="highlight"><pre><span></span><span class="gp">[~/project]$</span> foo -h
</pre></div>With the virtual environment:
$ pygmentize -l console -f html <<<"(env) [~/project]$ foo -h"
<div class="highlight"><pre><span></span><span class="go">(env) [~/project]$ foo -h</span>
</pre></div>Note that it is detected if there is nothing after the environment name or possibly a user@host:dir without brackets:
$ pygmentize -l shell-session -f html <<<"(env)a@b:x$ foo -h"
<div class="highlight"><pre><span></span><span class="gp">(env)a@b:x$</span> foo -h
</pre></div>Context:
Some software I develop is documented with Sphinx. Since I encourage users of my software to use virtual environments, I would like to illustrate their use in my documentation, but the lexer fails to parse my examples if I use the virtual environment names. I think this is just a matter of accounting for an optional virtual environment name in BashSessionLexer._ps1rgx, but there may be complexities I'm not considering.