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

Method _measure_column

rich/table.py:716–753  ·  view source on GitHub ↗

Get the minimum and maximum width of the column.

(
        self,
        console: "Console",
        options: "ConsoleOptions",
        column: Column,
    )

Source from the content-addressed store, hash-verified

714 return pad_left + pad_right
715
716 def _measure_column(
717 self,
718 console: "Console",
719 options: "ConsoleOptions",
720 column: Column,
721 ) -> Measurement:
722 """Get the minimum and maximum width of the column."""
723
724 max_width = options.max_width
725 if max_width < 1:
726 return Measurement(0, 0)
727
728 padding_width = self._get_padding_width(column._index)
729 if column.width is not None:
730 # Fixed width column
731 return Measurement(
732 column.width + padding_width, column.width + padding_width
733 ).with_maximum(max_width)
734 # Flexible column, we need to measure contents
735 min_widths: List[int] = []
736 max_widths: List[int] = []
737 append_min = min_widths.append
738 append_max = max_widths.append
739 get_render_width = Measurement.get
740 for cell in self._get_cells(console, column._index, column):
741 _min, _max = get_render_width(console, options, cell.renderable)
742 append_min(_min)
743 append_max(_max)
744
745 measurement = Measurement(
746 max(min_widths) if min_widths else 1,
747 max(max_widths) if max_widths else max_width,
748 ).with_maximum(max_width)
749 measurement = measurement.clamp(
750 None if column.min_width is None else column.min_width + padding_width,
751 None if column.max_width is None else column.max_width + padding_width,
752 )
753 return measurement
754
755 def _render(
756 self, console: "Console", options: "ConsoleOptions", widths: List[int]

Callers 1

Calls 5

_get_padding_widthMethod · 0.95
_get_cellsMethod · 0.95
MeasurementClass · 0.85
with_maximumMethod · 0.80
clampMethod · 0.80

Tested by

no test coverage detected