Method: rich.table.Table._render
Calls: 117, Exceptions: 0, Paths: 11Back
Path 1: 76 calls (0.65)
Console (76)
ConsoleOptions (76)
[5, 41, 5, 7] (12) [20, 9, 92, 19] (11) [6] (6) [8, 25] (5) [20, 9, 93, 18] (4) [10] (4) [7, 59, 14] (3) [11, 41, 12, 7] (3) [43, 42] (2) [14, 1] (2) ...
Segment (3902)
1def _render(
2 self, console: "Console", options: "ConsoleOptions", widths: List[int]
3 ) -> "RenderResult":
4 table_style = console.get_style(self.style or "")
5
6 border_style = table_style + console.get_style(self.border_style or "")
7 _column_cells = (
8 self._get_cells(console, column_index, column)
9 for column_index, column in enumerate(self.columns)
10 )
11 row_cells: List[Tuple[_Cell, ...]] = list(zip(*_column_cells))
12 _box = (
13 self.box.substitute(
14 options, safe=pick_bool(self.safe_box, console.safe_box)
15 )
16 if self.box
17 else None
18 )
19 _box = _box.get_plain_headed_box() if _box and not self.show_header else _box
20
21 new_line = Segment.line()
22
23 columns = self.columns
24 show_header = self.show_header
25 show_footer = self.show_footer
26 show_edge = self.show_edge
27 show_lines = self.show_lines
28 leading = self.leading
29
30 _Segment = Segment
31 if _box:
32 box_segments = [
33 (
34 _Segment(_box.head_left, border_style),
35 _Segment(_box.head_right, border_style),
36 _Segment(_box.head_vertical, border_style),
37 ),
38 (
39 _Segment(_box.foot_left, border_style),
40 _Segment(_box.foot_right, border_style),
41 _Segment(_box.foot_vertical, border_style),
42 ),
43 (
44 _Segment(_box.mid_left, border_style),
45 _Segment(_box.mid_right, border_style),
46 _Segment(_box.mid_vertical, border_style),
47 ),
48 ]
49 if show_edge:
50 yield _Segment(_box.get_top(widths), border_style)
51 yield new_line
52 else:
53 box_segments = []
54
55 get_row_style = self.get_row_style
56 get_style = console.get_style
57
58 for index, (first, last, row_cell) in enumerate(loop_first_last(row_cells)):
59 header_row = first and show_header
60 footer_row = last and show_footer
61 row = (
62 self.rows[index - show_header]
63 if (not header_row and not footer_row)
64 else None
65 )
66 max_height = 1
67 cells: List[List[List[Segment]]] = []
68 if header_row or footer_row:
69 row_style = Style.null()
70 else:
71 row_style = get_style(
72 get_row_style(console, index - 1 if show_header else index)
73 )
74 for width, cell, column in zip(widths, row_cell, columns):
75 render_options = options.update(
76 width=width,
77 justify=column.justify,
78 no_wrap=column.no_wrap,
79 overflow=column.overflow,
80 height=None,
81 )
82 lines = console.render_lines(
83 cell.renderable,
84 render_options,
85 style=get_style(cell.style) + row_style,
86 )
87 max_height = max(max_height, len(lines))
88 cells.append(lines)
89
90 row_height = max(len(cell) for cell in cells)
91
92 def align_cell(
93 cell: List[List[Segment]],
94 vertical: "VerticalAlignMethod",
95 width: int,
96 style: Style,
97 ) -> List[List[Segment]]:
98 if header_row:
99 vertical = "bottom"
100 elif footer_row:
101 vertical = "top"
102
103 if vertical == "top":
104 return _Segment.align_top(cell, width, row_height, style)
105 elif vertical == "middle":
106 return _Segment.align_middle(cell, width, row_height, style)
107 return _Segment.align_bottom(cell, width, row_height, style)
108
109 cells[:] = [
110 _Segment.set_shape(
111 align_cell(
112 cell,
113 _cell.vertical,
114 width,
115 get_style(_cell.style) + row_style,
116 ),
117 width,
118 max_height,
119 )
120 for width, _cell, cell, column in zip(widths, row_cell, cells, columns)
121 ]
122
123 if _box:
124 if last and show_footer:
125 yield _Segment(
126 _box.get_row(widths, "foot", edge=show_edge), border_style
127 )
128 yield new_line
129 left, right, _divider = box_segments[0 if first else (2 if last else 1)]
130
131 # If the column divider is whitespace also style it with the row background
132 divider = (
133 _divider
134 if _divider.text.strip()
135 else _Segment(
136 _divider.text, row_style.background_style + _divider.style
137 )
138 )
139 for line_no in range(max_height):
140 if show_edge:
141 yield left
142 for last_cell, rendered_cell in loop_last(cells):
143 yield from rendered_cell[line_no]
144 if not last_cell:
145 yield divider
146 if show_edge:
147 yield right
148 yield new_line
149 else:
150 for line_no in range(max_height):
151 for rendered_cell in cells:
152 yield from rendered_cell[line_no]
153 yield new_line
154 if _box and first and show_header:
155 yield _Segment(
156 _box.get_row(widths, "head", edge=show_edge), border_style
157 )
158 yield new_line
159 end_section = row and row.end_section
160 if _box and (show_lines or leading or end_section):
161 if (
162 not last
163 and not (show_footer and index >= len(row_cells) - 2)
164 and not (show_header and header_row)
165 ):
166 if leading:
167 yield _Segment(
168 _box.get_row(widths, "mid", edge=show_edge) * leading,
169 border_style,
170 )
171 else:
172 yield _Segment(
173 _box.get_row(widths, "row", edge=show_edge), border_style
174 )
175 yield new_line
176
177 if _box and show_edge:
178 yield _Segment(_box.get_bottom(widths), border_style)
179 yield new_line
Path 2: 14 calls (0.12)
Console (14)
ConsoleOptions (14)
[22, 17, 5] (3) [6, 0, 0] (1) [11, 0, 0] (1) [16, 0, 0] (1) [21, 0, 0] (1) [22, 2, 2] (1) [22, 5, 4] (1) [22, 9, 5] (1) [22, 14, 5] (1) [23, 18, 5] (1...
Segment (510) None (14)
1def _render(
2 self, console: "Console", options: "ConsoleOptions", widths: List[int]
3 ) -> "RenderResult":
4 table_style = console.get_style(self.style or "")
5
6 border_style = table_style + console.get_style(self.border_style or "")
7 _column_cells = (
8 self._get_cells(console, column_index, column)
9 for column_index, column in enumerate(self.columns)
10 )
11 row_cells: List[Tuple[_Cell, ...]] = list(zip(*_column_cells))
12 _box = (
13 self.box.substitute(
14 options, safe=pick_bool(self.safe_box, console.safe_box)
15 )
16 if self.box
17 else None
18 )
19 _box = _box.get_plain_headed_box() if _box and not self.show_header else _box
20
21 new_line = Segment.line()
22
23 columns = self.columns
24 show_header = self.show_header
25 show_footer = self.show_footer
26 show_edge = self.show_edge
27 show_lines = self.show_lines
28 leading = self.leading
29
30 _Segment = Segment
31 if _box:
32 box_segments = [
33 (
34 _Segment(_box.head_left, border_style),
35 _Segment(_box.head_right, border_style),
36 _Segment(_box.head_vertical, border_style),
37 ),
38 (
39 _Segment(_box.foot_left, border_style),
40 _Segment(_box.foot_right, border_style),
41 _Segment(_box.foot_vertical, border_style),
42 ),
43 (
44 _Segment(_box.mid_left, border_style),
45 _Segment(_box.mid_right, border_style),
46 _Segment(_box.mid_vertical, border_style),
47 ),
48 ]
49 if show_edge:
50 yield _Segment(_box.get_top(widths), border_style)
51 yield new_line
52 else:
53 box_segments = []
54
55 get_row_style = self.get_row_style
56 get_style = console.get_style
57
58 for index, (first, last, row_cell) in enumerate(loop_first_last(row_cells)):
59 header_row = first and show_header
60 footer_row = last and show_footer
61 row = (
62 self.rows[index - show_header]
63 if (not header_row and not footer_row)
64 else None
65 )
66 max_height = 1
67 cells: List[List[List[Segment]]] = []
68 if header_row or footer_row:
69 row_style = Style.null()
70 else:
71 row_style = get_style(
72 get_row_style(console, index - 1 if show_header else index)
73 )
74 for width, cell, column in zip(widths, row_cell, columns):
75 render_options = options.update(
76 width=width,
77 justify=column.justify,
78 no_wrap=column.no_wrap,
79 overflow=column.overflow,
80 height=None,
81 )
82 lines = console.render_lines(
83 cell.renderable,
84 render_options,
85 style=get_style(cell.style) + row_style,
86 )
87 max_height = max(max_height, len(lines))
88 cells.append(lines)
89
90 row_height = max(len(cell) for cell in cells)
91
92 def align_cell(
93 cell: List[List[Segment]],
94 vertical: "VerticalAlignMethod",
95 width: int,
96 style: Style,
97 ) -> List[List[Segment]]:
98 if header_row:
99 vertical = "bottom"
100 elif footer_row:
101 vertical = "top"
102
103 if vertical == "top":
104 return _Segment.align_top(cell, width, row_height, style)
105 elif vertical == "middle":
106 return _Segment.align_middle(cell, width, row_height, style)
107 return _Segment.align_bottom(cell, width, row_height, style)
108
109 cells[:] = [
110 _Segment.set_shape(
111 align_cell(
112 cell,
113 _cell.vertical,
114 width,
115 get_style(_cell.style) + row_style,
116 ),
117 width,
118 max_height,
119 )
120 for width, _cell, cell, column in zip(widths, row_cell, cells, columns)
121 ]
122
123 if _box:
124 if last and show_footer:
125 yield _Segment(
126 _box.get_row(widths, "foot", edge=show_edge), border_style
127 )
128 yield new_line
129 left, right, _divider = box_segments[0 if first else (2 if last else 1)]
130
131 # If the column divider is whitespace also style it with the row background
132 divider = (
133 _divider
134 if _divider.text.strip()
135 else _Segment(
136 _divider.text, row_style.background_style + _divider.style
137 )
138 )
139 for line_no in range(max_height):
140 if show_edge:
141 yield left
142 for last_cell, rendered_cell in loop_last(cells):
143 yield from rendered_cell[line_no]
144 if not last_cell:
145 yield divider
146 if show_edge:
147 yield right
148 yield new_line
149 else:
150 for line_no in range(max_height):
151 for rendered_cell in cells:
152 yield from rendered_cell[line_no]
153 yield new_line
154 if _box and first and show_header:
155 yield _Segment(
156 _box.get_row(widths, "head", edge=show_edge), border_style
157 )
158 yield new_line
159 end_section = row and row.end_section
160 if _box and (show_lines or leading or end_section):
161 if (
162 not last
163 and not (show_footer and index >= len(row_cells) - 2)
164 and not (show_header and header_row)
165 ):
166 if leading:
167 yield _Segment(
168 _box.get_row(widths, "mid", edge=show_edge) * leading,
169 border_style,
170 )
171 else:
172 yield _Segment(
173 _box.get_row(widths, "row", edge=show_edge), border_style
174 )
175 yield new_line
176
177 if _box and show_edge:
178 yield _Segment(_box.get_bottom(widths), border_style)
179 yield new_line
Path 3: 12 calls (0.1)
Console (12)
ConsoleOptions (12)
[3, 3] (5) [5, 5] (3) [6, 6] (2) [15, 14] (1) [23, 6] (1)
Segment (394) None (12)
1def _render(
2 self, console: "Console", options: "ConsoleOptions", widths: List[int]
3 ) -> "RenderResult":
4 table_style = console.get_style(self.style or "")
5
6 border_style = table_style + console.get_style(self.border_style or "")
7 _column_cells = (
8 self._get_cells(console, column_index, column)
9 for column_index, column in enumerate(self.columns)
10 )
11 row_cells: List[Tuple[_Cell, ...]] = list(zip(*_column_cells))
12 _box = (
13 self.box.substitute(
14 options, safe=pick_bool(self.safe_box, console.safe_box)
15 )
16 if self.box
17 else None
18 )
19 _box = _box.get_plain_headed_box() if _box and not self.show_header else _box
20
21 new_line = Segment.line()
22
23 columns = self.columns
24 show_header = self.show_header
25 show_footer = self.show_footer
26 show_edge = self.show_edge
27 show_lines = self.show_lines
28 leading = self.leading
29
30 _Segment = Segment
31 if _box:
32 box_segments = [
33 (
34 _Segment(_box.head_left, border_style),
35 _Segment(_box.head_right, border_style),
36 _Segment(_box.head_vertical, border_style),
37 ),
38 (
39 _Segment(_box.foot_left, border_style),
40 _Segment(_box.foot_right, border_style),
41 _Segment(_box.foot_vertical, border_style),
42 ),
43 (
44 _Segment(_box.mid_left, border_style),
45 _Segment(_box.mid_right, border_style),
46 _Segment(_box.mid_vertical, border_style),
47 ),
48 ]
49 if show_edge:
50 yield _Segment(_box.get_top(widths), border_style)
51 yield new_line
52 else:
53 box_segments = []
54
55 get_row_style = self.get_row_style
56 get_style = console.get_style
57
58 for index, (first, last, row_cell) in enumerate(loop_first_last(row_cells)):
59 header_row = first and show_header
60 footer_row = last and show_footer
61 row = (
62 self.rows[index - show_header]
63 if (not header_row and not footer_row)
64 else None
65 )
66 max_height = 1
67 cells: List[List[List[Segment]]] = []
68 if header_row or footer_row:
69 row_style = Style.null()
70 else:
71 row_style = get_style(
72 get_row_style(console, index - 1 if show_header else index)
73 )
74 for width, cell, column in zip(widths, row_cell, columns):
75 render_options = options.update(
76 width=width,
77 justify=column.justify,
78 no_wrap=column.no_wrap,
79 overflow=column.overflow,
80 height=None,
81 )
82 lines = console.render_lines(
83 cell.renderable,
84 render_options,
85 style=get_style(cell.style) + row_style,
86 )
87 max_height = max(max_height, len(lines))
88 cells.append(lines)
89
90 row_height = max(len(cell) for cell in cells)
91
92 def align_cell(
93 cell: List[List[Segment]],
94 vertical: "VerticalAlignMethod",
95 width: int,
96 style: Style,
97 ) -> List[List[Segment]]:
98 if header_row:
99 vertical = "bottom"
100 elif footer_row:
101 vertical = "top"
102
103 if vertical == "top":
104 return _Segment.align_top(cell, width, row_height, style)
105 elif vertical == "middle":
106 return _Segment.align_middle(cell, width, row_height, style)
107 return _Segment.align_bottom(cell, width, row_height, style)
108
109 cells[:] = [
110 _Segment.set_shape(
111 align_cell(
112 cell,
113 _cell.vertical,
114 width,
115 get_style(_cell.style) + row_style,
116 ),
117 width,
118 max_height,
119 )
120 for width, _cell, cell, column in zip(widths, row_cell, cells, columns)
121 ]
122
123 if _box:
124 if last and show_footer:
125 yield _Segment(
126 _box.get_row(widths, "foot", edge=show_edge), border_style
127 )
128 yield new_line
129 left, right, _divider = box_segments[0 if first else (2 if last else 1)]
130
131 # If the column divider is whitespace also style it with the row background
132 divider = (
133 _divider
134 if _divider.text.strip()
135 else _Segment(
136 _divider.text, row_style.background_style + _divider.style
137 )
138 )
139 for line_no in range(max_height):
140 if show_edge:
141 yield left
142 for last_cell, rendered_cell in loop_last(cells):
143 yield from rendered_cell[line_no]
144 if not last_cell:
145 yield divider
146 if show_edge:
147 yield right
148 yield new_line
149 else:
150 for line_no in range(max_height):
151 for rendered_cell in cells:
152 yield from rendered_cell[line_no]
153 yield new_line
154 if _box and first and show_header:
155 yield _Segment(
156 _box.get_row(widths, "head", edge=show_edge), border_style
157 )
158 yield new_line
159 end_section = row and row.end_section
160 if _box and (show_lines or leading or end_section):
161 if (
162 not last
163 and not (show_footer and index >= len(row_cells) - 2)
164 and not (show_header and header_row)
165 ):
166 if leading:
167 yield _Segment(
168 _box.get_row(widths, "mid", edge=show_edge) * leading,
169 border_style,
170 )
171 else:
172 yield _Segment(
173 _box.get_row(widths, "row", edge=show_edge), border_style
174 )
175 yield new_line
176
177 if _box and show_edge:
178 yield _Segment(_box.get_bottom(widths), border_style)
179 yield new_line
Path 4: 5 calls (0.04)
Console (5)
ConsoleOptions (5)
[30, 0, 30, 0] (3) [80] (1) [40, 0, 40, 0] (1)
1def _render(
2 self, console: "Console", options: "ConsoleOptions", widths: List[int]
3 ) -> "RenderResult":
4 table_style = console.get_style(self.style or "")
5
6 border_style = table_style + console.get_style(self.border_style or "")
7 _column_cells = (
8 self._get_cells(console, column_index, column)
9 for column_index, column in enumerate(self.columns)
10 )
11 row_cells: List[Tuple[_Cell, ...]] = list(zip(*_column_cells))
12 _box = (
13 self.box.substitute(
14 options, safe=pick_bool(self.safe_box, console.safe_box)
15 )
16 if self.box
17 else None
18 )
19 _box = _box.get_plain_headed_box() if _box and not self.show_header else _box
20
21 new_line = Segment.line()
22
23 columns = self.columns
24 show_header = self.show_header
25 show_footer = self.show_footer
26 show_edge = self.show_edge
27 show_lines = self.show_lines
28 leading = self.leading
29
30 _Segment = Segment
31 if _box:
32 box_segments = [
33 (
34 _Segment(_box.head_left, border_style),
35 _Segment(_box.head_right, border_style),
36 _Segment(_box.head_vertical, border_style),
37 ),
38 (
39 _Segment(_box.foot_left, border_style),
40 _Segment(_box.foot_right, border_style),
41 _Segment(_box.foot_vertical, border_style),
42 ),
43 (
44 _Segment(_box.mid_left, border_style),
45 _Segment(_box.mid_right, border_style),
46 _Segment(_box.mid_vertical, border_style),
47 ),
48 ]
49 if show_edge:
50 yield _Segment(_box.get_top(widths), border_style)
51 yield new_line
52 else:
53 box_segments = []
54
55 get_row_style = self.get_row_style
56 get_style = console.get_style
57
58 for index, (first, last, row_cell) in enumerate(loop_first_last(row_cells)):
59 header_row = first and show_header
60 footer_row = last and show_footer
61 row = (
62 self.rows[index - show_header]
63 if (not header_row and not footer_row)
64 else None
65 )
66 max_height = 1
67 cells: List[List[List[Segment]]] = []
68 if header_row or footer_row:
69 row_style = Style.null()
70 else:
71 row_style = get_style(
72 get_row_style(console, index - 1 if show_header else index)
73 )
74 for width, cell, column in zip(widths, row_cell, columns):
75 render_options = options.update(
76 width=width,
77 justify=column.justify,
78 no_wrap=column.no_wrap,
79 overflow=column.overflow,
80 height=None,
81 )
82 lines = console.render_lines(
83 cell.renderable,
84 render_options,
85 style=get_style(cell.style) + row_style,
86 )
87 max_height = max(max_height, len(lines))
88 cells.append(lines)
89
90 row_height = max(len(cell) for cell in cells)
91
92 def align_cell(
93 cell: List[List[Segment]],
94 vertical: "VerticalAlignMethod",
95 width: int,
96 style: Style,
97 ) -> List[List[Segment]]:
98 if header_row:
99 vertical = "bottom"
100 elif footer_row:
101 vertical = "top"
102
103 if vertical == "top":
104 return _Segment.align_top(cell, width, row_height, style)
105 elif vertical == "middle":
106 return _Segment.align_middle(cell, width, row_height, style)
107 return _Segment.align_bottom(cell, width, row_height, style)
108
109 cells[:] = [
110 _Segment.set_shape(
111 align_cell(
112 cell,
113 _cell.vertical,
114 width,
115 get_style(_cell.style) + row_style,
116 ),
117 width,
118 max_height,
119 )
120 for width, _cell, cell, column in zip(widths, row_cell, cells, columns)
121 ]
122
123 if _box:
124 if last and show_footer:
125 yield _Segment(
126 _box.get_row(widths, "foot", edge=show_edge), border_style
127 )
128 yield new_line
129 left, right, _divider = box_segments[0 if first else (2 if last else 1)]
130
131 # If the column divider is whitespace also style it with the row background
132 divider = (
133 _divider
134 if _divider.text.strip()
135 else _Segment(
136 _divider.text, row_style.background_style + _divider.style
137 )
138 )
139 for line_no in range(max_height):
140 if show_edge:
141 yield left
142 for last_cell, rendered_cell in loop_last(cells):
143 yield from rendered_cell[line_no]
144 if not last_cell:
145 yield divider
146 if show_edge:
147 yield right
148 yield new_line
149 else:
150 for line_no in range(max_height):
151 for rendered_cell in cells:
152 yield from rendered_cell[line_no]
153 yield new_line
154 if _box and first and show_header:
155 yield _Segment(
156 _box.get_row(widths, "head", edge=show_edge), border_style
157 )
158 yield new_line
159 end_section = row and row.end_section
160 if _box and (show_lines or leading or end_section):
161 if (
162 not last
163 and not (show_footer and index >= len(row_cells) - 2)
164 and not (show_header and header_row)
165 ):
166 if leading:
167 yield _Segment(
168 _box.get_row(widths, "mid", edge=show_edge) * leading,
169 border_style,
170 )
171 else:
172 yield _Segment(
173 _box.get_row(widths, "row", edge=show_edge), border_style
174 )
175 yield new_line
176
177 if _box and show_edge:
178 yield _Segment(_box.get_bottom(widths), border_style)
179 yield new_line
Path 5: 4 calls (0.03)
Console (4)
ConsoleOptions (4)
[22, 17, 5, 10] (2) [17, 0, 0, 0] (1) [10, 9, 0, 0] (1)
Segment (542)
1def _render(
2 self, console: "Console", options: "ConsoleOptions", widths: List[int]
3 ) -> "RenderResult":
4 table_style = console.get_style(self.style or "")
5
6 border_style = table_style + console.get_style(self.border_style or "")
7 _column_cells = (
8 self._get_cells(console, column_index, column)
9 for column_index, column in enumerate(self.columns)
10 )
11 row_cells: List[Tuple[_Cell, ...]] = list(zip(*_column_cells))
12 _box = (
13 self.box.substitute(
14 options, safe=pick_bool(self.safe_box, console.safe_box)
15 )
16 if self.box
17 else None
18 )
19 _box = _box.get_plain_headed_box() if _box and not self.show_header else _box
20
21 new_line = Segment.line()
22
23 columns = self.columns
24 show_header = self.show_header
25 show_footer = self.show_footer
26 show_edge = self.show_edge
27 show_lines = self.show_lines
28 leading = self.leading
29
30 _Segment = Segment
31 if _box:
32 box_segments = [
33 (
34 _Segment(_box.head_left, border_style),
35 _Segment(_box.head_right, border_style),
36 _Segment(_box.head_vertical, border_style),
37 ),
38 (
39 _Segment(_box.foot_left, border_style),
40 _Segment(_box.foot_right, border_style),
41 _Segment(_box.foot_vertical, border_style),
42 ),
43 (
44 _Segment(_box.mid_left, border_style),
45 _Segment(_box.mid_right, border_style),
46 _Segment(_box.mid_vertical, border_style),
47 ),
48 ]
49 if show_edge:
50 yield _Segment(_box.get_top(widths), border_style)
51 yield new_line
52 else:
53 box_segments = []
54
55 get_row_style = self.get_row_style
56 get_style = console.get_style
57
58 for index, (first, last, row_cell) in enumerate(loop_first_last(row_cells)):
59 header_row = first and show_header
60 footer_row = last and show_footer
61 row = (
62 self.rows[index - show_header]
63 if (not header_row and not footer_row)
64 else None
65 )
66 max_height = 1
67 cells: List[List[List[Segment]]] = []
68 if header_row or footer_row:
69 row_style = Style.null()
70 else:
71 row_style = get_style(
72 get_row_style(console, index - 1 if show_header else index)
73 )
74 for width, cell, column in zip(widths, row_cell, columns):
75 render_options = options.update(
76 width=width,
77 justify=column.justify,
78 no_wrap=column.no_wrap,
79 overflow=column.overflow,
80 height=None,
81 )
82 lines = console.render_lines(
83 cell.renderable,
84 render_options,
85 style=get_style(cell.style) + row_style,
86 )
87 max_height = max(max_height, len(lines))
88 cells.append(lines)
89
90 row_height = max(len(cell) for cell in cells)
91
92 def align_cell(
93 cell: List[List[Segment]],
94 vertical: "VerticalAlignMethod",
95 width: int,
96 style: Style,
97 ) -> List[List[Segment]]:
98 if header_row:
99 vertical = "bottom"
100 elif footer_row:
101 vertical = "top"
102
103 if vertical == "top":
104 return _Segment.align_top(cell, width, row_height, style)
105 elif vertical == "middle":
106 return _Segment.align_middle(cell, width, row_height, style)
107 return _Segment.align_bottom(cell, width, row_height, style)
108
109 cells[:] = [
110 _Segment.set_shape(
111 align_cell(
112 cell,
113 _cell.vertical,
114 width,
115 get_style(_cell.style) + row_style,
116 ),
117 width,
118 max_height,
119 )
120 for width, _cell, cell, column in zip(widths, row_cell, cells, columns)
121 ]
122
123 if _box:
124 if last and show_footer:
125 yield _Segment(
126 _box.get_row(widths, "foot", edge=show_edge), border_style
127 )
128 yield new_line
129 left, right, _divider = box_segments[0 if first else (2 if last else 1)]
130
131 # If the column divider is whitespace also style it with the row background
132 divider = (
133 _divider
134 if _divider.text.strip()
135 else _Segment(
136 _divider.text, row_style.background_style + _divider.style
137 )
138 )
139 for line_no in range(max_height):
140 if show_edge:
141 yield left
142 for last_cell, rendered_cell in loop_last(cells):
143 yield from rendered_cell[line_no]
144 if not last_cell:
145 yield divider
146 if show_edge:
147 yield right
148 yield new_line
149 else:
150 for line_no in range(max_height):
151 for rendered_cell in cells:
152 yield from rendered_cell[line_no]
153 yield new_line
154 if _box and first and show_header:
155 yield _Segment(
156 _box.get_row(widths, "head", edge=show_edge), border_style
157 )
158 yield new_line
159 end_section = row and row.end_section
160 if _box and (show_lines or leading or end_section):
161 if (
162 not last
163 and not (show_footer and index >= len(row_cells) - 2)
164 and not (show_header and header_row)
165 ):
166 if leading:
167 yield _Segment(
168 _box.get_row(widths, "mid", edge=show_edge) * leading,
169 border_style,
170 )
171 else:
172 yield _Segment(
173 _box.get_row(widths, "row", edge=show_edge), border_style
174 )
175 yield new_line
176
177 if _box and show_edge:
178 yield _Segment(_box.get_bottom(widths), border_style)
179 yield new_line
Path 6: 1 calls (0.01)
Console (1)
ConsoleOptions (1)
[14, 33, 19, 16] (1)
Segment (121)
1def _render(
2 self, console: "Console", options: "ConsoleOptions", widths: List[int]
3 ) -> "RenderResult":
4 table_style = console.get_style(self.style or "")
5
6 border_style = table_style + console.get_style(self.border_style or "")
7 _column_cells = (
8 self._get_cells(console, column_index, column)
9 for column_index, column in enumerate(self.columns)
10 )
11 row_cells: List[Tuple[_Cell, ...]] = list(zip(*_column_cells))
12 _box = (
13 self.box.substitute(
14 options, safe=pick_bool(self.safe_box, console.safe_box)
15 )
16 if self.box
17 else None
18 )
19 _box = _box.get_plain_headed_box() if _box and not self.show_header else _box
20
21 new_line = Segment.line()
22
23 columns = self.columns
24 show_header = self.show_header
25 show_footer = self.show_footer
26 show_edge = self.show_edge
27 show_lines = self.show_lines
28 leading = self.leading
29
30 _Segment = Segment
31 if _box:
32 box_segments = [
33 (
34 _Segment(_box.head_left, border_style),
35 _Segment(_box.head_right, border_style),
36 _Segment(_box.head_vertical, border_style),
37 ),
38 (
39 _Segment(_box.foot_left, border_style),
40 _Segment(_box.foot_right, border_style),
41 _Segment(_box.foot_vertical, border_style),
42 ),
43 (
44 _Segment(_box.mid_left, border_style),
45 _Segment(_box.mid_right, border_style),
46 _Segment(_box.mid_vertical, border_style),
47 ),
48 ]
49 if show_edge:
50 yield _Segment(_box.get_top(widths), border_style)
51 yield new_line
52 else:
53 box_segments = []
54
55 get_row_style = self.get_row_style
56 get_style = console.get_style
57
58 for index, (first, last, row_cell) in enumerate(loop_first_last(row_cells)):
59 header_row = first and show_header
60 footer_row = last and show_footer
61 row = (
62 self.rows[index - show_header]
63 if (not header_row and not footer_row)
64 else None
65 )
66 max_height = 1
67 cells: List[List[List[Segment]]] = []
68 if header_row or footer_row:
69 row_style = Style.null()
70 else:
71 row_style = get_style(
72 get_row_style(console, index - 1 if show_header else index)
73 )
74 for width, cell, column in zip(widths, row_cell, columns):
75 render_options = options.update(
76 width=width,
77 justify=column.justify,
78 no_wrap=column.no_wrap,
79 overflow=column.overflow,
80 height=None,
81 )
82 lines = console.render_lines(
83 cell.renderable,
84 render_options,
85 style=get_style(cell.style) + row_style,
86 )
87 max_height = max(max_height, len(lines))
88 cells.append(lines)
89
90 row_height = max(len(cell) for cell in cells)
91
92 def align_cell(
93 cell: List[List[Segment]],
94 vertical: "VerticalAlignMethod",
95 width: int,
96 style: Style,
97 ) -> List[List[Segment]]:
98 if header_row:
99 vertical = "bottom"
100 elif footer_row:
101 vertical = "top"
102
103 if vertical == "top":
104 return _Segment.align_top(cell, width, row_height, style)
105 elif vertical == "middle":
106 return _Segment.align_middle(cell, width, row_height, style)
107 return _Segment.align_bottom(cell, width, row_height, style)
108
109 cells[:] = [
110 _Segment.set_shape(
111 align_cell(
112 cell,
113 _cell.vertical,
114 width,
115 get_style(_cell.style) + row_style,
116 ),
117 width,
118 max_height,
119 )
120 for width, _cell, cell, column in zip(widths, row_cell, cells, columns)
121 ]
122
123 if _box:
124 if last and show_footer:
125 yield _Segment(
126 _box.get_row(widths, "foot", edge=show_edge), border_style
127 )
128 yield new_line
129 left, right, _divider = box_segments[0 if first else (2 if last else 1)]
130
131 # If the column divider is whitespace also style it with the row background
132 divider = (
133 _divider
134 if _divider.text.strip()
135 else _Segment(
136 _divider.text, row_style.background_style + _divider.style
137 )
138 )
139 for line_no in range(max_height):
140 if show_edge:
141 yield left
142 for last_cell, rendered_cell in loop_last(cells):
143 yield from rendered_cell[line_no]
144 if not last_cell:
145 yield divider
146 if show_edge:
147 yield right
148 yield new_line
149 else:
150 for line_no in range(max_height):
151 for rendered_cell in cells:
152 yield from rendered_cell[line_no]
153 yield new_line
154 if _box and first and show_header:
155 yield _Segment(
156 _box.get_row(widths, "head", edge=show_edge), border_style
157 )
158 yield new_line
159 end_section = row and row.end_section
160 if _box and (show_lines or leading or end_section):
161 if (
162 not last
163 and not (show_footer and index >= len(row_cells) - 2)
164 and not (show_header and header_row)
165 ):
166 if leading:
167 yield _Segment(
168 _box.get_row(widths, "mid", edge=show_edge) * leading,
169 border_style,
170 )
171 else:
172 yield _Segment(
173 _box.get_row(widths, "row", edge=show_edge), border_style
174 )
175 yield new_line
176
177 if _box and show_edge:
178 yield _Segment(_box.get_bottom(widths), border_style)
179 yield new_line
Path 7: 1 calls (0.01)
Console (1)
ConsoleOptions (1)
[22, 17, 5, 10] (1)
Segment (82) None (1)
1def _render(
2 self, console: "Console", options: "ConsoleOptions", widths: List[int]
3 ) -> "RenderResult":
4 table_style = console.get_style(self.style or "")
5
6 border_style = table_style + console.get_style(self.border_style or "")
7 _column_cells = (
8 self._get_cells(console, column_index, column)
9 for column_index, column in enumerate(self.columns)
10 )
11 row_cells: List[Tuple[_Cell, ...]] = list(zip(*_column_cells))
12 _box = (
13 self.box.substitute(
14 options, safe=pick_bool(self.safe_box, console.safe_box)
15 )
16 if self.box
17 else None
18 )
19 _box = _box.get_plain_headed_box() if _box and not self.show_header else _box
20
21 new_line = Segment.line()
22
23 columns = self.columns
24 show_header = self.show_header
25 show_footer = self.show_footer
26 show_edge = self.show_edge
27 show_lines = self.show_lines
28 leading = self.leading
29
30 _Segment = Segment
31 if _box:
32 box_segments = [
33 (
34 _Segment(_box.head_left, border_style),
35 _Segment(_box.head_right, border_style),
36 _Segment(_box.head_vertical, border_style),
37 ),
38 (
39 _Segment(_box.foot_left, border_style),
40 _Segment(_box.foot_right, border_style),
41 _Segment(_box.foot_vertical, border_style),
42 ),
43 (
44 _Segment(_box.mid_left, border_style),
45 _Segment(_box.mid_right, border_style),
46 _Segment(_box.mid_vertical, border_style),
47 ),
48 ]
49 if show_edge:
50 yield _Segment(_box.get_top(widths), border_style)
51 yield new_line
52 else:
53 box_segments = []
54
55 get_row_style = self.get_row_style
56 get_style = console.get_style
57
58 for index, (first, last, row_cell) in enumerate(loop_first_last(row_cells)):
59 header_row = first and show_header
60 footer_row = last and show_footer
61 row = (
62 self.rows[index - show_header]
63 if (not header_row and not footer_row)
64 else None
65 )
66 max_height = 1
67 cells: List[List[List[Segment]]] = []
68 if header_row or footer_row:
69 row_style = Style.null()
70 else:
71 row_style = get_style(
72 get_row_style(console, index - 1 if show_header else index)
73 )
74 for width, cell, column in zip(widths, row_cell, columns):
75 render_options = options.update(
76 width=width,
77 justify=column.justify,
78 no_wrap=column.no_wrap,
79 overflow=column.overflow,
80 height=None,
81 )
82 lines = console.render_lines(
83 cell.renderable,
84 render_options,
85 style=get_style(cell.style) + row_style,
86 )
87 max_height = max(max_height, len(lines))
88 cells.append(lines)
89
90 row_height = max(len(cell) for cell in cells)
91
92 def align_cell(
93 cell: List[List[Segment]],
94 vertical: "VerticalAlignMethod",
95 width: int,
96 style: Style,
97 ) -> List[List[Segment]]:
98 if header_row:
99 vertical = "bottom"
100 elif footer_row:
101 vertical = "top"
102
103 if vertical == "top":
104 return _Segment.align_top(cell, width, row_height, style)
105 elif vertical == "middle":
106 return _Segment.align_middle(cell, width, row_height, style)
107 return _Segment.align_bottom(cell, width, row_height, style)
108
109 cells[:] = [
110 _Segment.set_shape(
111 align_cell(
112 cell,
113 _cell.vertical,
114 width,
115 get_style(_cell.style) + row_style,
116 ),
117 width,
118 max_height,
119 )
120 for width, _cell, cell, column in zip(widths, row_cell, cells, columns)
121 ]
122
123 if _box:
124 if last and show_footer:
125 yield _Segment(
126 _box.get_row(widths, "foot", edge=show_edge), border_style
127 )
128 yield new_line
129 left, right, _divider = box_segments[0 if first else (2 if last else 1)]
130
131 # If the column divider is whitespace also style it with the row background
132 divider = (
133 _divider
134 if _divider.text.strip()
135 else _Segment(
136 _divider.text, row_style.background_style + _divider.style
137 )
138 )
139 for line_no in range(max_height):
140 if show_edge:
141 yield left
142 for last_cell, rendered_cell in loop_last(cells):
143 yield from rendered_cell[line_no]
144 if not last_cell:
145 yield divider
146 if show_edge:
147 yield right
148 yield new_line
149 else:
150 for line_no in range(max_height):
151 for rendered_cell in cells:
152 yield from rendered_cell[line_no]
153 yield new_line
154 if _box and first and show_header:
155 yield _Segment(
156 _box.get_row(widths, "head", edge=show_edge), border_style
157 )
158 yield new_line
159 end_section = row and row.end_section
160 if _box and (show_lines or leading or end_section):
161 if (
162 not last
163 and not (show_footer and index >= len(row_cells) - 2)
164 and not (show_header and header_row)
165 ):
166 if leading:
167 yield _Segment(
168 _box.get_row(widths, "mid", edge=show_edge) * leading,
169 border_style,
170 )
171 else:
172 yield _Segment(
173 _box.get_row(widths, "row", edge=show_edge), border_style
174 )
175 yield new_line
176
177 if _box and show_edge:
178 yield _Segment(_box.get_bottom(widths), border_style)
179 yield new_line
Path 8: 1 calls (0.01)
Console (1)
ConsoleOptions (1)
[22, 17, 5, 10] (1)
Segment (102) None (1)
1def _render(
2 self, console: "Console", options: "ConsoleOptions", widths: List[int]
3 ) -> "RenderResult":
4 table_style = console.get_style(self.style or "")
5
6 border_style = table_style + console.get_style(self.border_style or "")
7 _column_cells = (
8 self._get_cells(console, column_index, column)
9 for column_index, column in enumerate(self.columns)
10 )
11 row_cells: List[Tuple[_Cell, ...]] = list(zip(*_column_cells))
12 _box = (
13 self.box.substitute(
14 options, safe=pick_bool(self.safe_box, console.safe_box)
15 )
16 if self.box
17 else None
18 )
19 _box = _box.get_plain_headed_box() if _box and not self.show_header else _box
20
21 new_line = Segment.line()
22
23 columns = self.columns
24 show_header = self.show_header
25 show_footer = self.show_footer
26 show_edge = self.show_edge
27 show_lines = self.show_lines
28 leading = self.leading
29
30 _Segment = Segment
31 if _box:
32 box_segments = [
33 (
34 _Segment(_box.head_left, border_style),
35 _Segment(_box.head_right, border_style),
36 _Segment(_box.head_vertical, border_style),
37 ),
38 (
39 _Segment(_box.foot_left, border_style),
40 _Segment(_box.foot_right, border_style),
41 _Segment(_box.foot_vertical, border_style),
42 ),
43 (
44 _Segment(_box.mid_left, border_style),
45 _Segment(_box.mid_right, border_style),
46 _Segment(_box.mid_vertical, border_style),
47 ),
48 ]
49 if show_edge:
50 yield _Segment(_box.get_top(widths), border_style)
51 yield new_line
52 else:
53 box_segments = []
54
55 get_row_style = self.get_row_style
56 get_style = console.get_style
57
58 for index, (first, last, row_cell) in enumerate(loop_first_last(row_cells)):
59 header_row = first and show_header
60 footer_row = last and show_footer
61 row = (
62 self.rows[index - show_header]
63 if (not header_row and not footer_row)
64 else None
65 )
66 max_height = 1
67 cells: List[List[List[Segment]]] = []
68 if header_row or footer_row:
69 row_style = Style.null()
70 else:
71 row_style = get_style(
72 get_row_style(console, index - 1 if show_header else index)
73 )
74 for width, cell, column in zip(widths, row_cell, columns):
75 render_options = options.update(
76 width=width,
77 justify=column.justify,
78 no_wrap=column.no_wrap,
79 overflow=column.overflow,
80 height=None,
81 )
82 lines = console.render_lines(
83 cell.renderable,
84 render_options,
85 style=get_style(cell.style) + row_style,
86 )
87 max_height = max(max_height, len(lines))
88 cells.append(lines)
89
90 row_height = max(len(cell) for cell in cells)
91
92 def align_cell(
93 cell: List[List[Segment]],
94 vertical: "VerticalAlignMethod",
95 width: int,
96 style: Style,
97 ) -> List[List[Segment]]:
98 if header_row:
99 vertical = "bottom"
100 elif footer_row:
101 vertical = "top"
102
103 if vertical == "top":
104 return _Segment.align_top(cell, width, row_height, style)
105 elif vertical == "middle":
106 return _Segment.align_middle(cell, width, row_height, style)
107 return _Segment.align_bottom(cell, width, row_height, style)
108
109 cells[:] = [
110 _Segment.set_shape(
111 align_cell(
112 cell,
113 _cell.vertical,
114 width,
115 get_style(_cell.style) + row_style,
116 ),
117 width,
118 max_height,
119 )
120 for width, _cell, cell, column in zip(widths, row_cell, cells, columns)
121 ]
122
123 if _box:
124 if last and show_footer:
125 yield _Segment(
126 _box.get_row(widths, "foot", edge=show_edge), border_style
127 )
128 yield new_line
129 left, right, _divider = box_segments[0 if first else (2 if last else 1)]
130
131 # If the column divider is whitespace also style it with the row background
132 divider = (
133 _divider
134 if _divider.text.strip()
135 else _Segment(
136 _divider.text, row_style.background_style + _divider.style
137 )
138 )
139 for line_no in range(max_height):
140 if show_edge:
141 yield left
142 for last_cell, rendered_cell in loop_last(cells):
143 yield from rendered_cell[line_no]
144 if not last_cell:
145 yield divider
146 if show_edge:
147 yield right
148 yield new_line
149 else:
150 for line_no in range(max_height):
151 for rendered_cell in cells:
152 yield from rendered_cell[line_no]
153 yield new_line
154 if _box and first and show_header:
155 yield _Segment(
156 _box.get_row(widths, "head", edge=show_edge), border_style
157 )
158 yield new_line
159 end_section = row and row.end_section
160 if _box and (show_lines or leading or end_section):
161 if (
162 not last
163 and not (show_footer and index >= len(row_cells) - 2)
164 and not (show_header and header_row)
165 ):
166 if leading:
167 yield _Segment(
168 _box.get_row(widths, "mid", edge=show_edge) * leading,
169 border_style,
170 )
171 else:
172 yield _Segment(
173 _box.get_row(widths, "row", edge=show_edge), border_style
174 )
175 yield new_line
176
177 if _box and show_edge:
178 yield _Segment(_box.get_bottom(widths), border_style)
179 yield new_line
Path 9: 1 calls (0.01)
Console (1)
ConsoleOptions (1)
[25, 19, 4, 9] (1)
Segment (48)
1def _render(
2 self, console: "Console", options: "ConsoleOptions", widths: List[int]
3 ) -> "RenderResult":
4 table_style = console.get_style(self.style or "")
5
6 border_style = table_style + console.get_style(self.border_style or "")
7 _column_cells = (
8 self._get_cells(console, column_index, column)
9 for column_index, column in enumerate(self.columns)
10 )
11 row_cells: List[Tuple[_Cell, ...]] = list(zip(*_column_cells))
12 _box = (
13 self.box.substitute(
14 options, safe=pick_bool(self.safe_box, console.safe_box)
15 )
16 if self.box
17 else None
18 )
19 _box = _box.get_plain_headed_box() if _box and not self.show_header else _box
20
21 new_line = Segment.line()
22
23 columns = self.columns
24 show_header = self.show_header
25 show_footer = self.show_footer
26 show_edge = self.show_edge
27 show_lines = self.show_lines
28 leading = self.leading
29
30 _Segment = Segment
31 if _box:
32 box_segments = [
33 (
34 _Segment(_box.head_left, border_style),
35 _Segment(_box.head_right, border_style),
36 _Segment(_box.head_vertical, border_style),
37 ),
38 (
39 _Segment(_box.foot_left, border_style),
40 _Segment(_box.foot_right, border_style),
41 _Segment(_box.foot_vertical, border_style),
42 ),
43 (
44 _Segment(_box.mid_left, border_style),
45 _Segment(_box.mid_right, border_style),
46 _Segment(_box.mid_vertical, border_style),
47 ),
48 ]
49 if show_edge:
50 yield _Segment(_box.get_top(widths), border_style)
51 yield new_line
52 else:
53 box_segments = []
54
55 get_row_style = self.get_row_style
56 get_style = console.get_style
57
58 for index, (first, last, row_cell) in enumerate(loop_first_last(row_cells)):
59 header_row = first and show_header
60 footer_row = last and show_footer
61 row = (
62 self.rows[index - show_header]
63 if (not header_row and not footer_row)
64 else None
65 )
66 max_height = 1
67 cells: List[List[List[Segment]]] = []
68 if header_row or footer_row:
69 row_style = Style.null()
70 else:
71 row_style = get_style(
72 get_row_style(console, index - 1 if show_header else index)
73 )
74 for width, cell, column in zip(widths, row_cell, columns):
75 render_options = options.update(
76 width=width,
77 justify=column.justify,
78 no_wrap=column.no_wrap,
79 overflow=column.overflow,
80 height=None,
81 )
82 lines = console.render_lines(
83 cell.renderable,
84 render_options,
85 style=get_style(cell.style) + row_style,
86 )
87 max_height = max(max_height, len(lines))
88 cells.append(lines)
89
90 row_height = max(len(cell) for cell in cells)
91
92 def align_cell(
93 cell: List[List[Segment]],
94 vertical: "VerticalAlignMethod",
95 width: int,
96 style: Style,
97 ) -> List[List[Segment]]:
98 if header_row:
99 vertical = "bottom"
100 elif footer_row:
101 vertical = "top"
102
103 if vertical == "top":
104 return _Segment.align_top(cell, width, row_height, style)
105 elif vertical == "middle":
106 return _Segment.align_middle(cell, width, row_height, style)
107 return _Segment.align_bottom(cell, width, row_height, style)
108
109 cells[:] = [
110 _Segment.set_shape(
111 align_cell(
112 cell,
113 _cell.vertical,
114 width,
115 get_style(_cell.style) + row_style,
116 ),
117 width,
118 max_height,
119 )
120 for width, _cell, cell, column in zip(widths, row_cell, cells, columns)
121 ]
122
123 if _box:
124 if last and show_footer:
125 yield _Segment(
126 _box.get_row(widths, "foot", edge=show_edge), border_style
127 )
128 yield new_line
129 left, right, _divider = box_segments[0 if first else (2 if last else 1)]
130
131 # If the column divider is whitespace also style it with the row background
132 divider = (
133 _divider
134 if _divider.text.strip()
135 else _Segment(
136 _divider.text, row_style.background_style + _divider.style
137 )
138 )
139 for line_no in range(max_height):
140 if show_edge:
141 yield left
142 for last_cell, rendered_cell in loop_last(cells):
143 yield from rendered_cell[line_no]
144 if not last_cell:
145 yield divider
146 if show_edge:
147 yield right
148 yield new_line
149 else:
150 for line_no in range(max_height):
151 for rendered_cell in cells:
152 yield from rendered_cell[line_no]
153 yield new_line
154 if _box and first and show_header:
155 yield _Segment(
156 _box.get_row(widths, "head", edge=show_edge), border_style
157 )
158 yield new_line
159 end_section = row and row.end_section
160 if _box and (show_lines or leading or end_section):
161 if (
162 not last
163 and not (show_footer and index >= len(row_cells) - 2)
164 and not (show_header and header_row)
165 ):
166 if leading:
167 yield _Segment(
168 _box.get_row(widths, "mid", edge=show_edge) * leading,
169 border_style,
170 )
171 else:
172 yield _Segment(
173 _box.get_row(widths, "row", edge=show_edge), border_style
174 )
175 yield new_line
176
177 if _box and show_edge:
178 yield _Segment(_box.get_bottom(widths), border_style)
179 yield new_line
Path 10: 1 calls (0.01)
Console (1)
ConsoleOptions (1)
[28] (1)
Segment (18) None (1)
1def _render(
2 self, console: "Console", options: "ConsoleOptions", widths: List[int]
3 ) -> "RenderResult":
4 table_style = console.get_style(self.style or "")
5
6 border_style = table_style + console.get_style(self.border_style or "")
7 _column_cells = (
8 self._get_cells(console, column_index, column)
9 for column_index, column in enumerate(self.columns)
10 )
11 row_cells: List[Tuple[_Cell, ...]] = list(zip(*_column_cells))
12 _box = (
13 self.box.substitute(
14 options, safe=pick_bool(self.safe_box, console.safe_box)
15 )
16 if self.box
17 else None
18 )
19 _box = _box.get_plain_headed_box() if _box and not self.show_header else _box
20
21 new_line = Segment.line()
22
23 columns = self.columns
24 show_header = self.show_header
25 show_footer = self.show_footer
26 show_edge = self.show_edge
27 show_lines = self.show_lines
28 leading = self.leading
29
30 _Segment = Segment
31 if _box:
32 box_segments = [
33 (
34 _Segment(_box.head_left, border_style),
35 _Segment(_box.head_right, border_style),
36 _Segment(_box.head_vertical, border_style),
37 ),
38 (
39 _Segment(_box.foot_left, border_style),
40 _Segment(_box.foot_right, border_style),
41 _Segment(_box.foot_vertical, border_style),
42 ),
43 (
44 _Segment(_box.mid_left, border_style),
45 _Segment(_box.mid_right, border_style),
46 _Segment(_box.mid_vertical, border_style),
47 ),
48 ]
49 if show_edge:
50 yield _Segment(_box.get_top(widths), border_style)
51 yield new_line
52 else:
53 box_segments = []
54
55 get_row_style = self.get_row_style
56 get_style = console.get_style
57
58 for index, (first, last, row_cell) in enumerate(loop_first_last(row_cells)):
59 header_row = first and show_header
60 footer_row = last and show_footer
61 row = (
62 self.rows[index - show_header]
63 if (not header_row and not footer_row)
64 else None
65 )
66 max_height = 1
67 cells: List[List[List[Segment]]] = []
68 if header_row or footer_row:
69 row_style = Style.null()
70 else:
71 row_style = get_style(
72 get_row_style(console, index - 1 if show_header else index)
73 )
74 for width, cell, column in zip(widths, row_cell, columns):
75 render_options = options.update(
76 width=width,
77 justify=column.justify,
78 no_wrap=column.no_wrap,
79 overflow=column.overflow,
80 height=None,
81 )
82 lines = console.render_lines(
83 cell.renderable,
84 render_options,
85 style=get_style(cell.style) + row_style,
86 )
87 max_height = max(max_height, len(lines))
88 cells.append(lines)
89
90 row_height = max(len(cell) for cell in cells)
91
92 def align_cell(
93 cell: List[List[Segment]],
94 vertical: "VerticalAlignMethod",
95 width: int,
96 style: Style,
97 ) -> List[List[Segment]]:
98 if header_row:
99 vertical = "bottom"
100 elif footer_row:
101 vertical = "top"
102
103 if vertical == "top":
104 return _Segment.align_top(cell, width, row_height, style)
105 elif vertical == "middle":
106 return _Segment.align_middle(cell, width, row_height, style)
107 return _Segment.align_bottom(cell, width, row_height, style)
108
109 cells[:] = [
110 _Segment.set_shape(
111 align_cell(
112 cell,
113 _cell.vertical,
114 width,
115 get_style(_cell.style) + row_style,
116 ),
117 width,
118 max_height,
119 )
120 for width, _cell, cell, column in zip(widths, row_cell, cells, columns)
121 ]
122
123 if _box:
124 if last and show_footer:
125 yield _Segment(
126 _box.get_row(widths, "foot", edge=show_edge), border_style
127 )
128 yield new_line
129 left, right, _divider = box_segments[0 if first else (2 if last else 1)]
130
131 # If the column divider is whitespace also style it with the row background
132 divider = (
133 _divider
134 if _divider.text.strip()
135 else _Segment(
136 _divider.text, row_style.background_style + _divider.style
137 )
138 )
139 for line_no in range(max_height):
140 if show_edge:
141 yield left
142 for last_cell, rendered_cell in loop_last(cells):
143 yield from rendered_cell[line_no]
144 if not last_cell:
145 yield divider
146 if show_edge:
147 yield right
148 yield new_line
149 else:
150 for line_no in range(max_height):
151 for rendered_cell in cells:
152 yield from rendered_cell[line_no]
153 yield new_line
154 if _box and first and show_header:
155 yield _Segment(
156 _box.get_row(widths, "head", edge=show_edge), border_style
157 )
158 yield new_line
159 end_section = row and row.end_section
160 if _box and (show_lines or leading or end_section):
161 if (
162 not last
163 and not (show_footer and index >= len(row_cells) - 2)
164 and not (show_header and header_row)
165 ):
166 if leading:
167 yield _Segment(
168 _box.get_row(widths, "mid", edge=show_edge) * leading,
169 border_style,
170 )
171 else:
172 yield _Segment(
173 _box.get_row(widths, "row", edge=show_edge), border_style
174 )
175 yield new_line
176
177 if _box and show_edge:
178 yield _Segment(_box.get_bottom(widths), border_style)
179 yield new_line
Path 11: 1 calls (0.01)
Console (1)
ConsoleOptions (1)
[6] (1)
Segment (46) None (1)
1def _render(
2 self, console: "Console", options: "ConsoleOptions", widths: List[int]
3 ) -> "RenderResult":
4 table_style = console.get_style(self.style or "")
5
6 border_style = table_style + console.get_style(self.border_style or "")
7 _column_cells = (
8 self._get_cells(console, column_index, column)
9 for column_index, column in enumerate(self.columns)
10 )
11 row_cells: List[Tuple[_Cell, ...]] = list(zip(*_column_cells))
12 _box = (
13 self.box.substitute(
14 options, safe=pick_bool(self.safe_box, console.safe_box)
15 )
16 if self.box
17 else None
18 )
19 _box = _box.get_plain_headed_box() if _box and not self.show_header else _box
20
21 new_line = Segment.line()
22
23 columns = self.columns
24 show_header = self.show_header
25 show_footer = self.show_footer
26 show_edge = self.show_edge
27 show_lines = self.show_lines
28 leading = self.leading
29
30 _Segment = Segment
31 if _box:
32 box_segments = [
33 (
34 _Segment(_box.head_left, border_style),
35 _Segment(_box.head_right, border_style),
36 _Segment(_box.head_vertical, border_style),
37 ),
38 (
39 _Segment(_box.foot_left, border_style),
40 _Segment(_box.foot_right, border_style),
41 _Segment(_box.foot_vertical, border_style),
42 ),
43 (
44 _Segment(_box.mid_left, border_style),
45 _Segment(_box.mid_right, border_style),
46 _Segment(_box.mid_vertical, border_style),
47 ),
48 ]
49 if show_edge:
50 yield _Segment(_box.get_top(widths), border_style)
51 yield new_line
52 else:
53 box_segments = []
54
55 get_row_style = self.get_row_style
56 get_style = console.get_style
57
58 for index, (first, last, row_cell) in enumerate(loop_first_last(row_cells)):
59 header_row = first and show_header
60 footer_row = last and show_footer
61 row = (
62 self.rows[index - show_header]
63 if (not header_row and not footer_row)
64 else None
65 )
66 max_height = 1
67 cells: List[List[List[Segment]]] = []
68 if header_row or footer_row:
69 row_style = Style.null()
70 else:
71 row_style = get_style(
72 get_row_style(console, index - 1 if show_header else index)
73 )
74 for width, cell, column in zip(widths, row_cell, columns):
75 render_options = options.update(
76 width=width,
77 justify=column.justify,
78 no_wrap=column.no_wrap,
79 overflow=column.overflow,
80 height=None,
81 )
82 lines = console.render_lines(
83 cell.renderable,
84 render_options,
85 style=get_style(cell.style) + row_style,
86 )
87 max_height = max(max_height, len(lines))
88 cells.append(lines)
89
90 row_height = max(len(cell) for cell in cells)
91
92 def align_cell(
93 cell: List[List[Segment]],
94 vertical: "VerticalAlignMethod",
95 width: int,
96 style: Style,
97 ) -> List[List[Segment]]:
98 if header_row:
99 vertical = "bottom"
100 elif footer_row:
101 vertical = "top"
102
103 if vertical == "top":
104 return _Segment.align_top(cell, width, row_height, style)
105 elif vertical == "middle":
106 return _Segment.align_middle(cell, width, row_height, style)
107 return _Segment.align_bottom(cell, width, row_height, style)
108
109 cells[:] = [
110 _Segment.set_shape(
111 align_cell(
112 cell,
113 _cell.vertical,
114 width,
115 get_style(_cell.style) + row_style,
116 ),
117 width,
118 max_height,
119 )
120 for width, _cell, cell, column in zip(widths, row_cell, cells, columns)
121 ]
122
123 if _box:
124 if last and show_footer:
125 yield _Segment(
126 _box.get_row(widths, "foot", edge=show_edge), border_style
127 )
128 yield new_line
129 left, right, _divider = box_segments[0 if first else (2 if last else 1)]
130
131 # If the column divider is whitespace also style it with the row background
132 divider = (
133 _divider
134 if _divider.text.strip()
135 else _Segment(
136 _divider.text, row_style.background_style + _divider.style
137 )
138 )
139 for line_no in range(max_height):
140 if show_edge:
141 yield left
142 for last_cell, rendered_cell in loop_last(cells):
143 yield from rendered_cell[line_no]
144 if not last_cell:
145 yield divider
146 if show_edge:
147 yield right
148 yield new_line
149 else:
150 for line_no in range(max_height):
151 for rendered_cell in cells:
152 yield from rendered_cell[line_no]
153 yield new_line
154 if _box and first and show_header:
155 yield _Segment(
156 _box.get_row(widths, "head", edge=show_edge), border_style
157 )
158 yield new_line
159 end_section = row and row.end_section
160 if _box and (show_lines or leading or end_section):
161 if (
162 not last
163 and not (show_footer and index >= len(row_cells) - 2)
164 and not (show_header and header_row)
165 ):
166 if leading:
167 yield _Segment(
168 _box.get_row(widths, "mid", edge=show_edge) * leading,
169 border_style,
170 )
171 else:
172 yield _Segment(
173 _box.get_row(widths, "row", edge=show_edge), border_style
174 )
175 yield new_line
176
177 if _box and show_edge:
178 yield _Segment(_box.get_bottom(widths), border_style)
179 yield new_line