rich.measure

class rich.measure.Measurement(minimum: int, maximum: int)[source]

Stores the minimum and maximum widths (in characters) required to render an object.

clamp(min_width: Optional[int] = None, max_width: Optional[int] = None)rich.measure.Measurement[source]

Clamp a measurement within the specified range.

Parameters
  • 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

New Measurement object.

Return type

Measurement

classmethod get(console: Console, renderable: RenderableType, max_width: int = None)Measurement[source]

Get a measurement for a renderable.

Parameters
  • console (Console) – Console instance.

  • renderable (RenderableType) – An object that may be rendered with Rich.

  • max_width (int, optional) – The maximum width available, or None to use console.width. Defaults to None.

Raises

errors.NotRenderableError – If the object is not renderable.

Returns

Measurement object containing range of character widths required to render the object.

Return type

Measurement

property maximum

Maximum number of cells required to render.

property minimum

Minimum number of cells required to render.

normalize()rich.measure.Measurement[source]

Get measurement that ensures that minimum <= maximum and minimum >= 0

Returns

A normalized measurement.

Return type

Measurement

property span

Get difference between maximum and minimum.

with_maximum(width: int)rich.measure.Measurement[source]

Get a RenderableWith where the widths are <= width.

Parameters

width (int) – Maximum desired width.

Returns

New Measurement object.

Return type

Measurement

with_minimum(width: int)rich.measure.Measurement[source]

Get a RenderableWith where the widths are >= width.

Parameters

width (int) – Minimum desired width.

Returns

New Measurement object.

Return type

Measurement

rich.measure.measure_renderables(console: Console, renderables: Iterable[RenderableType], max_width: int)Measurement[source]

Get a measurement that would fit a number of renderables.

Parameters
  • console (Console) – Console instance.

  • renderables (Iterable[RenderableType]) – One or more renderable objects.

  • max_width (int) – The maximum width available.

Returns

Measurement object containing range of character widths required to contain all given renderables.

Return type

Measurement