Skip to content

Commit

Permalink
ShellSessionBaseLexer: Support whitespace in virtualenv prompt
Browse files Browse the repository at this point in the history
The default virtualenv prompt contains a single space after
the name of the virtualenv in parentheses.

Commit 3f40368 which resolved pygments#1253 assigns the "Text" class to
any whitespace between the virtualenv name and the rest of the prompt,
but this is problematic, because it makes the space selectable, and
doesn't include it in the prompt.

Fix this by assigning the Generic.Prompt class to the space between the
name of the virtualenv and the rest of the prompt, instead of Text.
Also update the test accordingly.

Closes pygments#2496

Signed-off-by: Vangelis Koukis <evangelos.koukis@hpe.com>
  • Loading branch information
vkoukis committed Aug 28, 2023
1 parent 71cbc18 commit 41cd745
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pygments/lexers/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def get_tokens_unprocessed(self, text):
[(0, Generic.Prompt.VirtualEnv, venv)]))
if venv_whitespace:
insertions.append((len(curcode),
[(0, Text, venv_whitespace)]))
[(0, Generic.Prompt.VirtualEnv, venv_whitespace)]))
line = line[venv_match.end():]

m = self._ps1rgx.match(line)
Expand Down
2 changes: 1 addition & 1 deletion tests/snippets/console/test_virtualenv.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

---tokens---
'(env)' Generic.Prompt.VirtualEnv
' ' Text
' ' Generic.Prompt.VirtualEnv
'[~/project]$ ' Generic.Prompt
'foo' Text
' ' Text.Whitespace
Expand Down

0 comments on commit 41cd745

Please sign in to comment.