Skip to content

Commit

Permalink
Update formatter.py
Browse files Browse the repository at this point in the history
Initial implementation of hyperlinks, set BETTER_EXCEPTIONS_HYPERLINKS=1 to activate.
  • Loading branch information
stuaxo committed Aug 27, 2019
1 parent 4dab3e2 commit 28af958
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion better_exceptions/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@

MAX_LENGTH = 128

if os.environ.get("BETTER_EXCEPTIONS_HYPERLINKS") == "1":
HOSTNAME = os.uname()[1]
FORMAT_FILENAME = "\033]8;;file://{hostname}{filename}\033\\{filename}\033]8;;\033\\"
else:
FORMAT_FILENAME = "{filename}"


def isast(v):
return inspect.isclass(v) and issubclass(v, ast.AST)
Expand Down Expand Up @@ -250,7 +256,8 @@ def format_traceback_frame(self, tb):
lines.append(self._theme['inspect'](line) if self._colored else line)
formatted = u'\n '.join([to_unicode(x) for x in lines])

return (filename, lineno, function, formatted), color_source
formatted_filename = FORMAT_FILENAME.format(hostname=HOSTNAME, filename=filename, lineno=lineno)
return (formatted_filename, lineno, function, formatted), color_source


def format_traceback(self, tb=None):
Expand Down

0 comments on commit 28af958

Please sign in to comment.