Method: rich.containers.Lines.justify
Calls: 1763, Exceptions: 0, Paths: 6Back
Path 1: 968 calls (0.55)
Console (968)
60 (559) 80 (123) 100 (55) 96 (50) 46 (49) 20 (22) 3 (19) 6 (13) 16 (13) 30 (12)
'default' (968)
'fold' (901) 'ignore' (52) 'crop' (13) 'ellipsis' (2)
1def justify(
2 self,
3 console: "Console",
4 width: int,
5 justify: "JustifyMethod" = "left",
6 overflow: "OverflowMethod" = "fold",
7 ) -> None:
8 """Justify and overflow text to a given width.
9
10 Args:
11 console (Console): Console instance.
12 width (int): Number of characters per line.
13 justify (str, optional): Default justify method for text: "left", "center", "full" or "right". Defaults to "left".
14 overflow (str, optional): Default overflow for text: "crop", "fold", or "ellipsis". Defaults to "fold".
15
16 """
17 from .text import Text
18
19 if justify == "left":
20 for line in self._lines:
21 line.truncate(width, overflow=overflow, pad=True)
22 elif justify == "center":
23 for line in self._lines:
24 line.rstrip()
25 line.truncate(width, overflow=overflow)
26 line.pad_left((width - cell_len(line.plain)) // 2)
27 line.pad_right(width - cell_len(line.plain))
28 elif justify == "right":
29 for line in self._lines:
30 line.rstrip()
31 line.truncate(width, overflow=overflow)
32 line.pad_left(width - cell_len(line.plain))
33 elif justify == "full":
34 for line_index, line in enumerate(self._lines):
35 if line_index == len(self._lines) - 1:
36 break
37 words = line.split(" ")
38 words_size = sum(cell_len(word.plain) for word in words)
39 num_spaces = len(words) - 1
40 spaces = [1 for _ in range(num_spaces)]
41 index = 0
42 if spaces:
43 while words_size + num_spaces < width:
44 spaces[len(spaces) - index - 1] += 1
45 num_spaces += 1
46 index = (index + 1) % len(spaces)
47 tokens: List[Text] = []
48 for index, (word, next_word) in enumerate(
49 zip_longest(words, words[1:])
50 ):
51 tokens.append(word)
52 if index < len(spaces):
53 style = word.get_style_at_offset(console, -1)
54 next_style = next_word.get_style_at_offset(console, 0)
55 space_style = style if style == next_style else line.style
56 tokens.append(Text(" " * spaces[index], style=space_style))
57 self[line_index] = Text("").join(tokens)
Path 2: 572 calls (0.32)
Console (572)
4 (63) 88 (52) 8 (45) 60 (44) 20 (39) 1 (39) 19 (29) 100 (26) 7 (23) 3 (20)
'left' (572)
'ellipsis' (393) 'fold' (179)
1def justify(
2 self,
3 console: "Console",
4 width: int,
5 justify: "JustifyMethod" = "left",
6 overflow: "OverflowMethod" = "fold",
7 ) -> None:
8 """Justify and overflow text to a given width.
9
10 Args:
11 console (Console): Console instance.
12 width (int): Number of characters per line.
13 justify (str, optional): Default justify method for text: "left", "center", "full" or "right". Defaults to "left".
14 overflow (str, optional): Default overflow for text: "crop", "fold", or "ellipsis". Defaults to "fold".
15
16 """
17 from .text import Text
18
19 if justify == "left":
20 for line in self._lines:
21 line.truncate(width, overflow=overflow, pad=True)
22 elif justify == "center":
23 for line in self._lines:
24 line.rstrip()
25 line.truncate(width, overflow=overflow)
26 line.pad_left((width - cell_len(line.plain)) // 2)
27 line.pad_right(width - cell_len(line.plain))
28 elif justify == "right":
29 for line in self._lines:
30 line.rstrip()
31 line.truncate(width, overflow=overflow)
32 line.pad_left(width - cell_len(line.plain))
33 elif justify == "full":
34 for line_index, line in enumerate(self._lines):
35 if line_index == len(self._lines) - 1:
36 break
37 words = line.split(" ")
38 words_size = sum(cell_len(word.plain) for word in words)
39 num_spaces = len(words) - 1
40 spaces = [1 for _ in range(num_spaces)]
41 index = 0
42 if spaces:
43 while words_size + num_spaces < width:
44 spaces[len(spaces) - index - 1] += 1
45 num_spaces += 1
46 index = (index + 1) % len(spaces)
47 tokens: List[Text] = []
48 for index, (word, next_word) in enumerate(
49 zip_longest(words, words[1:])
50 ):
51 tokens.append(word)
52 if index < len(spaces):
53 style = word.get_style_at_offset(console, -1)
54 next_style = next_word.get_style_at_offset(console, 0)
55 space_style = style if style == next_style else line.style
56 tokens.append(Text(" " * spaces[index], style=space_style))
57 self[line_index] = Text("").join(tokens)
Path 3: 130 calls (0.07)
Console (130)
15 (31) 12 (17) 100 (11) 60 (8) 7 (7) 48 (6) 59 (6) 20 (5) 19 (5) 3 (4)
'center' (130)
'ellipsis' (66) 'fold' (58) 'crop' (6)
1def justify(
2 self,
3 console: "Console",
4 width: int,
5 justify: "JustifyMethod" = "left",
6 overflow: "OverflowMethod" = "fold",
7 ) -> None:
8 """Justify and overflow text to a given width.
9
10 Args:
11 console (Console): Console instance.
12 width (int): Number of characters per line.
13 justify (str, optional): Default justify method for text: "left", "center", "full" or "right". Defaults to "left".
14 overflow (str, optional): Default overflow for text: "crop", "fold", or "ellipsis". Defaults to "fold".
15
16 """
17 from .text import Text
18
19 if justify == "left":
20 for line in self._lines:
21 line.truncate(width, overflow=overflow, pad=True)
22 elif justify == "center":
23 for line in self._lines:
24 line.rstrip()
25 line.truncate(width, overflow=overflow)
26 line.pad_left((width - cell_len(line.plain)) // 2)
27 line.pad_right(width - cell_len(line.plain))
28 elif justify == "right":
29 for line in self._lines:
30 line.rstrip()
31 line.truncate(width, overflow=overflow)
32 line.pad_left(width - cell_len(line.plain))
33 elif justify == "full":
34 for line_index, line in enumerate(self._lines):
35 if line_index == len(self._lines) - 1:
36 break
37 words = line.split(" ")
38 words_size = sum(cell_len(word.plain) for word in words)
39 num_spaces = len(words) - 1
40 spaces = [1 for _ in range(num_spaces)]
41 index = 0
42 if spaces:
43 while words_size + num_spaces < width:
44 spaces[len(spaces) - index - 1] += 1
45 num_spaces += 1
46 index = (index + 1) % len(spaces)
47 tokens: List[Text] = []
48 for index, (word, next_word) in enumerate(
49 zip_longest(words, words[1:])
50 ):
51 tokens.append(word)
52 if index < len(spaces):
53 style = word.get_style_at_offset(console, -1)
54 next_style = next_word.get_style_at_offset(console, 0)
55 space_style = style if style == next_style else line.style
56 tokens.append(Text(" " * spaces[index], style=space_style))
57 self[line_index] = Text("").join(tokens)
Path 4: 90 calls (0.05)
Console (90)
3 (40) 18 (10) 13 (8) 17 (5) 14 (5) 7 (5) 4 (5) 10 (4) 11 (2) 9 (2)
'right' (90)
'ellipsis' (86) 'fold' (4)
1def justify(
2 self,
3 console: "Console",
4 width: int,
5 justify: "JustifyMethod" = "left",
6 overflow: "OverflowMethod" = "fold",
7 ) -> None:
8 """Justify and overflow text to a given width.
9
10 Args:
11 console (Console): Console instance.
12 width (int): Number of characters per line.
13 justify (str, optional): Default justify method for text: "left", "center", "full" or "right". Defaults to "left".
14 overflow (str, optional): Default overflow for text: "crop", "fold", or "ellipsis". Defaults to "fold".
15
16 """
17 from .text import Text
18
19 if justify == "left":
20 for line in self._lines:
21 line.truncate(width, overflow=overflow, pad=True)
22 elif justify == "center":
23 for line in self._lines:
24 line.rstrip()
25 line.truncate(width, overflow=overflow)
26 line.pad_left((width - cell_len(line.plain)) // 2)
27 line.pad_right(width - cell_len(line.plain))
28 elif justify == "right":
29 for line in self._lines:
30 line.rstrip()
31 line.truncate(width, overflow=overflow)
32 line.pad_left(width - cell_len(line.plain))
33 elif justify == "full":
34 for line_index, line in enumerate(self._lines):
35 if line_index == len(self._lines) - 1:
36 break
37 words = line.split(" ")
38 words_size = sum(cell_len(word.plain) for word in words)
39 num_spaces = len(words) - 1
40 spaces = [1 for _ in range(num_spaces)]
41 index = 0
42 if spaces:
43 while words_size + num_spaces < width:
44 spaces[len(spaces) - index - 1] += 1
45 num_spaces += 1
46 index = (index + 1) % len(spaces)
47 tokens: List[Text] = []
48 for index, (word, next_word) in enumerate(
49 zip_longest(words, words[1:])
50 ):
51 tokens.append(word)
52 if index < len(spaces):
53 style = word.get_style_at_offset(console, -1)
54 next_style = next_word.get_style_at_offset(console, 0)
55 space_style = style if style == next_style else line.style
56 tokens.append(Text(" " * spaces[index], style=space_style))
57 self[line_index] = Text("").join(tokens)
Path 5: 2 calls (0.0)
Console (2)
7 (1) 100 (1)
'full' (2)
'fold' (2)
1def justify(
2 self,
3 console: "Console",
4 width: int,
5 justify: "JustifyMethod" = "left",
6 overflow: "OverflowMethod" = "fold",
7 ) -> None:
8 """Justify and overflow text to a given width.
9
10 Args:
11 console (Console): Console instance.
12 width (int): Number of characters per line.
13 justify (str, optional): Default justify method for text: "left", "center", "full" or "right". Defaults to "left".
14 overflow (str, optional): Default overflow for text: "crop", "fold", or "ellipsis". Defaults to "fold".
15
16 """
17 from .text import Text
18
19 if justify == "left":
20 for line in self._lines:
21 line.truncate(width, overflow=overflow, pad=True)
22 elif justify == "center":
23 for line in self._lines:
24 line.rstrip()
25 line.truncate(width, overflow=overflow)
26 line.pad_left((width - cell_len(line.plain)) // 2)
27 line.pad_right(width - cell_len(line.plain))
28 elif justify == "right":
29 for line in self._lines:
30 line.rstrip()
31 line.truncate(width, overflow=overflow)
32 line.pad_left(width - cell_len(line.plain))
33 elif justify == "full":
34 for line_index, line in enumerate(self._lines):
35 if line_index == len(self._lines) - 1:
36 break
37 words = line.split(" ")
38 words_size = sum(cell_len(word.plain) for word in words)
39 num_spaces = len(words) - 1
40 spaces = [1 for _ in range(num_spaces)]
41 index = 0
42 if spaces:
43 while words_size + num_spaces < width:
44 spaces[len(spaces) - index - 1] += 1
45 num_spaces += 1
46 index = (index + 1) % len(spaces)
47 tokens: List[Text] = []
48 for index, (word, next_word) in enumerate(
49 zip_longest(words, words[1:])
50 ):
51 tokens.append(word)
52 if index < len(spaces):
53 style = word.get_style_at_offset(console, -1)
54 next_style = next_word.get_style_at_offset(console, 0)
55 space_style = style if style == next_style else line.style
56 tokens.append(Text(" " * spaces[index], style=space_style))
57 self[line_index] = Text("").join(tokens)
Path 6: 1 calls (0.0)
Console (1)
22 (1)
'full' (1)
'ellipsis' (1)
1def justify(
2 self,
3 console: "Console",
4 width: int,
5 justify: "JustifyMethod" = "left",
6 overflow: "OverflowMethod" = "fold",
7 ) -> None:
8 """Justify and overflow text to a given width.
9
10 Args:
11 console (Console): Console instance.
12 width (int): Number of characters per line.
13 justify (str, optional): Default justify method for text: "left", "center", "full" or "right". Defaults to "left".
14 overflow (str, optional): Default overflow for text: "crop", "fold", or "ellipsis". Defaults to "fold".
15
16 """
17 from .text import Text
18
19 if justify == "left":
20 for line in self._lines:
21 line.truncate(width, overflow=overflow, pad=True)
22 elif justify == "center":
23 for line in self._lines:
24 line.rstrip()
25 line.truncate(width, overflow=overflow)
26 line.pad_left((width - cell_len(line.plain)) // 2)
27 line.pad_right(width - cell_len(line.plain))
28 elif justify == "right":
29 for line in self._lines:
30 line.rstrip()
31 line.truncate(width, overflow=overflow)
32 line.pad_left(width - cell_len(line.plain))
33 elif justify == "full":
34 for line_index, line in enumerate(self._lines):
35 if line_index == len(self._lines) - 1:
36 break
37 words = line.split(" ")
38 words_size = sum(cell_len(word.plain) for word in words)
39 num_spaces = len(words) - 1
40 spaces = [1 for _ in range(num_spaces)]
41 index = 0
42 if spaces:
43 while words_size + num_spaces < width:
44 spaces[len(spaces) - index - 1] += 1
45 num_spaces += 1
46 index = (index + 1) % len(spaces)
47 tokens: List[Text] = []
48 for index, (word, next_word) in enumerate(
49 zip_longest(words, words[1:])
50 ):
51 tokens.append(word)
52 if index < len(spaces):
53 style = word.get_style_at_offset(console, -1)
54 next_style = next_word.get_style_at_offset(console, 0)
55 space_style = style if style == next_style else line.style
56 tokens.append(Text(" " * spaces[index], style=space_style))
57 self[line_index] = Text("").join(tokens)