Created
August 18, 2014 15:00
-
-
Save mlauter/e9b5d707eb7ef074fc5e to your computer and use it in GitHub Desktop.
pygments traceback coloring
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from pygments.style import Style | |
#from pygments.token import Keyword, Name, Comment, String, Error, Number, Operator, Generic, Token, Whitespace | |
class BpcTracebackStyle(Style): | |
default_style = "" #put something here? | |
styles = { | |
Comment: 'bold #888', | |
Keyword: 'bold #005', | |
Name: '#f00', | |
Name.Function: '#0f0', | |
Name.Class: 'bold #0f0', | |
String: 'bg:#eee #111' | |
} | |
def myexcepthook(type, value, tb): | |
import traceback | |
from pygments import highlight | |
from pygments.lexers import get_lexer_by_name | |
from pygments.formatters import Terminal256Formatter | |
from pygments.styles import get_style_by_name | |
tbtext = ''.join(traceback.format_exception(type, value, tb)) | |
lexer = get_lexer_by_name("pytb", stripall=True) | |
formatter = Terminal256Formatter(style='colorful') | |
sys.stderr.write(highlight(tbtext, lexer, formatter)) | |
def g(): f() | |
def f(): 1/0 | |
sys.excepthook = myexcepthook | |
g() | |
#colorscheme={Name.Builtin:("red","blue")} | |
#['monokai', 'manni', 'rrt', 'perldoc', 'borland', 'colorful', 'default', 'murphy', 'vs', 'trac', 'tango', 'fruity', 'autumn', 'bw', 'emacs', 'vim', 'pastie', 'friendly', 'native'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment