summaryrefslogtreecommitdiff
path: root/pygments/lexers/shell.py
diff options
context:
space:
mode:
authorTim Hatch <tim@timhatch.com>2016-06-01 00:49:28 -0700
committerTim Hatch <tim@timhatch.com>2016-06-01 00:49:28 -0700
commit7c9e7f5d18971e5cc5efe14bff3fd429480a0140 (patch)
tree5a710f10b9841e45708cf19adcb5913a0733fbb2 /pygments/lexers/shell.py
parent0ed2df2cf1625f22d0ee8cfad7d0c711a2ee9fb6 (diff)
downloadpygments-7c9e7f5d18971e5cc5efe14bff3fd429480a0140.tar.gz
Add backslash-continuation support to console lexer.
Fixes #1237
Diffstat (limited to 'pygments/lexers/shell.py')
-rw-r--r--pygments/lexers/shell.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/pygments/lexers/shell.py b/pygments/lexers/shell.py
index b9368ade..ae790b9e 100644
--- a/pygments/lexers/shell.py
+++ b/pygments/lexers/shell.py
@@ -137,11 +137,15 @@ class ShellSessionBaseLexer(Lexer):
pos = 0
curcode = ''
insertions = []
+ backslash_continuation = False
for match in line_re.finditer(text):
line = match.group()
m = re.match(self._ps1rgx, line)
- if m:
+ if backslash_continuation:
+ curcode += line
+ backslash_continuation = curcode.endswith('\\\n')
+ elif m:
# To support output lexers (say diff output), the output
# needs to be broken by prompts whenever the output lexer
# changes.
@@ -151,10 +155,12 @@ class ShellSessionBaseLexer(Lexer):
insertions.append((len(curcode),
[(0, Generic.Prompt, m.group(1))]))
curcode += m.group(2)
+ backslash_continuation = curcode.endswith('\\\n')
elif line.startswith(self._ps2):
insertions.append((len(curcode),
[(0, Generic.Prompt, line[:len(self._ps2)])]))
curcode += line[len(self._ps2):]
+ backslash_continuation = curcode.endswith('\\\n')
else:
if insertions:
toks = innerlexer.get_tokens_unprocessed(curcode)