Christian Jann avatar Christian Jann committed 97f49ab

Added ShellSessionLexer

Comments (0)

Files changed (5)

 * Hiram Chirino -- Scaml and Jade lexers
 * Ian Cooper -- VGL lexer
 * Leaf Corcoran -- MoonScript lexer
+* Christian Jann -- ShellSession lexer
 * Christopher Creutzig -- MuPAD lexer
 * Pete Curry -- bugfixes
 * Owen Durni -- haXe lexer

pygments/lexers/_mapping.py

     'SchemeLexer': ('pygments.lexers.functional', 'Scheme', ('scheme', 'scm'), ('*.scm', '*.ss'), ('text/x-scheme', 'application/x-scheme')),
     'ScilabLexer': ('pygments.lexers.math', 'Scilab', ('scilab',), ('*.sci', '*.sce', '*.tst'), ('text/scilab',)),
     'ScssLexer': ('pygments.lexers.web', 'SCSS', ('scss',), ('*.scss',), ('text/x-scss',)),
+    'ShellSessionLexer': ('pygments.lexers.shell', 'Shell Session', ('shell-session',), ('*.shell-session',), ('application/x-sh-session',)),
     'SmaliLexer': ('pygments.lexers.dalvik', 'Smali', ('smali',), ('*.smali',), ('text/smali',)),
     'SmalltalkLexer': ('pygments.lexers.other', 'Smalltalk', ('smalltalk', 'squeak'), ('*.st',), ('text/x-smalltalk',)),
     'SmartyLexer': ('pygments.lexers.templates', 'Smarty', ('smarty',), ('*.tpl',), ('application/x-smarty',)),

pygments/lexers/shell.py

 
 
 __all__ = ['BashLexer', 'BashSessionLexer', 'TcshLexer', 'BatchLexer',
-           'PowerShellLexer']
+           'PowerShellLexer', 'ShellSessionLexer']
 
 line_re  = re.compile('.*?\n')
 
                 yield pos+i, t, v
 
 
+class ShellSessionLexer(Lexer):
+    """
+    Lexer for shell sessions that works with different command prompts
+
+    *New in Pygments 1.6.*
+    """
+
+    name = 'Shell Session'
+    aliases = ['shell-session']
+    filenames = ['*.shell-session']
+    mimetypes = ['application/x-sh-session']
+
+    def get_tokens_unprocessed(self, text):
+        bashlexer = BashLexer(**self.options)
+
+        pos = 0
+        curcode = ''
+        insertions = []
+
+        for match in line_re.finditer(text):
+            line = match.group()
+            m = re.match(r'^((?:\[?\S+@[^$#%]+)[$#%])(.*\n?)', line)
+            if m:
+                # To support output lexers (say diff output), the output
+                # needs to be broken by prompts whenever the output lexer
+                # changes.
+                if not insertions:
+                    pos = match.start()
+
+                insertions.append((len(curcode),
+                                   [(0, Generic.Prompt, m.group(1))]))
+                curcode += m.group(2)
+            else:
+                if insertions:
+                    toks = bashlexer.get_tokens_unprocessed(curcode)
+                    for i, t, v in do_insertions(insertions, toks):
+                        yield pos+i, t, v
+                yield match.start(), Generic.Output, line
+                insertions = []
+                curcode = ''
+        if insertions:
+            for i, t, v in do_insertions(insertions,
+                                         bashlexer.get_tokens_unprocessed(curcode)):
+                yield pos+i, t, v
+
+
 class BatchLexer(RegexLexer):
     """
     Lexer for the DOS/Windows Batch file format.

tests/examplefiles/example.shell-session

+[user@linuxbox imx-bootlets-src-10.05.02]$ make CROSS_COMPILE=arm-none-eabi-  clean
+rm -rf *.sb
+rm -f sd_mmc_bootstream.raw
+rm -f linux_prep/board/*.o
+...
+Files:
+rm -f power_prep.o eabi.o
+Build output:
+make[1]: Leaving directory `/home/...'
+[user@linuxbox imx-bootlets-src-10.05.02]$ make CROSS_COMPILE=arm-none-eabi-
+make[1]: Entering directory `/home/...'
+...
+#@echo "generating U-Boot boot stream image"
+#elftosb2 -z -c ./uboot_prebuilt.db -o imx23_uboot.sb
+echo "generating kernel bootstream file sd_mmc_bootstream.raw"
+generating kernel bootstream file sd_mmc_bootstream.raw
+#Please use cfimager to burn xxx_linux.sb. The below way will no
+#work at imx28 platform.
+> test
+$ test
+rm -f sd_mmc_bootstream.raw
+[user@linuxbox imx-bootlets-src-10.05.02]$
+pi@raspberrypi ~ $ sudo sh -c "echo 17 > /sys/class/gpio/export"
+pi@raspberrypi ~ $ sudo sh -c "echo out > /sys/class/gpio/gpio17/direction"
+pi@raspberrypi ~ $ sudo sh -c "echo 1 > /sys/class/gpio/gpio17/value"
+pi@raspberrypi ~ $ sudo sh -c "echo 0 > /sys/class/gpio/gpio17/value"
+pi@raspberrypi ~ $
+[user@linuxbox ~]$ # copy other stuff to the SD card
+root@imx233-olinuxino-micro:~# lsmod
+  Not tainted
+[user@linuxbox ~]$ tail -n 2 /mnt/rpi/etc/inittab
+#Spawn a getty on Raspberry Pi serial line
+T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
+pi@raspberrypi:~/Adafruit-WebIDE$ mkdir tmp
+pi@raspberrypi:~/Adafruit-WebIDE$ npm config set tmp tmp
+pi@raspberrypi:~/Adafruit-WebIDE$ npm install
+pi@raspberrypi ~/Adafruit-WebIDE $ ifconfig eth0
+eth0      Link encap:Ethernet  HWaddr b5:33:ff:33:ee:aq
+          inet addr:10.42.0.60  Bcast:10.42.0.255  Mask:255.255.255.0
+          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
+          RX packets:21867 errors:0 dropped:0 overruns:0 frame:0
+          TX packets:8684 errors:0 dropped:0 overruns:0 carrier:0
+          collisions:0 txqueuelen:1000
+          RX bytes:27338495 (26.0 MiB)  TX bytes:1268356 (1.2 MiB)
+

tests/test_basic_api.py

             'SqliteConsoleLexer', 'MatlabSessionLexer', 'ErlangShellLexer',
             'BashSessionLexer', 'LiterateHaskellLexer', 'PostgresConsoleLexer',
             'ElixirConsoleLexer', 'JuliaConsoleLexer', 'RobotFrameworkLexer',
-            'DylanConsoleLexer'):
+            'DylanConsoleLexer', 'ShellSessionLexer'):
             inst = cls(ensurenl=False)
             ensure(inst.get_tokens('a\nb'), 'a\nb')
             inst = cls(ensurenl=False, stripall=True)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.