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

Method clamp

rich/measure.py:59–76  ·  view source on GitHub ↗

Clamp a measurement within the specified range. Args: min_width (int): Minimum desired width, or ``None`` for no minimum. Defaults to None. max_width (int): Maximum desired width, or ``None`` for no maximum. Defaults to None. Returns: Measurement

(
        self, min_width: Optional[int] = None, max_width: Optional[int] = None
    )

Source from the content-addressed store, hash-verified

57 return Measurement(max(minimum, width), max(maximum, width))
58
59 def clamp(
60 self, min_width: Optional[int] = None, max_width: Optional[int] = None
61 ) -> "Measurement":
62 """Clamp a measurement within the specified range.
63
64 Args:
65 min_width (int): Minimum desired width, or ``None`` for no minimum. Defaults to None.
66 max_width (int): Maximum desired width, or ``None`` for no maximum. Defaults to None.
67
68 Returns:
69 Measurement: New Measurement object.
70 """
71 measurement = self
72 if min_width is not None:
73 measurement = measurement.with_minimum(min_width)
74 if max_width is not None:
75 measurement = measurement.with_maximum(max_width)
76 return measurement
77
78 @classmethod
79 def get(

Callers 3

test_clampFunction · 0.95
__rich_measure__Method · 0.95
_measure_columnMethod · 0.80

Calls 2

with_minimumMethod · 0.80
with_maximumMethod · 0.80

Tested by 1

test_clampFunction · 0.76