Method: rich.table.Table._measure_column
Calls: 591, Exceptions: 0, Paths: 3Back
Path 1: 539 calls (0.91)
Console (539)
ConsoleOptions (539)
Column (539)
Measurement (539)
1def _measure_column(
2 self,
3 console: "Console",
4 options: "ConsoleOptions",
5 column: Column,
6 ) -> Measurement:
7 """Get the minimum and maximum width of the column."""
8
9 max_width = options.max_width
10 if max_width < 1:
11 return Measurement(0, 0)
12
13 padding_width = self._get_padding_width(column._index)
14
15 if column.width is not None:
16 # Fixed width column
17 return Measurement(
18 column.width + padding_width, column.width + padding_width
19 ).with_maximum(max_width)
20 # Flexible column, we need to measure contents
21 min_widths: List[int] = []
22 max_widths: List[int] = []
23 append_min = min_widths.append
24 append_max = max_widths.append
25 get_render_width = Measurement.get
26 for cell in self._get_cells(console, column._index, column):
27 _min, _max = get_render_width(console, options, cell.renderable)
28 append_min(_min)
29 append_max(_max)
30
31 measurement = Measurement(
32 max(min_widths) if min_widths else 1,
33 max(max_widths) if max_widths else max_width,
34 ).with_maximum(max_width)
35 measurement = measurement.clamp(
36 None if column.min_width is None else column.min_width + padding_width,
37 None if column.max_width is None else column.max_width + padding_width,
38 )
39 return measurement
Path 2: 27 calls (0.05)
Console (27)
ConsoleOptions (27)
Column (27)
Measurement (27)
1def _measure_column(
2 self,
3 console: "Console",
4 options: "ConsoleOptions",
5 column: Column,
6 ) -> Measurement:
7 """Get the minimum and maximum width of the column."""
8
9 max_width = options.max_width
10 if max_width < 1:
11 return Measurement(0, 0)
12
13 padding_width = self._get_padding_width(column._index)
14
15 if column.width is not None:
16 # Fixed width column
17 return Measurement(
18 column.width + padding_width, column.width + padding_width
19 ).with_maximum(max_width)
20 # Flexible column, we need to measure contents
21 min_widths: List[int] = []
22 max_widths: List[int] = []
23 append_min = min_widths.append
24 append_max = max_widths.append
25 get_render_width = Measurement.get
26 for cell in self._get_cells(console, column._index, column):
27 _min, _max = get_render_width(console, options, cell.renderable)
28 append_min(_min)
29 append_max(_max)
30
31 measurement = Measurement(
32 max(min_widths) if min_widths else 1,
33 max(max_widths) if max_widths else max_width,
34 ).with_maximum(max_width)
35 measurement = measurement.clamp(
36 None if column.min_width is None else column.min_width + padding_width,
37 None if column.max_width is None else column.max_width + padding_width,
38 )
39 return measurement
Path 3: 25 calls (0.04)
Console (25)
ConsoleOptions (25)
Column (25)
Measurement (25)
1def _measure_column(
2 self,
3 console: "Console",
4 options: "ConsoleOptions",
5 column: Column,
6 ) -> Measurement:
7 """Get the minimum and maximum width of the column."""
8
9 max_width = options.max_width
10 if max_width < 1:
11 return Measurement(0, 0)
12
13 padding_width = self._get_padding_width(column._index)
14
15 if column.width is not None:
16 # Fixed width column
17 return Measurement(
18 column.width + padding_width, column.width + padding_width
19 ).with_maximum(max_width)
20 # Flexible column, we need to measure contents
21 min_widths: List[int] = []
22 max_widths: List[int] = []
23 append_min = min_widths.append
24 append_max = max_widths.append
25 get_render_width = Measurement.get
26 for cell in self._get_cells(console, column._index, column):
27 _min, _max = get_render_width(console, options, cell.renderable)
28 append_min(_min)
29 append_max(_max)
30
31 measurement = Measurement(
32 max(min_widths) if min_widths else 1,
33 max(max_widths) if max_widths else max_width,
34 ).with_maximum(max_width)
35 measurement = measurement.clamp(
36 None if column.min_width is None else column.min_width + padding_width,
37 None if column.max_width is None else column.max_width + padding_width,
38 )
39 return measurement