Get the Segments for the Syntax object, excluding any vertical/horizontal padding
(
self,
console: Console,
options: ConsoleOptions,
)
| 650 | yield segments |
| 651 | |
| 652 | def _get_syntax( |
| 653 | self, |
| 654 | console: Console, |
| 655 | options: ConsoleOptions, |
| 656 | ) -> Iterable[Segment]: |
| 657 | """ |
| 658 | Get the Segments for the Syntax object, excluding any vertical/horizontal padding |
| 659 | """ |
| 660 | transparent_background = self._get_base_style().transparent_background |
| 661 | _pad_top, pad_right, _pad_bottom, pad_left = self.padding |
| 662 | horizontal_padding = pad_left + pad_right |
| 663 | code_width = ( |
| 664 | ( |
| 665 | (options.max_width - self._numbers_column_width - 1) |
| 666 | if self.line_numbers |
| 667 | else options.max_width |
| 668 | ) |
| 669 | - horizontal_padding |
| 670 | if self.code_width is None |
| 671 | else self.code_width |
| 672 | ) |
| 673 | code_width = max(0, code_width) |
| 674 | |
| 675 | ends_on_nl, processed_code = self._process_code(self.code) |
| 676 | text = self.highlight(processed_code, self.line_range) |
| 677 | |
| 678 | if not self.line_numbers and not self.word_wrap and not self.line_range: |
| 679 | if not ends_on_nl: |
| 680 | text.remove_suffix("\n") |
| 681 | # Simple case of just rendering text |
| 682 | style = ( |
| 683 | self._get_base_style() |
| 684 | + self._theme.get_style_for_token(Comment) |
| 685 | + Style(dim=True) |
| 686 | + self.background_style |
| 687 | ) |
| 688 | if self.indent_guides and not options.ascii_only: |
| 689 | text = text.with_indent_guides(self.tab_size, style=style) |
| 690 | text.overflow = "crop" |
| 691 | if style.transparent_background: |
| 692 | yield from console.render( |
| 693 | text, options=options.update(width=code_width) |
| 694 | ) |
| 695 | else: |
| 696 | syntax_lines = console.render_lines( |
| 697 | text, |
| 698 | options.update(width=code_width, height=None, justify="left"), |
| 699 | style=self.background_style, |
| 700 | pad=True, |
| 701 | new_lines=True, |
| 702 | ) |
| 703 | for syntax_line in syntax_lines: |
| 704 | yield from syntax_line |
| 705 | return |
| 706 | |
| 707 | start_line, end_line = self.line_range or (None, None) |
| 708 | line_offset = 0 |
| 709 | if start_line: |
no test coverage detected