summaryrefslogtreecommitdiff
path: root/pygments
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2022-10-26 21:12:22 +0200
committerGeorg Brandl <georg@python.org>2022-10-28 17:52:51 +0200
commit2fbffb07087f78f16e84f141a28e14118ecd5b75 (patch)
tree5c6d97d21c6de8d0c83e1eb4c0fe2c20d6d0b136 /pygments
parentcffc5df62c258ca39fc7474f7197f2df33ab014f (diff)
downloadpygments-git-2fbffb07087f78f16e84f141a28e14118ecd5b75.tar.gz
shell session: allow continuation without marker for PowerShell
Fixes #2262
Diffstat (limited to 'pygments')
-rw-r--r--pygments/lexers/shell.py16
1 files changed, 12 insertions, 4 deletions
diff --git a/pygments/lexers/shell.py b/pygments/lexers/shell.py
index be74a040..e25274eb 100644
--- a/pygments/lexers/shell.py
+++ b/pygments/lexers/shell.py
@@ -154,6 +154,7 @@ class ShellSessionBaseLexer(Lexer):
.. versionadded:: 2.1
"""
+ _bare_continuation = False
_venv = re.compile(r'^(\([^)]*\))(\s*)')
def get_tokens_unprocessed(self, text):
@@ -172,10 +173,10 @@ class ShellSessionBaseLexer(Lexer):
venv = venv_match.group(1)
venv_whitespace = venv_match.group(2)
insertions.append((len(curcode),
- [(0, Generic.Prompt.VirtualEnv, venv)]))
+ [(0, Generic.Prompt.VirtualEnv, venv)]))
if venv_whitespace:
insertions.append((len(curcode),
- [(0, Text, venv_whitespace)]))
+ [(0, Text, venv_whitespace)]))
line = line[venv_match.end():]
m = self._ps1rgx.match(line)
@@ -193,11 +194,17 @@ class ShellSessionBaseLexer(Lexer):
elif backslash_continuation:
if line.startswith(self._ps2):
insertions.append((len(curcode),
- [(0, Generic.Prompt, line[:len(self._ps2)])]))
+ [(0, Generic.Prompt,
+ line[:len(self._ps2)])]))
curcode += line[len(self._ps2):]
else:
curcode += line
backslash_continuation = curcode.endswith('\\\n')
+ elif self._bare_continuation and line.startswith(self._ps2):
+ insertions.append((len(curcode),
+ [(0, Generic.Prompt,
+ line[:len(self._ps2)])]))
+ curcode += line[len(self._ps2):]
else:
if insertions:
toks = innerlexer.get_tokens_unprocessed(curcode)
@@ -774,8 +781,9 @@ class PowerShellSessionLexer(ShellSessionBaseLexer):
mimetypes = []
_innerLexerCls = PowerShellLexer
+ _bare_continuation = True
_ps1rgx = re.compile(r'^((?:\[[^]]+\]: )?PS[^>]*> ?)(.*\n?)')
- _ps2 = '>> '
+ _ps2 = '> '
class FishShellLexer(RegexLexer):