Skip to content

Commit

Permalink
traceback polish
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Feb 15, 2020
1 parent 6b91b8a commit 2517bc7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion rich/default_styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"traceback.text": Style(),
"traceback.filename": Style(color="green"),
"traceback.lineno": Style(bold=True, color="cyan"),
"traceback.name": Style(color="yellow"),
"traceback.name": Style(color="yellow", italic=True),
"traceback.exc_type": Style(color="bright_red", bold=True),
"traceback.exc_value": Style(),
}
Expand Down
13 changes: 8 additions & 5 deletions rich/traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from dataclasses import dataclass, field
from traceback import extract_tb
from typing import Type, List
from typing import Optional, Type, List

from .console import Console, ConsoleOptions, RenderResult
from .console import Console, ConsoleOptions, ConsoleRenderable, RenderResult
from .constrain import Constrain
from .highlighter import RegexHighlighter, ReprHighlighter
from .padding import Padding
Expand Down Expand Up @@ -53,11 +53,11 @@ class Trace:


class PathHighlighter(RegexHighlighter):
highlights = [r'"(?P<dim>.*/)(?P<b>.+)"']
highlights = [r'"(?P<dim>.*/)(?P<_>.+)"']


class Traceback:
def __init__(self, trace: Trace = None, code_width: int = 88):
def __init__(self, trace: Trace = None, code_width: Optional[int] = 88):
if trace is None:
trace = self.extract(*sys.exc_info())
self.trace = trace
Expand Down Expand Up @@ -94,7 +94,10 @@ def __console__(self, console: Console, options: ConsoleOptions) -> RenderResult
highlighter = ReprHighlighter()
for last, stack in iter_last(reversed(self.trace.stacks)):
yield Text.from_markup("[b]Traceback[/b] [dim](most recent call last):")
yield Constrain(Panel(stack, style="blue"), width=self.code_width)
stack_renderable: ConsoleRenderable = Panel(stack, style="blue")
if self.code_width is not None:
stack_renderable = Constrain(stack_renderable, width=self.code_width)
yield stack_renderable
yield Text.assemble((f"{stack.exc_type}: ", "traceback.exc_type"), end="")
yield highlighter(stack.exc_value)
if not last:
Expand Down

0 comments on commit 2517bc7

Please sign in to comment.