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 = " ")
| 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 |