MCPcopy
hub / github.com/Textualize/rich / __rich_console__

Method __rich_console__

rich/traceback.py:626–726  ·  view source on GitHub ↗
(
        self, console: Console, options: ConsoleOptions
    )

Source from the content-addressed store, hash-verified

624 return trace
625
626 def __rich_console__(
627 self, console: Console, options: ConsoleOptions
628 ) -> RenderResult:
629 theme = self.theme
630 background_style = theme.get_background_style()
631 token_style = theme.get_style_for_token
632
633 traceback_theme = Theme(
634 {
635 "pretty": token_style(TextToken),
636 "pygments.text": token_style(Token),
637 "pygments.string": token_style(String),
638 "pygments.function": token_style(Name.Function),
639 "pygments.number": token_style(Number),
640 "repr.indent": token_style(Comment) + Style(dim=True),
641 "repr.str": token_style(String),
642 "repr.brace": token_style(TextToken) + Style(bold=True),
643 "repr.number": token_style(Number),
644 "repr.bool_true": token_style(Keyword.Constant),
645 "repr.bool_false": token_style(Keyword.Constant),
646 "repr.none": token_style(Keyword.Constant),
647 "scope.border": token_style(String.Delimiter),
648 "scope.equals": token_style(Operator),
649 "scope.key": token_style(Name),
650 "scope.key.special": token_style(Name.Constant) + Style(dim=True),
651 },
652 inherit=False,
653 )
654
655 highlighter = ReprHighlighter()
656
657 @group()
658 def render_stack(stack: Stack, last: bool) -> RenderResult:
659 if stack.frames:
660 stack_renderable: ConsoleRenderable = Panel(
661 self._render_stack(stack),
662 title="[traceback.title]Traceback [dim](most recent call last)",
663 style=background_style,
664 border_style="traceback.border",
665 expand=True,
666 padding=(0, 1),
667 )
668 stack_renderable = Constrain(stack_renderable, self.width)
669 with console.use_theme(traceback_theme):
670 yield stack_renderable
671
672 if stack.syntax_error is not None:
673 with console.use_theme(traceback_theme):
674 yield Constrain(
675 Panel(
676 self._render_syntax_error(stack.syntax_error),
677 style=background_style,
678 border_style="traceback.border.syntax_error",
679 expand=True,
680 padding=(0, 1),
681 width=self.width,
682 ),
683 self.width,

Callers

nothing calls this directly

Calls 5

ThemeClass · 0.85
StyleClass · 0.85
ReprHighlighterClass · 0.85
loop_lastFunction · 0.85
get_background_styleMethod · 0.45

Tested by

no test coverage detected