| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,7 +22,7 @@ The author's setup looks something like this: | |||
| 22 | 22 | ||
| 23 | 23 | Any debugger command can be split off into a view: | |
| 24 | 24 | ||
| 25 | -  | ||
| 25 | +  | ||
| 26 | 26 | ||
| 27 | 27 | More screenshots are [here](https://github.com/snare/voltron/wiki/Screenshots). | |
| 28 | 28 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,18 +1,27 @@ | |||
| 1 | 1 | import logging | |
| 2 | + import importlib | ||
| 3 | + try: | ||
| 4 | + from pygments.lexers import get_lexer_by_name | ||
| 5 | + except: | ||
| 6 | + get_lexer_by_name = None | ||
| 2 | 7 | ||
| 3 | 8 | from voltron.view import * | |
| 4 | 9 | from voltron.plugin import * | |
| 5 | 10 | from voltron.api import * | |
| 6 | 11 | ||
| 7 | 12 | log = logging.getLogger('view') | |
| 8 | 13 | ||
| 14 | + | ||
| 9 | 15 | class CommandView (TerminalView): | |
| 10 | 16 | @classmethod | |
| 11 | 17 | def configure_subparser(cls, subparsers): | |
| 12 | 18 | sp = subparsers.add_parser('command', aliases=('c', 'cmd'), | |
| 13 | 19 | help='run a command each time the debugger host stops') | |
| 14 | 20 | VoltronView.add_generic_arguments(sp) | |
| 15 | 21 | sp.add_argument('command', action='store', help='command to run') | |
| 22 | + sp.add_argument('--lexer', '-l', action='store', | ||
| 23 | + help='apply a Pygments lexer to the command output (e.g. "c")', | ||
| 24 | + default=None) | ||
| 16 | 25 | sp.set_defaults(func=CommandView) | |
| 17 | 26 | ||
| 18 | 27 | def render(self): | |
@@ -27,8 +36,15 @@ def render(self): | |||
| 27 | 36 | return | |
| 28 | 37 | ||
| 29 | 38 | if res and res.is_success: | |
| 30 | - # Get the command output | ||
| 31 | - self.body = res.output | ||
| 39 | + if get_lexer_by_name and self.args.lexer: | ||
| 40 | + try: | ||
| 41 | + lexer = get_lexer_by_name(self.args.lexer, stripall=True) | ||
| 42 | + self.body = pygments.highlight(res.output, lexer, pygments.formatters.TerminalFormatter()) | ||
| 43 | + except Exception as e: | ||
| 44 | + log.warning('Failed to highlight view contents: ' + repr(e)) | ||
| 45 | + self.body = res.output | ||
| 46 | + else: | ||
| 47 | + self.body = res.output | ||
| 32 | 48 | else: | |
| 33 | 49 | log.error("Error executing command: {}".format(res.message)) | |
| 34 | 50 | self.body = self.colour(res.message, 'red') | |
| Back | FazBrowse Home | New Git URL |
0 commit comments