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

Method align

rich/text.py:944–962  ·  view source on GitHub ↗

Align text to a given width. Args: align (AlignMethod): One of "left", "center", or "right". width (int): Desired width. character (str, optional): Character to pad with. Defaults to " ".

(self, align: AlignMethod, width: int, character: str = " ")

Source from the content-addressed store, hash-verified

942 self.plain = f"{self.plain}{character * count}"
943
944 def align(self, align: AlignMethod, width: int, character: str = " ") -> None:
945 """Align text to a given width.
946
947 Args:
948 align (AlignMethod): One of "left", "center", or "right".
949 width (int): Desired width.
950 character (str, optional): Character to pad with. Defaults to " ".
951 """
952 self.truncate(width)
953 excess_space = width - cell_len(self.plain)
954 if excess_space:
955 if align == "left":
956 self.pad_right(excess_space, character)
957 elif align == "center":
958 left = excess_space // 2
959 self.pad_left(left, character)
960 self.pad_right(excess_space - left, character)
961 else:
962 self.pad_left(excess_space, character)
963
964 def append(
965 self, text: Union["Text", str], style: Optional[Union[str, "Style"]] = None

Callers 5

test_align_leftFunction · 0.95
test_align_rightFunction · 0.95
test_align_centerFunction · 0.95
time_align_centerMethod · 0.80

Calls 4

truncateMethod · 0.95
pad_rightMethod · 0.95
pad_leftMethod · 0.95
cell_lenFunction · 0.85

Tested by 3

test_align_leftFunction · 0.76
test_align_rightFunction · 0.76
test_align_centerFunction · 0.76