summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeert Smelt <Anthirian@users.noreply.github.com>2020-06-30 10:49:58 +0200
committerGitHub <noreply@github.com>2020-06-30 10:49:58 +0200
commitb5577a68a9c286f4bce157d63e8c83ed8d70e704 (patch)
tree331092f227cb1ebb0ec08834809d54cd90350f8b
parent18d1f8f3afd60df65da736a1393b534d245cb58a (diff)
downloadpygments-git-b5577a68a9c286f4bce157d63e8c83ed8d70e704.tar.gz
Add support for PowerShell Remoting sessions (#1398)
* Add support for PowerShell Remoting sessions * Add test case for PowerShell Remoting sessions * Make whitespace after prompt optional * Fix test case containing backslashes * Add test case for local PowerShell sessions
-rw-r--r--pygments/lexers/shell.py2
-rw-r--r--tests/test_shell.py30
2 files changed, 30 insertions, 2 deletions
diff --git a/pygments/lexers/shell.py b/pygments/lexers/shell.py
index a7f12ff6..bc55a52a 100644
--- a/pygments/lexers/shell.py
+++ b/pygments/lexers/shell.py
@@ -773,7 +773,7 @@ class PowerShellSessionLexer(ShellSessionBaseLexer):
mimetypes = []
_innerLexerCls = PowerShellLexer
- _ps1rgx = re.compile(r'^(PS [^>]+> )(.*\n?)')
+ _ps1rgx = re.compile(r'^((?:\[[^]]+\]: )?PS [^>]+> ?)(.*\n?)')
_ps2 = '>> '
diff --git a/tests/test_shell.py b/tests/test_shell.py
index 64918a2e..753a37e3 100644
--- a/tests/test_shell.py
+++ b/tests/test_shell.py
@@ -10,7 +10,7 @@
import pytest
from pygments.token import Token
-from pygments.lexers import BashLexer, BashSessionLexer, MSDOSSessionLexer
+from pygments.lexers import BashLexer, BashSessionLexer, MSDOSSessionLexer, PowerShellSessionLexer
@pytest.fixture(scope='module')
@@ -28,6 +28,11 @@ def lexer_msdos():
yield MSDOSSessionLexer()
+@pytest.fixture(scope='module')
+def lexer_powershell_session():
+ yield PowerShellSessionLexer()
+
+
def test_curly_no_escape_and_quotes(lexer_bash):
fragment = u'echo "${a//["b"]/}"\n'
tokens = [
@@ -163,6 +168,29 @@ def test_msdos_gt_only(lexer_msdos):
]
assert list(lexer_msdos.get_tokens(fragment)) == tokens
+
+def test_powershell_session(lexer_powershell_session):
+ fragment = u'PS C:\\> Get-ChildItem\n'
+ tokens = [
+ (Token.Name.Builtin, u''),
+ (Token.Generic.Prompt, u'PS C:\\> '),
+ (Token.Name.Builtin, u'Get-ChildItem'),
+ (Token.Text, u'\n')
+ ]
+ assert list(lexer_powershell_session.get_tokens(fragment)) == tokens
+
+
+def test_powershell_remoting_session(lexer_powershell_session):
+ fragment = u'[Long-NetBIOS-Hostname]: PS C:\\> Get-ChildItem\n'
+ tokens = [
+ (Token.Name.Builtin, u''),
+ (Token.Generic.Prompt, u'[Long-NetBIOS-Hostname]: PS C:\\> '),
+ (Token.Name.Builtin, u'Get-ChildItem'),
+ (Token.Text, u'\n')
+ ]
+ assert list(lexer_powershell_session.get_tokens(fragment)) == tokens
+
+
def test_virtualenv(lexer_session):
fragment = u'(env) [~/project]$ foo -h\n'
tokens = [