Method: rich.syntax.Syntax._get_syntax
Calls: 39, Exceptions: 0, Paths: 13Back
Path 1: 15 calls (0.38)
Console (15)
ConsoleOptions (15)
Segment (1068)
1def _get_syntax(
2 self,
3 console: Console,
4 options: ConsoleOptions,
5 ) -> Iterable[Segment]:
6 """
7 Get the Segments for the Syntax object, excluding any vertical/horizontal padding
8 """
9 transparent_background = self._get_base_style().transparent_background
10 code_width = (
11 (
12 (options.max_width - self._numbers_column_width - 1)
13 if self.line_numbers
14 else options.max_width
15 )
16 if self.code_width is None
17 else self.code_width
18 )
19
20 ends_on_nl, processed_code = self._process_code(self.code)
21 text = self.highlight(processed_code, self.line_range)
22
23 if not self.line_numbers and not self.word_wrap and not self.line_range:
24 if not ends_on_nl:
25 text.remove_suffix("\n")
26 # Simple case of just rendering text
27 style = (
28 self._get_base_style()
29 + self._theme.get_style_for_token(Comment)
30 + Style(dim=True)
31 + self.background_style
32 )
33 if self.indent_guides and not options.ascii_only:
34 text = text.with_indent_guides(self.tab_size, style=style)
35 text.overflow = "crop"
36 if style.transparent_background:
37 yield from console.render(
38 text, options=options.update(width=code_width)
39 )
40 else:
41 syntax_lines = console.render_lines(
42 text,
43 options.update(width=code_width, height=None, justify="left"),
44 style=self.background_style,
45 pad=True,
46 new_lines=True,
47 )
48 for syntax_line in syntax_lines:
49 yield from syntax_line
50 return
51
52 start_line, end_line = self.line_range or (None, None)
53 line_offset = 0
54 if start_line:
55 line_offset = max(0, start_line - 1)
56 lines: Union[List[Text], Lines] = text.split("\n", allow_blank=ends_on_nl)
57 if self.line_range:
58 lines = lines[line_offset:end_line]
59
60 if self.indent_guides and not options.ascii_only:
61 style = (
62 self._get_base_style()
63 + self._theme.get_style_for_token(Comment)
64 + Style(dim=True)
65 + self.background_style
66 )
67 lines = (
68 Text("\n")
69 .join(lines)
70 .with_indent_guides(self.tab_size, style=style)
71 .split("\n", allow_blank=True)
72 )
73
74 numbers_column_width = self._numbers_column_width
75 render_options = options.update(width=code_width)
76
77 highlight_line = self.highlight_lines.__contains__
78 _Segment = Segment
79 new_line = _Segment("\n")
80
81 line_pointer = "> " if options.legacy_windows else "❱ "
82
83 (
84 background_style,
85 number_style,
86 highlight_number_style,
87 ) = self._get_number_styles(console)
88
89 for line_no, line in enumerate(lines, self.start_line + line_offset):
90 if self.word_wrap:
91 wrapped_lines = console.render_lines(
92 line,
93 render_options.update(height=None, justify="left"),
94 style=background_style,
95 pad=not transparent_background,
96 )
97 else:
98 segments = list(line.render(console, end=""))
99 if options.no_wrap:
100 wrapped_lines = [segments]
101 else:
102 wrapped_lines = [
103 _Segment.adjust_line_length(
104 segments,
105 render_options.max_width,
106 style=background_style,
107 pad=not transparent_background,
108 )
109 ]
110
111 if self.line_numbers:
112 wrapped_line_left_pad = _Segment(
113 " " * numbers_column_width + " ", background_style
114 )
115 for first, wrapped_line in loop_first(wrapped_lines):
116 if first:
117 line_column = str(line_no).rjust(numbers_column_width - 2) + " "
118 if highlight_line(line_no):
119 yield _Segment(line_pointer, Style(color="red"))
120 yield _Segment(line_column, highlight_number_style)
121 else:
122 yield _Segment(" ", highlight_number_style)
123 yield _Segment(line_column, number_style)
124 else:
125 yield wrapped_line_left_pad
126 yield from wrapped_line
127 yield new_line
128 else:
129 for wrapped_line in wrapped_lines:
130 yield from wrapped_line
131 yield new_line
Path 2: 8 calls (0.21)
Console (8)
ConsoleOptions (8)
Segment (26)
1def _get_syntax(
2 self,
3 console: Console,
4 options: ConsoleOptions,
5 ) -> Iterable[Segment]:
6 """
7 Get the Segments for the Syntax object, excluding any vertical/horizontal padding
8 """
9 transparent_background = self._get_base_style().transparent_background
10 code_width = (
11 (
12 (options.max_width - self._numbers_column_width - 1)
13 if self.line_numbers
14 else options.max_width
15 )
16 if self.code_width is None
17 else self.code_width
18 )
19
20 ends_on_nl, processed_code = self._process_code(self.code)
21 text = self.highlight(processed_code, self.line_range)
22
23 if not self.line_numbers and not self.word_wrap and not self.line_range:
24 if not ends_on_nl:
25 text.remove_suffix("\n")
26 # Simple case of just rendering text
27 style = (
28 self._get_base_style()
29 + self._theme.get_style_for_token(Comment)
30 + Style(dim=True)
31 + self.background_style
32 )
33 if self.indent_guides and not options.ascii_only:
34 text = text.with_indent_guides(self.tab_size, style=style)
35 text.overflow = "crop"
36 if style.transparent_background:
37 yield from console.render(
38 text, options=options.update(width=code_width)
39 )
40 else:
41 syntax_lines = console.render_lines(
42 text,
43 options.update(width=code_width, height=None, justify="left"),
44 style=self.background_style,
45 pad=True,
46 new_lines=True,
47 )
48 for syntax_line in syntax_lines:
49 yield from syntax_line
50 return
51
52 start_line, end_line = self.line_range or (None, None)
53 line_offset = 0
54 if start_line:
55 line_offset = max(0, start_line - 1)
56 lines: Union[List[Text], Lines] = text.split("\n", allow_blank=ends_on_nl)
57 if self.line_range:
58 lines = lines[line_offset:end_line]
59
60 if self.indent_guides and not options.ascii_only:
61 style = (
62 self._get_base_style()
63 + self._theme.get_style_for_token(Comment)
64 + Style(dim=True)
65 + self.background_style
66 )
67 lines = (
68 Text("\n")
69 .join(lines)
70 .with_indent_guides(self.tab_size, style=style)
71 .split("\n", allow_blank=True)
72 )
73
74 numbers_column_width = self._numbers_column_width
75 render_options = options.update(width=code_width)
76
77 highlight_line = self.highlight_lines.__contains__
78 _Segment = Segment
79 new_line = _Segment("\n")
80
81 line_pointer = "> " if options.legacy_windows else "❱ "
82
83 (
84 background_style,
85 number_style,
86 highlight_number_style,
87 ) = self._get_number_styles(console)
88
89 for line_no, line in enumerate(lines, self.start_line + line_offset):
90 if self.word_wrap:
91 wrapped_lines = console.render_lines(
92 line,
93 render_options.update(height=None, justify="left"),
94 style=background_style,
95 pad=not transparent_background,
96 )
97 else:
98 segments = list(line.render(console, end=""))
99 if options.no_wrap:
100 wrapped_lines = [segments]
101 else:
102 wrapped_lines = [
103 _Segment.adjust_line_length(
104 segments,
105 render_options.max_width,
106 style=background_style,
107 pad=not transparent_background,
108 )
109 ]
110
111 if self.line_numbers:
112 wrapped_line_left_pad = _Segment(
113 " " * numbers_column_width + " ", background_style
114 )
115 for first, wrapped_line in loop_first(wrapped_lines):
116 if first:
117 line_column = str(line_no).rjust(numbers_column_width - 2) + " "
118 if highlight_line(line_no):
119 yield _Segment(line_pointer, Style(color="red"))
120 yield _Segment(line_column, highlight_number_style)
121 else:
122 yield _Segment(" ", highlight_number_style)
123 yield _Segment(line_column, number_style)
124 else:
125 yield wrapped_line_left_pad
126 yield from wrapped_line
127 yield new_line
128 else:
129 for wrapped_line in wrapped_lines:
130 yield from wrapped_line
131 yield new_line
Path 3: 5 calls (0.13)
Console (5)
ConsoleOptions (5)
Segment (382)
1def _get_syntax(
2 self,
3 console: Console,
4 options: ConsoleOptions,
5 ) -> Iterable[Segment]:
6 """
7 Get the Segments for the Syntax object, excluding any vertical/horizontal padding
8 """
9 transparent_background = self._get_base_style().transparent_background
10 code_width = (
11 (
12 (options.max_width - self._numbers_column_width - 1)
13 if self.line_numbers
14 else options.max_width
15 )
16 if self.code_width is None
17 else self.code_width
18 )
19
20 ends_on_nl, processed_code = self._process_code(self.code)
21 text = self.highlight(processed_code, self.line_range)
22
23 if not self.line_numbers and not self.word_wrap and not self.line_range:
24 if not ends_on_nl:
25 text.remove_suffix("\n")
26 # Simple case of just rendering text
27 style = (
28 self._get_base_style()
29 + self._theme.get_style_for_token(Comment)
30 + Style(dim=True)
31 + self.background_style
32 )
33 if self.indent_guides and not options.ascii_only:
34 text = text.with_indent_guides(self.tab_size, style=style)
35 text.overflow = "crop"
36 if style.transparent_background:
37 yield from console.render(
38 text, options=options.update(width=code_width)
39 )
40 else:
41 syntax_lines = console.render_lines(
42 text,
43 options.update(width=code_width, height=None, justify="left"),
44 style=self.background_style,
45 pad=True,
46 new_lines=True,
47 )
48 for syntax_line in syntax_lines:
49 yield from syntax_line
50 return
51
52 start_line, end_line = self.line_range or (None, None)
53 line_offset = 0
54 if start_line:
55 line_offset = max(0, start_line - 1)
56 lines: Union[List[Text], Lines] = text.split("\n", allow_blank=ends_on_nl)
57 if self.line_range:
58 lines = lines[line_offset:end_line]
59
60 if self.indent_guides and not options.ascii_only:
61 style = (
62 self._get_base_style()
63 + self._theme.get_style_for_token(Comment)
64 + Style(dim=True)
65 + self.background_style
66 )
67 lines = (
68 Text("\n")
69 .join(lines)
70 .with_indent_guides(self.tab_size, style=style)
71 .split("\n", allow_blank=True)
72 )
73
74 numbers_column_width = self._numbers_column_width
75 render_options = options.update(width=code_width)
76
77 highlight_line = self.highlight_lines.__contains__
78 _Segment = Segment
79 new_line = _Segment("\n")
80
81 line_pointer = "> " if options.legacy_windows else "❱ "
82
83 (
84 background_style,
85 number_style,
86 highlight_number_style,
87 ) = self._get_number_styles(console)
88
89 for line_no, line in enumerate(lines, self.start_line + line_offset):
90 if self.word_wrap:
91 wrapped_lines = console.render_lines(
92 line,
93 render_options.update(height=None, justify="left"),
94 style=background_style,
95 pad=not transparent_background,
96 )
97 else:
98 segments = list(line.render(console, end=""))
99 if options.no_wrap:
100 wrapped_lines = [segments]
101 else:
102 wrapped_lines = [
103 _Segment.adjust_line_length(
104 segments,
105 render_options.max_width,
106 style=background_style,
107 pad=not transparent_background,
108 )
109 ]
110
111 if self.line_numbers:
112 wrapped_line_left_pad = _Segment(
113 " " * numbers_column_width + " ", background_style
114 )
115 for first, wrapped_line in loop_first(wrapped_lines):
116 if first:
117 line_column = str(line_no).rjust(numbers_column_width - 2) + " "
118 if highlight_line(line_no):
119 yield _Segment(line_pointer, Style(color="red"))
120 yield _Segment(line_column, highlight_number_style)
121 else:
122 yield _Segment(" ", highlight_number_style)
123 yield _Segment(line_column, number_style)
124 else:
125 yield wrapped_line_left_pad
126 yield from wrapped_line
127 yield new_line
128 else:
129 for wrapped_line in wrapped_lines:
130 yield from wrapped_line
131 yield new_line
Path 4: 2 calls (0.05)
Console (2)
ConsoleOptions (2)
Segment (244)
None (2)
1def _get_syntax(
2 self,
3 console: Console,
4 options: ConsoleOptions,
5 ) -> Iterable[Segment]:
6 """
7 Get the Segments for the Syntax object, excluding any vertical/horizontal padding
8 """
9 transparent_background = self._get_base_style().transparent_background
10 code_width = (
11 (
12 (options.max_width - self._numbers_column_width - 1)
13 if self.line_numbers
14 else options.max_width
15 )
16 if self.code_width is None
17 else self.code_width
18 )
19
20 ends_on_nl, processed_code = self._process_code(self.code)
21 text = self.highlight(processed_code, self.line_range)
22
23 if not self.line_numbers and not self.word_wrap and not self.line_range:
24 if not ends_on_nl:
25 text.remove_suffix("\n")
26 # Simple case of just rendering text
27 style = (
28 self._get_base_style()
29 + self._theme.get_style_for_token(Comment)
30 + Style(dim=True)
31 + self.background_style
32 )
33 if self.indent_guides and not options.ascii_only:
34 text = text.with_indent_guides(self.tab_size, style=style)
35 text.overflow = "crop"
36 if style.transparent_background:
37 yield from console.render(
38 text, options=options.update(width=code_width)
39 )
40 else:
41 syntax_lines = console.render_lines(
42 text,
43 options.update(width=code_width, height=None, justify="left"),
44 style=self.background_style,
45 pad=True,
46 new_lines=True,
47 )
48 for syntax_line in syntax_lines:
49 yield from syntax_line
50 return
51
52 start_line, end_line = self.line_range or (None, None)
53 line_offset = 0
54 if start_line:
55 line_offset = max(0, start_line - 1)
56 lines: Union[List[Text], Lines] = text.split("\n", allow_blank=ends_on_nl)
57 if self.line_range:
58 lines = lines[line_offset:end_line]
59
60 if self.indent_guides and not options.ascii_only:
61 style = (
62 self._get_base_style()
63 + self._theme.get_style_for_token(Comment)
64 + Style(dim=True)
65 + self.background_style
66 )
67 lines = (
68 Text("\n")
69 .join(lines)
70 .with_indent_guides(self.tab_size, style=style)
71 .split("\n", allow_blank=True)
72 )
73
74 numbers_column_width = self._numbers_column_width
75 render_options = options.update(width=code_width)
76
77 highlight_line = self.highlight_lines.__contains__
78 _Segment = Segment
79 new_line = _Segment("\n")
80
81 line_pointer = "> " if options.legacy_windows else "❱ "
82
83 (
84 background_style,
85 number_style,
86 highlight_number_style,
87 ) = self._get_number_styles(console)
88
89 for line_no, line in enumerate(lines, self.start_line + line_offset):
90 if self.word_wrap:
91 wrapped_lines = console.render_lines(
92 line,
93 render_options.update(height=None, justify="left"),
94 style=background_style,
95 pad=not transparent_background,
96 )
97 else:
98 segments = list(line.render(console, end=""))
99 if options.no_wrap:
100 wrapped_lines = [segments]
101 else:
102 wrapped_lines = [
103 _Segment.adjust_line_length(
104 segments,
105 render_options.max_width,
106 style=background_style,
107 pad=not transparent_background,
108 )
109 ]
110
111 if self.line_numbers:
112 wrapped_line_left_pad = _Segment(
113 " " * numbers_column_width + " ", background_style
114 )
115 for first, wrapped_line in loop_first(wrapped_lines):
116 if first:
117 line_column = str(line_no).rjust(numbers_column_width - 2) + " "
118 if highlight_line(line_no):
119 yield _Segment(line_pointer, Style(color="red"))
120 yield _Segment(line_column, highlight_number_style)
121 else:
122 yield _Segment(" ", highlight_number_style)
123 yield _Segment(line_column, number_style)
124 else:
125 yield wrapped_line_left_pad
126 yield from wrapped_line
127 yield new_line
128 else:
129 for wrapped_line in wrapped_lines:
130 yield from wrapped_line
131 yield new_line
Path 5: 1 calls (0.03)
Console (1)
ConsoleOptions (1)
Segment (114)
1def _get_syntax(
2 self,
3 console: Console,
4 options: ConsoleOptions,
5 ) -> Iterable[Segment]:
6 """
7 Get the Segments for the Syntax object, excluding any vertical/horizontal padding
8 """
9 transparent_background = self._get_base_style().transparent_background
10 code_width = (
11 (
12 (options.max_width - self._numbers_column_width - 1)
13 if self.line_numbers
14 else options.max_width
15 )
16 if self.code_width is None
17 else self.code_width
18 )
19
20 ends_on_nl, processed_code = self._process_code(self.code)
21 text = self.highlight(processed_code, self.line_range)
22
23 if not self.line_numbers and not self.word_wrap and not self.line_range:
24 if not ends_on_nl:
25 text.remove_suffix("\n")
26 # Simple case of just rendering text
27 style = (
28 self._get_base_style()
29 + self._theme.get_style_for_token(Comment)
30 + Style(dim=True)
31 + self.background_style
32 )
33 if self.indent_guides and not options.ascii_only:
34 text = text.with_indent_guides(self.tab_size, style=style)
35 text.overflow = "crop"
36 if style.transparent_background:
37 yield from console.render(
38 text, options=options.update(width=code_width)
39 )
40 else:
41 syntax_lines = console.render_lines(
42 text,
43 options.update(width=code_width, height=None, justify="left"),
44 style=self.background_style,
45 pad=True,
46 new_lines=True,
47 )
48 for syntax_line in syntax_lines:
49 yield from syntax_line
50 return
51
52 start_line, end_line = self.line_range or (None, None)
53 line_offset = 0
54 if start_line:
55 line_offset = max(0, start_line - 1)
56 lines: Union[List[Text], Lines] = text.split("\n", allow_blank=ends_on_nl)
57 if self.line_range:
58 lines = lines[line_offset:end_line]
59
60 if self.indent_guides and not options.ascii_only:
61 style = (
62 self._get_base_style()
63 + self._theme.get_style_for_token(Comment)
64 + Style(dim=True)
65 + self.background_style
66 )
67 lines = (
68 Text("\n")
69 .join(lines)
70 .with_indent_guides(self.tab_size, style=style)
71 .split("\n", allow_blank=True)
72 )
73
74 numbers_column_width = self._numbers_column_width
75 render_options = options.update(width=code_width)
76
77 highlight_line = self.highlight_lines.__contains__
78 _Segment = Segment
79 new_line = _Segment("\n")
80
81 line_pointer = "> " if options.legacy_windows else "❱ "
82
83 (
84 background_style,
85 number_style,
86 highlight_number_style,
87 ) = self._get_number_styles(console)
88
89 for line_no, line in enumerate(lines, self.start_line + line_offset):
90 if self.word_wrap:
91 wrapped_lines = console.render_lines(
92 line,
93 render_options.update(height=None, justify="left"),
94 style=background_style,
95 pad=not transparent_background,
96 )
97 else:
98 segments = list(line.render(console, end=""))
99 if options.no_wrap:
100 wrapped_lines = [segments]
101 else:
102 wrapped_lines = [
103 _Segment.adjust_line_length(
104 segments,
105 render_options.max_width,
106 style=background_style,
107 pad=not transparent_background,
108 )
109 ]
110
111 if self.line_numbers:
112 wrapped_line_left_pad = _Segment(
113 " " * numbers_column_width + " ", background_style
114 )
115 for first, wrapped_line in loop_first(wrapped_lines):
116 if first:
117 line_column = str(line_no).rjust(numbers_column_width - 2) + " "
118 if highlight_line(line_no):
119 yield _Segment(line_pointer, Style(color="red"))
120 yield _Segment(line_column, highlight_number_style)
121 else:
122 yield _Segment(" ", highlight_number_style)
123 yield _Segment(line_column, number_style)
124 else:
125 yield wrapped_line_left_pad
126 yield from wrapped_line
127 yield new_line
128 else:
129 for wrapped_line in wrapped_lines:
130 yield from wrapped_line
131 yield new_line
Path 6: 1 calls (0.03)
Console (1)
ConsoleOptions (1)
Segment (27)
1def _get_syntax(
2 self,
3 console: Console,
4 options: ConsoleOptions,
5 ) -> Iterable[Segment]:
6 """
7 Get the Segments for the Syntax object, excluding any vertical/horizontal padding
8 """
9 transparent_background = self._get_base_style().transparent_background
10 code_width = (
11 (
12 (options.max_width - self._numbers_column_width - 1)
13 if self.line_numbers
14 else options.max_width
15 )
16 if self.code_width is None
17 else self.code_width
18 )
19
20 ends_on_nl, processed_code = self._process_code(self.code)
21 text = self.highlight(processed_code, self.line_range)
22
23 if not self.line_numbers and not self.word_wrap and not self.line_range:
24 if not ends_on_nl:
25 text.remove_suffix("\n")
26 # Simple case of just rendering text
27 style = (
28 self._get_base_style()
29 + self._theme.get_style_for_token(Comment)
30 + Style(dim=True)
31 + self.background_style
32 )
33 if self.indent_guides and not options.ascii_only:
34 text = text.with_indent_guides(self.tab_size, style=style)
35 text.overflow = "crop"
36 if style.transparent_background:
37 yield from console.render(
38 text, options=options.update(width=code_width)
39 )
40 else:
41 syntax_lines = console.render_lines(
42 text,
43 options.update(width=code_width, height=None, justify="left"),
44 style=self.background_style,
45 pad=True,
46 new_lines=True,
47 )
48 for syntax_line in syntax_lines:
49 yield from syntax_line
50 return
51
52 start_line, end_line = self.line_range or (None, None)
53 line_offset = 0
54 if start_line:
55 line_offset = max(0, start_line - 1)
56 lines: Union[List[Text], Lines] = text.split("\n", allow_blank=ends_on_nl)
57 if self.line_range:
58 lines = lines[line_offset:end_line]
59
60 if self.indent_guides and not options.ascii_only:
61 style = (
62 self._get_base_style()
63 + self._theme.get_style_for_token(Comment)
64 + Style(dim=True)
65 + self.background_style
66 )
67 lines = (
68 Text("\n")
69 .join(lines)
70 .with_indent_guides(self.tab_size, style=style)
71 .split("\n", allow_blank=True)
72 )
73
74 numbers_column_width = self._numbers_column_width
75 render_options = options.update(width=code_width)
76
77 highlight_line = self.highlight_lines.__contains__
78 _Segment = Segment
79 new_line = _Segment("\n")
80
81 line_pointer = "> " if options.legacy_windows else "❱ "
82
83 (
84 background_style,
85 number_style,
86 highlight_number_style,
87 ) = self._get_number_styles(console)
88
89 for line_no, line in enumerate(lines, self.start_line + line_offset):
90 if self.word_wrap:
91 wrapped_lines = console.render_lines(
92 line,
93 render_options.update(height=None, justify="left"),
94 style=background_style,
95 pad=not transparent_background,
96 )
97 else:
98 segments = list(line.render(console, end=""))
99 if options.no_wrap:
100 wrapped_lines = [segments]
101 else:
102 wrapped_lines = [
103 _Segment.adjust_line_length(
104 segments,
105 render_options.max_width,
106 style=background_style,
107 pad=not transparent_background,
108 )
109 ]
110
111 if self.line_numbers:
112 wrapped_line_left_pad = _Segment(
113 " " * numbers_column_width + " ", background_style
114 )
115 for first, wrapped_line in loop_first(wrapped_lines):
116 if first:
117 line_column = str(line_no).rjust(numbers_column_width - 2) + " "
118 if highlight_line(line_no):
119 yield _Segment(line_pointer, Style(color="red"))
120 yield _Segment(line_column, highlight_number_style)
121 else:
122 yield _Segment(" ", highlight_number_style)
123 yield _Segment(line_column, number_style)
124 else:
125 yield wrapped_line_left_pad
126 yield from wrapped_line
127 yield new_line
128 else:
129 for wrapped_line in wrapped_lines:
130 yield from wrapped_line
131 yield new_line
Path 7: 1 calls (0.03)
Console (1)
ConsoleOptions (1)
Segment (95)
1def _get_syntax(
2 self,
3 console: Console,
4 options: ConsoleOptions,
5 ) -> Iterable[Segment]:
6 """
7 Get the Segments for the Syntax object, excluding any vertical/horizontal padding
8 """
9 transparent_background = self._get_base_style().transparent_background
10 code_width = (
11 (
12 (options.max_width - self._numbers_column_width - 1)
13 if self.line_numbers
14 else options.max_width
15 )
16 if self.code_width is None
17 else self.code_width
18 )
19
20 ends_on_nl, processed_code = self._process_code(self.code)
21 text = self.highlight(processed_code, self.line_range)
22
23 if not self.line_numbers and not self.word_wrap and not self.line_range:
24 if not ends_on_nl:
25 text.remove_suffix("\n")
26 # Simple case of just rendering text
27 style = (
28 self._get_base_style()
29 + self._theme.get_style_for_token(Comment)
30 + Style(dim=True)
31 + self.background_style
32 )
33 if self.indent_guides and not options.ascii_only:
34 text = text.with_indent_guides(self.tab_size, style=style)
35 text.overflow = "crop"
36 if style.transparent_background:
37 yield from console.render(
38 text, options=options.update(width=code_width)
39 )
40 else:
41 syntax_lines = console.render_lines(
42 text,
43 options.update(width=code_width, height=None, justify="left"),
44 style=self.background_style,
45 pad=True,
46 new_lines=True,
47 )
48 for syntax_line in syntax_lines:
49 yield from syntax_line
50 return
51
52 start_line, end_line = self.line_range or (None, None)
53 line_offset = 0
54 if start_line:
55 line_offset = max(0, start_line - 1)
56 lines: Union[List[Text], Lines] = text.split("\n", allow_blank=ends_on_nl)
57 if self.line_range:
58 lines = lines[line_offset:end_line]
59
60 if self.indent_guides and not options.ascii_only:
61 style = (
62 self._get_base_style()
63 + self._theme.get_style_for_token(Comment)
64 + Style(dim=True)
65 + self.background_style
66 )
67 lines = (
68 Text("\n")
69 .join(lines)
70 .with_indent_guides(self.tab_size, style=style)
71 .split("\n", allow_blank=True)
72 )
73
74 numbers_column_width = self._numbers_column_width
75 render_options = options.update(width=code_width)
76
77 highlight_line = self.highlight_lines.__contains__
78 _Segment = Segment
79 new_line = _Segment("\n")
80
81 line_pointer = "> " if options.legacy_windows else "❱ "
82
83 (
84 background_style,
85 number_style,
86 highlight_number_style,
87 ) = self._get_number_styles(console)
88
89 for line_no, line in enumerate(lines, self.start_line + line_offset):
90 if self.word_wrap:
91 wrapped_lines = console.render_lines(
92 line,
93 render_options.update(height=None, justify="left"),
94 style=background_style,
95 pad=not transparent_background,
96 )
97 else:
98 segments = list(line.render(console, end=""))
99 if options.no_wrap:
100 wrapped_lines = [segments]
101 else:
102 wrapped_lines = [
103 _Segment.adjust_line_length(
104 segments,
105 render_options.max_width,
106 style=background_style,
107 pad=not transparent_background,
108 )
109 ]
110
111 if self.line_numbers:
112 wrapped_line_left_pad = _Segment(
113 " " * numbers_column_width + " ", background_style
114 )
115 for first, wrapped_line in loop_first(wrapped_lines):
116 if first:
117 line_column = str(line_no).rjust(numbers_column_width - 2) + " "
118 if highlight_line(line_no):
119 yield _Segment(line_pointer, Style(color="red"))
120 yield _Segment(line_column, highlight_number_style)
121 else:
122 yield _Segment(" ", highlight_number_style)
123 yield _Segment(line_column, number_style)
124 else:
125 yield wrapped_line_left_pad
126 yield from wrapped_line
127 yield new_line
128 else:
129 for wrapped_line in wrapped_lines:
130 yield from wrapped_line
131 yield new_line
Path 8: 1 calls (0.03)
Console (1)
ConsoleOptions (1)
Segment (111)
None (1)
1def _get_syntax(
2 self,
3 console: Console,
4 options: ConsoleOptions,
5 ) -> Iterable[Segment]:
6 """
7 Get the Segments for the Syntax object, excluding any vertical/horizontal padding
8 """
9 transparent_background = self._get_base_style().transparent_background
10 code_width = (
11 (
12 (options.max_width - self._numbers_column_width - 1)
13 if self.line_numbers
14 else options.max_width
15 )
16 if self.code_width is None
17 else self.code_width
18 )
19
20 ends_on_nl, processed_code = self._process_code(self.code)
21 text = self.highlight(processed_code, self.line_range)
22
23 if not self.line_numbers and not self.word_wrap and not self.line_range:
24 if not ends_on_nl:
25 text.remove_suffix("\n")
26 # Simple case of just rendering text
27 style = (
28 self._get_base_style()
29 + self._theme.get_style_for_token(Comment)
30 + Style(dim=True)
31 + self.background_style
32 )
33 if self.indent_guides and not options.ascii_only:
34 text = text.with_indent_guides(self.tab_size, style=style)
35 text.overflow = "crop"
36 if style.transparent_background:
37 yield from console.render(
38 text, options=options.update(width=code_width)
39 )
40 else:
41 syntax_lines = console.render_lines(
42 text,
43 options.update(width=code_width, height=None, justify="left"),
44 style=self.background_style,
45 pad=True,
46 new_lines=True,
47 )
48 for syntax_line in syntax_lines:
49 yield from syntax_line
50 return
51
52 start_line, end_line = self.line_range or (None, None)
53 line_offset = 0
54 if start_line:
55 line_offset = max(0, start_line - 1)
56 lines: Union[List[Text], Lines] = text.split("\n", allow_blank=ends_on_nl)
57 if self.line_range:
58 lines = lines[line_offset:end_line]
59
60 if self.indent_guides and not options.ascii_only:
61 style = (
62 self._get_base_style()
63 + self._theme.get_style_for_token(Comment)
64 + Style(dim=True)
65 + self.background_style
66 )
67 lines = (
68 Text("\n")
69 .join(lines)
70 .with_indent_guides(self.tab_size, style=style)
71 .split("\n", allow_blank=True)
72 )
73
74 numbers_column_width = self._numbers_column_width
75 render_options = options.update(width=code_width)
76
77 highlight_line = self.highlight_lines.__contains__
78 _Segment = Segment
79 new_line = _Segment("\n")
80
81 line_pointer = "> " if options.legacy_windows else "❱ "
82
83 (
84 background_style,
85 number_style,
86 highlight_number_style,
87 ) = self._get_number_styles(console)
88
89 for line_no, line in enumerate(lines, self.start_line + line_offset):
90 if self.word_wrap:
91 wrapped_lines = console.render_lines(
92 line,
93 render_options.update(height=None, justify="left"),
94 style=background_style,
95 pad=not transparent_background,
96 )
97 else:
98 segments = list(line.render(console, end=""))
99 if options.no_wrap:
100 wrapped_lines = [segments]
101 else:
102 wrapped_lines = [
103 _Segment.adjust_line_length(
104 segments,
105 render_options.max_width,
106 style=background_style,
107 pad=not transparent_background,
108 )
109 ]
110
111 if self.line_numbers:
112 wrapped_line_left_pad = _Segment(
113 " " * numbers_column_width + " ", background_style
114 )
115 for first, wrapped_line in loop_first(wrapped_lines):
116 if first:
117 line_column = str(line_no).rjust(numbers_column_width - 2) + " "
118 if highlight_line(line_no):
119 yield _Segment(line_pointer, Style(color="red"))
120 yield _Segment(line_column, highlight_number_style)
121 else:
122 yield _Segment(" ", highlight_number_style)
123 yield _Segment(line_column, number_style)
124 else:
125 yield wrapped_line_left_pad
126 yield from wrapped_line
127 yield new_line
128 else:
129 for wrapped_line in wrapped_lines:
130 yield from wrapped_line
131 yield new_line
Path 9: 1 calls (0.03)
Console (1)
ConsoleOptions (1)
Segment (13)
1def _get_syntax(
2 self,
3 console: Console,
4 options: ConsoleOptions,
5 ) -> Iterable[Segment]:
6 """
7 Get the Segments for the Syntax object, excluding any vertical/horizontal padding
8 """
9 transparent_background = self._get_base_style().transparent_background
10 code_width = (
11 (
12 (options.max_width - self._numbers_column_width - 1)
13 if self.line_numbers
14 else options.max_width
15 )
16 if self.code_width is None
17 else self.code_width
18 )
19
20 ends_on_nl, processed_code = self._process_code(self.code)
21 text = self.highlight(processed_code, self.line_range)
22
23 if not self.line_numbers and not self.word_wrap and not self.line_range:
24 if not ends_on_nl:
25 text.remove_suffix("\n")
26 # Simple case of just rendering text
27 style = (
28 self._get_base_style()
29 + self._theme.get_style_for_token(Comment)
30 + Style(dim=True)
31 + self.background_style
32 )
33 if self.indent_guides and not options.ascii_only:
34 text = text.with_indent_guides(self.tab_size, style=style)
35 text.overflow = "crop"
36 if style.transparent_background:
37 yield from console.render(
38 text, options=options.update(width=code_width)
39 )
40 else:
41 syntax_lines = console.render_lines(
42 text,
43 options.update(width=code_width, height=None, justify="left"),
44 style=self.background_style,
45 pad=True,
46 new_lines=True,
47 )
48 for syntax_line in syntax_lines:
49 yield from syntax_line
50 return
51
52 start_line, end_line = self.line_range or (None, None)
53 line_offset = 0
54 if start_line:
55 line_offset = max(0, start_line - 1)
56 lines: Union[List[Text], Lines] = text.split("\n", allow_blank=ends_on_nl)
57 if self.line_range:
58 lines = lines[line_offset:end_line]
59
60 if self.indent_guides and not options.ascii_only:
61 style = (
62 self._get_base_style()
63 + self._theme.get_style_for_token(Comment)
64 + Style(dim=True)
65 + self.background_style
66 )
67 lines = (
68 Text("\n")
69 .join(lines)
70 .with_indent_guides(self.tab_size, style=style)
71 .split("\n", allow_blank=True)
72 )
73
74 numbers_column_width = self._numbers_column_width
75 render_options = options.update(width=code_width)
76
77 highlight_line = self.highlight_lines.__contains__
78 _Segment = Segment
79 new_line = _Segment("\n")
80
81 line_pointer = "> " if options.legacy_windows else "❱ "
82
83 (
84 background_style,
85 number_style,
86 highlight_number_style,
87 ) = self._get_number_styles(console)
88
89 for line_no, line in enumerate(lines, self.start_line + line_offset):
90 if self.word_wrap:
91 wrapped_lines = console.render_lines(
92 line,
93 render_options.update(height=None, justify="left"),
94 style=background_style,
95 pad=not transparent_background,
96 )
97 else:
98 segments = list(line.render(console, end=""))
99 if options.no_wrap:
100 wrapped_lines = [segments]
101 else:
102 wrapped_lines = [
103 _Segment.adjust_line_length(
104 segments,
105 render_options.max_width,
106 style=background_style,
107 pad=not transparent_background,
108 )
109 ]
110
111 if self.line_numbers:
112 wrapped_line_left_pad = _Segment(
113 " " * numbers_column_width + " ", background_style
114 )
115 for first, wrapped_line in loop_first(wrapped_lines):
116 if first:
117 line_column = str(line_no).rjust(numbers_column_width - 2) + " "
118 if highlight_line(line_no):
119 yield _Segment(line_pointer, Style(color="red"))
120 yield _Segment(line_column, highlight_number_style)
121 else:
122 yield _Segment(" ", highlight_number_style)
123 yield _Segment(line_column, number_style)
124 else:
125 yield wrapped_line_left_pad
126 yield from wrapped_line
127 yield new_line
128 else:
129 for wrapped_line in wrapped_lines:
130 yield from wrapped_line
131 yield new_line
Path 10: 1 calls (0.03)
Console (1)
ConsoleOptions (1)
Segment (95)
1def _get_syntax(
2 self,
3 console: Console,
4 options: ConsoleOptions,
5 ) -> Iterable[Segment]:
6 """
7 Get the Segments for the Syntax object, excluding any vertical/horizontal padding
8 """
9 transparent_background = self._get_base_style().transparent_background
10 code_width = (
11 (
12 (options.max_width - self._numbers_column_width - 1)
13 if self.line_numbers
14 else options.max_width
15 )
16 if self.code_width is None
17 else self.code_width
18 )
19
20 ends_on_nl, processed_code = self._process_code(self.code)
21 text = self.highlight(processed_code, self.line_range)
22
23 if not self.line_numbers and not self.word_wrap and not self.line_range:
24 if not ends_on_nl:
25 text.remove_suffix("\n")
26 # Simple case of just rendering text
27 style = (
28 self._get_base_style()
29 + self._theme.get_style_for_token(Comment)
30 + Style(dim=True)
31 + self.background_style
32 )
33 if self.indent_guides and not options.ascii_only:
34 text = text.with_indent_guides(self.tab_size, style=style)
35 text.overflow = "crop"
36 if style.transparent_background:
37 yield from console.render(
38 text, options=options.update(width=code_width)
39 )
40 else:
41 syntax_lines = console.render_lines(
42 text,
43 options.update(width=code_width, height=None, justify="left"),
44 style=self.background_style,
45 pad=True,
46 new_lines=True,
47 )
48 for syntax_line in syntax_lines:
49 yield from syntax_line
50 return
51
52 start_line, end_line = self.line_range or (None, None)
53 line_offset = 0
54 if start_line:
55 line_offset = max(0, start_line - 1)
56 lines: Union[List[Text], Lines] = text.split("\n", allow_blank=ends_on_nl)
57 if self.line_range:
58 lines = lines[line_offset:end_line]
59
60 if self.indent_guides and not options.ascii_only:
61 style = (
62 self._get_base_style()
63 + self._theme.get_style_for_token(Comment)
64 + Style(dim=True)
65 + self.background_style
66 )
67 lines = (
68 Text("\n")
69 .join(lines)
70 .with_indent_guides(self.tab_size, style=style)
71 .split("\n", allow_blank=True)
72 )
73
74 numbers_column_width = self._numbers_column_width
75 render_options = options.update(width=code_width)
76
77 highlight_line = self.highlight_lines.__contains__
78 _Segment = Segment
79 new_line = _Segment("\n")
80
81 line_pointer = "> " if options.legacy_windows else "❱ "
82
83 (
84 background_style,
85 number_style,
86 highlight_number_style,
87 ) = self._get_number_styles(console)
88
89 for line_no, line in enumerate(lines, self.start_line + line_offset):
90 if self.word_wrap:
91 wrapped_lines = console.render_lines(
92 line,
93 render_options.update(height=None, justify="left"),
94 style=background_style,
95 pad=not transparent_background,
96 )
97 else:
98 segments = list(line.render(console, end=""))
99 if options.no_wrap:
100 wrapped_lines = [segments]
101 else:
102 wrapped_lines = [
103 _Segment.adjust_line_length(
104 segments,
105 render_options.max_width,
106 style=background_style,
107 pad=not transparent_background,
108 )
109 ]
110
111 if self.line_numbers:
112 wrapped_line_left_pad = _Segment(
113 " " * numbers_column_width + " ", background_style
114 )
115 for first, wrapped_line in loop_first(wrapped_lines):
116 if first:
117 line_column = str(line_no).rjust(numbers_column_width - 2) + " "
118 if highlight_line(line_no):
119 yield _Segment(line_pointer, Style(color="red"))
120 yield _Segment(line_column, highlight_number_style)
121 else:
122 yield _Segment(" ", highlight_number_style)
123 yield _Segment(line_column, number_style)
124 else:
125 yield wrapped_line_left_pad
126 yield from wrapped_line
127 yield new_line
128 else:
129 for wrapped_line in wrapped_lines:
130 yield from wrapped_line
131 yield new_line
Path 11: 1 calls (0.03)
Console (1)
ConsoleOptions (1)
Segment (82)
1def _get_syntax(
2 self,
3 console: Console,
4 options: ConsoleOptions,
5 ) -> Iterable[Segment]:
6 """
7 Get the Segments for the Syntax object, excluding any vertical/horizontal padding
8 """
9 transparent_background = self._get_base_style().transparent_background
10 code_width = (
11 (
12 (options.max_width - self._numbers_column_width - 1)
13 if self.line_numbers
14 else options.max_width
15 )
16 if self.code_width is None
17 else self.code_width
18 )
19
20 ends_on_nl, processed_code = self._process_code(self.code)
21 text = self.highlight(processed_code, self.line_range)
22
23 if not self.line_numbers and not self.word_wrap and not self.line_range:
24 if not ends_on_nl:
25 text.remove_suffix("\n")
26 # Simple case of just rendering text
27 style = (
28 self._get_base_style()
29 + self._theme.get_style_for_token(Comment)
30 + Style(dim=True)
31 + self.background_style
32 )
33 if self.indent_guides and not options.ascii_only:
34 text = text.with_indent_guides(self.tab_size, style=style)
35 text.overflow = "crop"
36 if style.transparent_background:
37 yield from console.render(
38 text, options=options.update(width=code_width)
39 )
40 else:
41 syntax_lines = console.render_lines(
42 text,
43 options.update(width=code_width, height=None, justify="left"),
44 style=self.background_style,
45 pad=True,
46 new_lines=True,
47 )
48 for syntax_line in syntax_lines:
49 yield from syntax_line
50 return
51
52 start_line, end_line = self.line_range or (None, None)
53 line_offset = 0
54 if start_line:
55 line_offset = max(0, start_line - 1)
56 lines: Union[List[Text], Lines] = text.split("\n", allow_blank=ends_on_nl)
57 if self.line_range:
58 lines = lines[line_offset:end_line]
59
60 if self.indent_guides and not options.ascii_only:
61 style = (
62 self._get_base_style()
63 + self._theme.get_style_for_token(Comment)
64 + Style(dim=True)
65 + self.background_style
66 )
67 lines = (
68 Text("\n")
69 .join(lines)
70 .with_indent_guides(self.tab_size, style=style)
71 .split("\n", allow_blank=True)
72 )
73
74 numbers_column_width = self._numbers_column_width
75 render_options = options.update(width=code_width)
76
77 highlight_line = self.highlight_lines.__contains__
78 _Segment = Segment
79 new_line = _Segment("\n")
80
81 line_pointer = "> " if options.legacy_windows else "❱ "
82
83 (
84 background_style,
85 number_style,
86 highlight_number_style,
87 ) = self._get_number_styles(console)
88
89 for line_no, line in enumerate(lines, self.start_line + line_offset):
90 if self.word_wrap:
91 wrapped_lines = console.render_lines(
92 line,
93 render_options.update(height=None, justify="left"),
94 style=background_style,
95 pad=not transparent_background,
96 )
97 else:
98 segments = list(line.render(console, end=""))
99 if options.no_wrap:
100 wrapped_lines = [segments]
101 else:
102 wrapped_lines = [
103 _Segment.adjust_line_length(
104 segments,
105 render_options.max_width,
106 style=background_style,
107 pad=not transparent_background,
108 )
109 ]
110
111 if self.line_numbers:
112 wrapped_line_left_pad = _Segment(
113 " " * numbers_column_width + " ", background_style
114 )
115 for first, wrapped_line in loop_first(wrapped_lines):
116 if first:
117 line_column = str(line_no).rjust(numbers_column_width - 2) + " "
118 if highlight_line(line_no):
119 yield _Segment(line_pointer, Style(color="red"))
120 yield _Segment(line_column, highlight_number_style)
121 else:
122 yield _Segment(" ", highlight_number_style)
123 yield _Segment(line_column, number_style)
124 else:
125 yield wrapped_line_left_pad
126 yield from wrapped_line
127 yield new_line
128 else:
129 for wrapped_line in wrapped_lines:
130 yield from wrapped_line
131 yield new_line
Path 12: 1 calls (0.03)
Console (1)
ConsoleOptions (1)
Segment (150)
1def _get_syntax(
2 self,
3 console: Console,
4 options: ConsoleOptions,
5 ) -> Iterable[Segment]:
6 """
7 Get the Segments for the Syntax object, excluding any vertical/horizontal padding
8 """
9 transparent_background = self._get_base_style().transparent_background
10 code_width = (
11 (
12 (options.max_width - self._numbers_column_width - 1)
13 if self.line_numbers
14 else options.max_width
15 )
16 if self.code_width is None
17 else self.code_width
18 )
19
20 ends_on_nl, processed_code = self._process_code(self.code)
21 text = self.highlight(processed_code, self.line_range)
22
23 if not self.line_numbers and not self.word_wrap and not self.line_range:
24 if not ends_on_nl:
25 text.remove_suffix("\n")
26 # Simple case of just rendering text
27 style = (
28 self._get_base_style()
29 + self._theme.get_style_for_token(Comment)
30 + Style(dim=True)
31 + self.background_style
32 )
33 if self.indent_guides and not options.ascii_only:
34 text = text.with_indent_guides(self.tab_size, style=style)
35 text.overflow = "crop"
36 if style.transparent_background:
37 yield from console.render(
38 text, options=options.update(width=code_width)
39 )
40 else:
41 syntax_lines = console.render_lines(
42 text,
43 options.update(width=code_width, height=None, justify="left"),
44 style=self.background_style,
45 pad=True,
46 new_lines=True,
47 )
48 for syntax_line in syntax_lines:
49 yield from syntax_line
50 return
51
52 start_line, end_line = self.line_range or (None, None)
53 line_offset = 0
54 if start_line:
55 line_offset = max(0, start_line - 1)
56 lines: Union[List[Text], Lines] = text.split("\n", allow_blank=ends_on_nl)
57 if self.line_range:
58 lines = lines[line_offset:end_line]
59
60 if self.indent_guides and not options.ascii_only:
61 style = (
62 self._get_base_style()
63 + self._theme.get_style_for_token(Comment)
64 + Style(dim=True)
65 + self.background_style
66 )
67 lines = (
68 Text("\n")
69 .join(lines)
70 .with_indent_guides(self.tab_size, style=style)
71 .split("\n", allow_blank=True)
72 )
73
74 numbers_column_width = self._numbers_column_width
75 render_options = options.update(width=code_width)
76
77 highlight_line = self.highlight_lines.__contains__
78 _Segment = Segment
79 new_line = _Segment("\n")
80
81 line_pointer = "> " if options.legacy_windows else "❱ "
82
83 (
84 background_style,
85 number_style,
86 highlight_number_style,
87 ) = self._get_number_styles(console)
88
89 for line_no, line in enumerate(lines, self.start_line + line_offset):
90 if self.word_wrap:
91 wrapped_lines = console.render_lines(
92 line,
93 render_options.update(height=None, justify="left"),
94 style=background_style,
95 pad=not transparent_background,
96 )
97 else:
98 segments = list(line.render(console, end=""))
99 if options.no_wrap:
100 wrapped_lines = [segments]
101 else:
102 wrapped_lines = [
103 _Segment.adjust_line_length(
104 segments,
105 render_options.max_width,
106 style=background_style,
107 pad=not transparent_background,
108 )
109 ]
110
111 if self.line_numbers:
112 wrapped_line_left_pad = _Segment(
113 " " * numbers_column_width + " ", background_style
114 )
115 for first, wrapped_line in loop_first(wrapped_lines):
116 if first:
117 line_column = str(line_no).rjust(numbers_column_width - 2) + " "
118 if highlight_line(line_no):
119 yield _Segment(line_pointer, Style(color="red"))
120 yield _Segment(line_column, highlight_number_style)
121 else:
122 yield _Segment(" ", highlight_number_style)
123 yield _Segment(line_column, number_style)
124 else:
125 yield wrapped_line_left_pad
126 yield from wrapped_line
127 yield new_line
128 else:
129 for wrapped_line in wrapped_lines:
130 yield from wrapped_line
131 yield new_line
Path 13: 1 calls (0.03)
Console (1)
ConsoleOptions (1)
Segment (7)
None (1)
1def _get_syntax(
2 self,
3 console: Console,
4 options: ConsoleOptions,
5 ) -> Iterable[Segment]:
6 """
7 Get the Segments for the Syntax object, excluding any vertical/horizontal padding
8 """
9 transparent_background = self._get_base_style().transparent_background
10 code_width = (
11 (
12 (options.max_width - self._numbers_column_width - 1)
13 if self.line_numbers
14 else options.max_width
15 )
16 if self.code_width is None
17 else self.code_width
18 )
19
20 ends_on_nl, processed_code = self._process_code(self.code)
21 text = self.highlight(processed_code, self.line_range)
22
23 if not self.line_numbers and not self.word_wrap and not self.line_range:
24 if not ends_on_nl:
25 text.remove_suffix("\n")
26 # Simple case of just rendering text
27 style = (
28 self._get_base_style()
29 + self._theme.get_style_for_token(Comment)
30 + Style(dim=True)
31 + self.background_style
32 )
33 if self.indent_guides and not options.ascii_only:
34 text = text.with_indent_guides(self.tab_size, style=style)
35 text.overflow = "crop"
36 if style.transparent_background:
37 yield from console.render(
38 text, options=options.update(width=code_width)
39 )
40 else:
41 syntax_lines = console.render_lines(
42 text,
43 options.update(width=code_width, height=None, justify="left"),
44 style=self.background_style,
45 pad=True,
46 new_lines=True,
47 )
48 for syntax_line in syntax_lines:
49 yield from syntax_line
50 return
51
52 start_line, end_line = self.line_range or (None, None)
53 line_offset = 0
54 if start_line:
55 line_offset = max(0, start_line - 1)
56 lines: Union[List[Text], Lines] = text.split("\n", allow_blank=ends_on_nl)
57 if self.line_range:
58 lines = lines[line_offset:end_line]
59
60 if self.indent_guides and not options.ascii_only:
61 style = (
62 self._get_base_style()
63 + self._theme.get_style_for_token(Comment)
64 + Style(dim=True)
65 + self.background_style
66 )
67 lines = (
68 Text("\n")
69 .join(lines)
70 .with_indent_guides(self.tab_size, style=style)
71 .split("\n", allow_blank=True)
72 )
73
74 numbers_column_width = self._numbers_column_width
75 render_options = options.update(width=code_width)
76
77 highlight_line = self.highlight_lines.__contains__
78 _Segment = Segment
79 new_line = _Segment("\n")
80
81 line_pointer = "> " if options.legacy_windows else "❱ "
82
83 (
84 background_style,
85 number_style,
86 highlight_number_style,
87 ) = self._get_number_styles(console)
88
89 for line_no, line in enumerate(lines, self.start_line + line_offset):
90 if self.word_wrap:
91 wrapped_lines = console.render_lines(
92 line,
93 render_options.update(height=None, justify="left"),
94 style=background_style,
95 pad=not transparent_background,
96 )
97 else:
98 segments = list(line.render(console, end=""))
99 if options.no_wrap:
100 wrapped_lines = [segments]
101 else:
102 wrapped_lines = [
103 _Segment.adjust_line_length(
104 segments,
105 render_options.max_width,
106 style=background_style,
107 pad=not transparent_background,
108 )
109 ]
110
111 if self.line_numbers:
112 wrapped_line_left_pad = _Segment(
113 " " * numbers_column_width + " ", background_style
114 )
115 for first, wrapped_line in loop_first(wrapped_lines):
116 if first:
117 line_column = str(line_no).rjust(numbers_column_width - 2) + " "
118 if highlight_line(line_no):
119 yield _Segment(line_pointer, Style(color="red"))
120 yield _Segment(line_column, highlight_number_style)
121 else:
122 yield _Segment(" ", highlight_number_style)
123 yield _Segment(line_column, number_style)
124 else:
125 yield wrapped_line_left_pad
126 yield from wrapped_line
127 yield new_line
128 else:
129 for wrapped_line in wrapped_lines:
130 yield from wrapped_line
131 yield new_line