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

Method set_shape

rich/segment.py:426–459  ·  view source on GitHub ↗

Set the shape of a list of lines (enclosing rectangle). Args: lines (List[List[Segment]]): A list of lines. width (int): Desired width. height (int, optional): Desired height or None for no change. style (Style, optional): Style of any padding

(
        cls,
        lines: List[List["Segment"]],
        width: int,
        height: Optional[int] = None,
        style: Optional[Style] = None,
        new_lines: bool = False,
    )

Source from the content-addressed store, hash-verified

424
425 @classmethod
426 def set_shape(
427 cls,
428 lines: List[List["Segment"]],
429 width: int,
430 height: Optional[int] = None,
431 style: Optional[Style] = None,
432 new_lines: bool = False,
433 ) -> List[List["Segment"]]:
434 """Set the shape of a list of lines (enclosing rectangle).
435
436 Args:
437 lines (List[List[Segment]]): A list of lines.
438 width (int): Desired width.
439 height (int, optional): Desired height or None for no change.
440 style (Style, optional): Style of any padding added.
441 new_lines (bool, optional): Padded lines should include "\n". Defaults to False.
442
443 Returns:
444 List[List[Segment]]: New list of lines.
445 """
446 _height = height or len(lines)
447
448 blank = (
449 [cls(" " * width + "\n", style)] if new_lines else [cls(" " * width, style)]
450 )
451
452 adjust_line_length = cls.adjust_line_length
453 shaped_lines = lines[:_height]
454 shaped_lines[:] = [
455 adjust_line_length(line, width, style=style) for line in lines
456 ]
457 if len(shaped_lines) < _height:
458 shaped_lines.extend([blank] * (_height - len(shaped_lines)))
459 return shaped_lines
460
461 @classmethod
462 def align_top(

Callers 4

test_set_shapeFunction · 0.80
_renderMethod · 0.80
__rich_console__Method · 0.80
__rich_console__Method · 0.80

Calls 1

extendMethod · 0.45

Tested by 1

test_set_shapeFunction · 0.64