FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add lexers to command view · Python-Repository-Hub/voltron@b33ae1c · GitHub

Commit b33ae1c

Browse files
committed
Add lexers to command view
1 parent f31d5d8 commit b33ae1c

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ The author's setup looks something like this:
2222

2323
Any debugger command can be split off into a view:
2424

25-
![command views](http://i.imgur.com/iatgsgN.png)
25+
![command views](http://i.imgur.com/mqptE3Z.png)
2626

2727
More screenshots are [here](https://github.com/snare/voltron/wiki/Screenshots).
2828

‎voltron/plugins/view/command.py‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
import logging
2+
import importlib
3+
try:
4+
from pygments.lexers import get_lexer_by_name
5+
except:
6+
get_lexer_by_name = None
27

38
from voltron.view import *
49
from voltron.plugin import *
510
from voltron.api import *
611

712
log = logging.getLogger('view')
813

14+
915
class CommandView (TerminalView):
1016
@classmethod
1117
def configure_subparser(cls, subparsers):
1218
sp = subparsers.add_parser('command', aliases=('c', 'cmd'),
1319
help='run a command each time the debugger host stops')
1420
VoltronView.add_generic_arguments(sp)
1521
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)
1625
sp.set_defaults(func=CommandView)
1726

1827
def render(self):
@@ -27,8 +36,15 @@ def render(self):
2736
return
2837

2938
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
3248
else:
3349
log.error("Error executing command: {}".format(res.message))
3450
self.body = self.colour(res.message, 'red')

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL