diff options
-rw-r--r-- | CHANGES | 1 | ||||
-rw-r--r-- | doc/languages.rst | 48 | ||||
-rw-r--r-- | pygments/lexers/shell.py | 5 | ||||
-rw-r--r-- | tests/test_shell.py | 18 |
4 files changed, 69 insertions, 3 deletions
@@ -34,6 +34,7 @@ Version 2.7.0 * Matlab (PR#1399) * NASM (PR#1465) * Nim (PR#1426) + * PowerShell Session (PR#1497) * SQL (PR#1402) * SystemVerilog (PR#1436, PR#1452, PR#1454, PR#1460, PR#1462, PR#1463, PR#1464) * TeraTerm (PR#1337) diff --git a/doc/languages.rst b/doc/languages.rst index ecb9d460..1bb7e7f9 100644 --- a/doc/languages.rst +++ b/doc/languages.rst @@ -293,6 +293,54 @@ Other markup * YANG * Windows Registry files + +Interactive terminal/shell sessions +----------------------------------- + +To highlight an interactive terminal or shell session, prefix your code snippet +with a specially formatted prompt. + +Supported shells with examples are shown below. In each example, prompt parts in +brackets ``[any]`` represent optional parts of the prompt, and prompt parts +without brackets or in parenthesis ``(any)`` represent required parts of the +prompt. + +* **Bash Session** (console, shell-session): + + .. code-block:: console + + [any@any]$ ls -lh + [any@any]# ls -lh + [any@any]% ls -lh + $ ls -lh + # ls -lh + % ls -lh + > ls -lh + +* **MSDOS Session** (doscon): + + .. code-block:: doscon + + [any]> dir + > dir + More? dir + +* **Tcsh Session** (tcshcon): + + .. code-block:: tcshcon + + (any)> ls -lh + ? ls -lh + +* **PowerShell Session** (ps1con): + + .. code-block:: ps1con + + PS[any]> Get-ChildItem + PS> Get-ChildItem + >> Get-ChildItem + + ... that's all? --------------- diff --git a/pygments/lexers/shell.py b/pygments/lexers/shell.py index bc55a52a..3b5218b8 100644 --- a/pygments/lexers/shell.py +++ b/pygments/lexers/shell.py @@ -172,7 +172,7 @@ class ShellSessionBaseLexer(Lexer): curcode += line backslash_continuation = curcode.endswith('\\\n') continue - + venv_match = self._venv.match(line) if venv_match: venv = venv_match.group(1) @@ -773,7 +773,7 @@ class PowerShellSessionLexer(ShellSessionBaseLexer): mimetypes = [] _innerLexerCls = PowerShellLexer - _ps1rgx = re.compile(r'^((?:\[[^]]+\]: )?PS [^>]+> ?)(.*\n?)') + _ps1rgx = re.compile(r'^((?:\[[^]]+\]: )?PS[^>]*> ?)(.*\n?)') _ps2 = '>> ' @@ -907,4 +907,3 @@ class ExeclineLexer(RegexLexer): def analyse_text(text): if shebang_matches(text, r'execlineb'): return 1 - diff --git a/tests/test_shell.py b/tests/test_shell.py index 753a37e3..42814a0b 100644 --- a/tests/test_shell.py +++ b/tests/test_shell.py @@ -179,6 +179,24 @@ def test_powershell_session(lexer_powershell_session): ] assert list(lexer_powershell_session.get_tokens(fragment)) == tokens + fragment = u'PS> Get-ChildItem\n' + tokens = [ + (Token.Name.Builtin, u''), + (Token.Generic.Prompt, u'PS> '), + (Token.Name.Builtin, u'Get-ChildItem'), + (Token.Text, u'\n') + ] + assert list(lexer_powershell_session.get_tokens(fragment)) == tokens + + fragment = u'PS > Get-ChildItem\n' + tokens = [ + (Token.Name.Builtin, u''), + (Token.Generic.Prompt, u'PS > '), + (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' |