Method: rich.console.Console.render_lines
Calls: 1463, Exceptions: 0, Paths: 5Back
Path 1: 1140 calls (0.78)
Padding (370) Text (240) Group (70) '' (47) Renderables (38) 'foo' (28) ProgressBar (25) Pretty (23) 'Averlongwordgoeshere' (20) 'bar' (17)
ConsoleOptions (1140)
Style (1134) None (6)
True (975) False (165)
False (1137) True (3)
1def render_lines(
2 self,
3 renderable: RenderableType,
4 options: Optional[ConsoleOptions] = None,
5 *,
6 style: Optional[Style] = None,
7 pad: bool = True,
8 new_lines: bool = False,
9 ) -> List[List[Segment]]:
10 """Render objects in to a list of lines.
11
12 The output of render_lines is useful when further formatting of rendered console text
13 is required, such as the Panel class which draws a border around any renderable object.
14
15 Args:
16 renderable (RenderableType): Any object renderable in the console.
17 options (Optional[ConsoleOptions], optional): Console options, or None to use self.options. Default to ``None``.
18 style (Style, optional): Optional style to apply to renderables. Defaults to ``None``.
19 pad (bool, optional): Pad lines shorter than render width. Defaults to ``True``.
20 new_lines (bool, optional): Include "\n" characters at end of lines.
21
22 Returns:
23 List[List[Segment]]: A list of lines, where a line is a list of Segment objects.
24 """
25 with self._lock:
26 render_options = options or self.options
27 _rendered = self.render(renderable, render_options)
28 if style:
29 _rendered = Segment.apply_style(_rendered, style)
30
31 render_height = render_options.height
32 if render_height is not None:
33 render_height = max(0, render_height)
34
35 lines = list(
36 islice(
37 Segment.split_and_crop_lines(
38 _rendered,
39 render_options.max_width,
40 include_new_lines=new_lines,
41 pad=pad,
42 style=style,
43 ),
44 None,
45 render_height,
46 )
47 )
48 if render_options.height is not None:
49 extra_lines = render_options.height - len(lines)
50 if extra_lines > 0:
51 pad_line = [
52 [Segment(" " * render_options.max_width, style), Segment("\n")]
53 if new_lines
54 else [Segment(" " * render_options.max_width, style)]
55 ]
56 lines.extend(pad_line * extra_lines)
57
58 return lines
Path 2: 291 calls (0.2)
Padding (240) Text (29) '' (8) Renderables (2) 'Coffee' (2) 'my string' (1) 'test renderable' (1) Segments (1) 'foo' (1) 'bar' (1)
ConsoleOptions (291)
Style (291)
True (290) False (1)
False (291)
1def render_lines(
2 self,
3 renderable: RenderableType,
4 options: Optional[ConsoleOptions] = None,
5 *,
6 style: Optional[Style] = None,
7 pad: bool = True,
8 new_lines: bool = False,
9 ) -> List[List[Segment]]:
10 """Render objects in to a list of lines.
11
12 The output of render_lines is useful when further formatting of rendered console text
13 is required, such as the Panel class which draws a border around any renderable object.
14
15 Args:
16 renderable (RenderableType): Any object renderable in the console.
17 options (Optional[ConsoleOptions], optional): Console options, or None to use self.options. Default to ``None``.
18 style (Style, optional): Optional style to apply to renderables. Defaults to ``None``.
19 pad (bool, optional): Pad lines shorter than render width. Defaults to ``True``.
20 new_lines (bool, optional): Include "\n" characters at end of lines.
21
22 Returns:
23 List[List[Segment]]: A list of lines, where a line is a list of Segment objects.
24 """
25 with self._lock:
26 render_options = options or self.options
27 _rendered = self.render(renderable, render_options)
28 if style:
29 _rendered = Segment.apply_style(_rendered, style)
30
31 render_height = render_options.height
32 if render_height is not None:
33 render_height = max(0, render_height)
34
35 lines = list(
36 islice(
37 Segment.split_and_crop_lines(
38 _rendered,
39 render_options.max_width,
40 include_new_lines=new_lines,
41 pad=pad,
42 style=style,
43 ),
44 None,
45 render_height,
46 )
47 )
48 if render_options.height is not None:
49 extra_lines = render_options.height - len(lines)
50 if extra_lines > 0:
51 pad_line = [
52 [Segment(" " * render_options.max_width, style), Segment("\n")]
53 if new_lines
54 else [Segment(" " * render_options.max_width, style)]
55 ]
56 lines.extend(pad_line * extra_lines)
57
58 return lines
Path 3: 21 calls (0.01)
Padding (8) _Placeholder (4) Align (4) Panel (2) 'hello' (1) Layout (1) Group (1)
ConsoleOptions (21)
Style (12) None (9)
True (21)
False (21)
1def render_lines(
2 self,
3 renderable: RenderableType,
4 options: Optional[ConsoleOptions] = None,
5 *,
6 style: Optional[Style] = None,
7 pad: bool = True,
8 new_lines: bool = False,
9 ) -> List[List[Segment]]:
10 """Render objects in to a list of lines.
11
12 The output of render_lines is useful when further formatting of rendered console text
13 is required, such as the Panel class which draws a border around any renderable object.
14
15 Args:
16 renderable (RenderableType): Any object renderable in the console.
17 options (Optional[ConsoleOptions], optional): Console options, or None to use self.options. Default to ``None``.
18 style (Style, optional): Optional style to apply to renderables. Defaults to ``None``.
19 pad (bool, optional): Pad lines shorter than render width. Defaults to ``True``.
20 new_lines (bool, optional): Include "\n" characters at end of lines.
21
22 Returns:
23 List[List[Segment]]: A list of lines, where a line is a list of Segment objects.
24 """
25 with self._lock:
26 render_options = options or self.options
27 _rendered = self.render(renderable, render_options)
28 if style:
29 _rendered = Segment.apply_style(_rendered, style)
30
31 render_height = render_options.height
32 if render_height is not None:
33 render_height = max(0, render_height)
34
35 lines = list(
36 islice(
37 Segment.split_and_crop_lines(
38 _rendered,
39 render_options.max_width,
40 include_new_lines=new_lines,
41 pad=pad,
42 style=style,
43 ),
44 None,
45 render_height,
46 )
47 )
48 if render_options.height is not None:
49 extra_lines = render_options.height - len(lines)
50 if extra_lines > 0:
51 pad_line = [
52 [Segment(" " * render_options.max_width, style), Segment("\n")]
53 if new_lines
54 else [Segment(" " * render_options.max_width, style)]
55 ]
56 lines.extend(pad_line * extra_lines)
57
58 return lines
Path 4: 8 calls (0.01)
'foo' (3) Group (2) 'bar' (1) test_reset_height.
ConsoleOptions (8)
None (5) Style (3)
True (8)
False (8)
1def render_lines(
2 self,
3 renderable: RenderableType,
4 options: Optional[ConsoleOptions] = None,
5 *,
6 style: Optional[Style] = None,
7 pad: bool = True,
8 new_lines: bool = False,
9 ) -> List[List[Segment]]:
10 """Render objects in to a list of lines.
11
12 The output of render_lines is useful when further formatting of rendered console text
13 is required, such as the Panel class which draws a border around any renderable object.
14
15 Args:
16 renderable (RenderableType): Any object renderable in the console.
17 options (Optional[ConsoleOptions], optional): Console options, or None to use self.options. Default to ``None``.
18 style (Style, optional): Optional style to apply to renderables. Defaults to ``None``.
19 pad (bool, optional): Pad lines shorter than render width. Defaults to ``True``.
20 new_lines (bool, optional): Include "\n" characters at end of lines.
21
22 Returns:
23 List[List[Segment]]: A list of lines, where a line is a list of Segment objects.
24 """
25 with self._lock:
26 render_options = options or self.options
27 _rendered = self.render(renderable, render_options)
28 if style:
29 _rendered = Segment.apply_style(_rendered, style)
30
31 render_height = render_options.height
32 if render_height is not None:
33 render_height = max(0, render_height)
34
35 lines = list(
36 islice(
37 Segment.split_and_crop_lines(
38 _rendered,
39 render_options.max_width,
40 include_new_lines=new_lines,
41 pad=pad,
42 style=style,
43 ),
44 None,
45 render_height,
46 )
47 )
48 if render_options.height is not None:
49 extra_lines = render_options.height - len(lines)
50 if extra_lines > 0:
51 pad_line = [
52 [Segment(" " * render_options.max_width, style), Segment("\n")]
53 if new_lines
54 else [Segment(" " * render_options.max_width, style)]
55 ]
56 lines.extend(pad_line * extra_lines)
57
58 return lines
Path 5: 3 calls (0.0)
'bar' (2) 'foo' (1)
ConsoleOptions (3)
Style (3)
True (3)
False (3)
1def render_lines(
2 self,
3 renderable: RenderableType,
4 options: Optional[ConsoleOptions] = None,
5 *,
6 style: Optional[Style] = None,
7 pad: bool = True,
8 new_lines: bool = False,
9 ) -> List[List[Segment]]:
10 """Render objects in to a list of lines.
11
12 The output of render_lines is useful when further formatting of rendered console text
13 is required, such as the Panel class which draws a border around any renderable object.
14
15 Args:
16 renderable (RenderableType): Any object renderable in the console.
17 options (Optional[ConsoleOptions], optional): Console options, or None to use self.options. Default to ``None``.
18 style (Style, optional): Optional style to apply to renderables. Defaults to ``None``.
19 pad (bool, optional): Pad lines shorter than render width. Defaults to ``True``.
20 new_lines (bool, optional): Include "\n" characters at end of lines.
21
22 Returns:
23 List[List[Segment]]: A list of lines, where a line is a list of Segment objects.
24 """
25 with self._lock:
26 render_options = options or self.options
27 _rendered = self.render(renderable, render_options)
28 if style:
29 _rendered = Segment.apply_style(_rendered, style)
30
31 render_height = render_options.height
32 if render_height is not None:
33 render_height = max(0, render_height)
34
35 lines = list(
36 islice(
37 Segment.split_and_crop_lines(
38 _rendered,
39 render_options.max_width,
40 include_new_lines=new_lines,
41 pad=pad,
42 style=style,
43 ),
44 None,
45 render_height,
46 )
47 )
48 if render_options.height is not None:
49 extra_lines = render_options.height - len(lines)
50 if extra_lines > 0:
51 pad_line = [
52 [Segment(" " * render_options.max_width, style), Segment("\n")]
53 if new_lines
54 else [Segment(" " * render_options.max_width, style)]
55 ]
56 lines.extend(pad_line * extra_lines)
57
58 return lines