rich.measure

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

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

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 RenderableWidth object.

Return type

RenderableWidth

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