Method: rich.text.Text.truncate
Calls: 2868, Exceptions: 0, Paths: 5Back
Path 1: 2400 calls (0.84)
60 (620) 3 (153) 4 (149) 20 (130) 100 (91) 80 (90) 96 (83) 1 (78) 8 (77) 46 (76)
'fold' (1301) 'ellipsis' (1031) None (45) 'crop' (23)
False (2139) True (261)
1def truncate(
2 self,
3 max_width: int,
4 *,
5 overflow: Optional["OverflowMethod"] = None,
6 pad: bool = False,
7 ) -> None:
8 """Truncate text if it is longer that a given width.
9
10 Args:
11 max_width (int): Maximum number of characters in text.
12 overflow (str, optional): Overflow method: "crop", "fold", or "ellipsis". Defaults to None, to use self.overflow.
13 pad (bool, optional): Pad with spaces if the length is less than max_width. Defaults to False.
14 """
15 _overflow = overflow or self.overflow or DEFAULT_OVERFLOW
16 if _overflow != "ignore":
17 length = cell_len(self.plain)
18 if length > max_width:
19 if _overflow == "ellipsis":
20 self.plain = set_cell_size(self.plain, max_width - 1) + "…"
21 else:
22 self.plain = set_cell_size(self.plain, max_width)
23 if pad and length < max_width:
24 spaces = max_width - length
25 self._text = [f"{self.plain}{' ' * spaces}"]
26 self._length = len(self.plain)
Path 2: 350 calls (0.12)
88 (52) 60 (42) 20 (34) 100 (26) 8 (22) 27 (19) 25 (15) 97 (14) 91 (13) 41 (12)
'fold' (176) 'ellipsis' (174)
True (350)
1def truncate(
2 self,
3 max_width: int,
4 *,
5 overflow: Optional["OverflowMethod"] = None,
6 pad: bool = False,
7 ) -> None:
8 """Truncate text if it is longer that a given width.
9
10 Args:
11 max_width (int): Maximum number of characters in text.
12 overflow (str, optional): Overflow method: "crop", "fold", or "ellipsis". Defaults to None, to use self.overflow.
13 pad (bool, optional): Pad with spaces if the length is less than max_width. Defaults to False.
14 """
15 _overflow = overflow or self.overflow or DEFAULT_OVERFLOW
16 if _overflow != "ignore":
17 length = cell_len(self.plain)
18 if length > max_width:
19 if _overflow == "ellipsis":
20 self.plain = set_cell_size(self.plain, max_width - 1) + "…"
21 else:
22 self.plain = set_cell_size(self.plain, max_width)
23 if pad and length < max_width:
24 spaces = max_width - length
25 self._text = [f"{self.plain}{' ' * spaces}"]
26 self._length = len(self.plain)
Path 3: 52 calls (0.02)
80 (34) 100 (14) 10 (2) 115 (1) 20 (1)
'ignore' (52)
False (52)
1def truncate(
2 self,
3 max_width: int,
4 *,
5 overflow: Optional["OverflowMethod"] = None,
6 pad: bool = False,
7 ) -> None:
8 """Truncate text if it is longer that a given width.
9
10 Args:
11 max_width (int): Maximum number of characters in text.
12 overflow (str, optional): Overflow method: "crop", "fold", or "ellipsis". Defaults to None, to use self.overflow.
13 pad (bool, optional): Pad with spaces if the length is less than max_width. Defaults to False.
14 """
15 _overflow = overflow or self.overflow or DEFAULT_OVERFLOW
16 if _overflow != "ignore":
17 length = cell_len(self.plain)
18 if length > max_width:
19 if _overflow == "ellipsis":
20 self.plain = set_cell_size(self.plain, max_width - 1) + "…"
21 else:
22 self.plain = set_cell_size(self.plain, max_width)
23 if pad and length < max_width:
24 spaces = max_width - length
25 self._text = [f"{self.plain}{' ' * spaces}"]
26 self._length = len(self.plain)
Path 4: 40 calls (0.01)
46 (6) 60 (6) 5 (5) 4 (5) 16 (4) 6 (3) 1 (3) 100 (2) 2 (2) 10 (1)
None (32) 'fold' (6) 'crop' (2)
False (36) True (4)
1def truncate(
2 self,
3 max_width: int,
4 *,
5 overflow: Optional["OverflowMethod"] = None,
6 pad: bool = False,
7 ) -> None:
8 """Truncate text if it is longer that a given width.
9
10 Args:
11 max_width (int): Maximum number of characters in text.
12 overflow (str, optional): Overflow method: "crop", "fold", or "ellipsis". Defaults to None, to use self.overflow.
13 pad (bool, optional): Pad with spaces if the length is less than max_width. Defaults to False.
14 """
15 _overflow = overflow or self.overflow or DEFAULT_OVERFLOW
16 if _overflow != "ignore":
17 length = cell_len(self.plain)
18 if length > max_width:
19 if _overflow == "ellipsis":
20 self.plain = set_cell_size(self.plain, max_width - 1) + "…"
21 else:
22 self.plain = set_cell_size(self.plain, max_width)
23 if pad and length < max_width:
24 spaces = max_width - length
25 self._text = [f"{self.plain}{' ' * spaces}"]
26 self._length = len(self.plain)
Path 5: 26 calls (0.01)
3 (6) 1 (4) 4 (4) 7 (3) 2 (2) 85 (1) 12 (1) 9 (1) 14 (1) 19 (1)
'ellipsis' (26)
False (18) True (8)
1def truncate(
2 self,
3 max_width: int,
4 *,
5 overflow: Optional["OverflowMethod"] = None,
6 pad: bool = False,
7 ) -> None:
8 """Truncate text if it is longer that a given width.
9
10 Args:
11 max_width (int): Maximum number of characters in text.
12 overflow (str, optional): Overflow method: "crop", "fold", or "ellipsis". Defaults to None, to use self.overflow.
13 pad (bool, optional): Pad with spaces if the length is less than max_width. Defaults to False.
14 """
15 _overflow = overflow or self.overflow or DEFAULT_OVERFLOW
16 if _overflow != "ignore":
17 length = cell_len(self.plain)
18 if length > max_width:
19 if _overflow == "ellipsis":
20 self.plain = set_cell_size(self.plain, max_width - 1) + "…"
21 else:
22 self.plain = set_cell_size(self.plain, max_width)
23 if pad and length < max_width:
24 spaces = max_width - length
25 self._text = [f"{self.plain}{' ' * spaces}"]
26 self._length = len(self.plain)