Method: rich.text.Text.render
Calls: 1263, Exceptions: 1, Paths: 5Back
Path 1: 611 calls (0.48)
Console (611)
'\n' (611)
Segment (4320) None (611)
1def render(self, console: "Console", end: str = "") -> Iterable["Segment"]:
2 """Render the text as Segments.
3
4 Args:
5 console (Console): Console instance.
6 end (Optional[str], optional): Optional end character.
7
8 Returns:
9 Iterable[Segment]: Result of render that may be written to the console.
10 """
11 _Segment = Segment
12 text = self.plain
13 if not self._spans:
14 yield Segment(text)
15 if end:
16 yield _Segment(end)
17 return
18 get_style = partial(console.get_style, default=Style.null())
19
20 enumerated_spans = list(enumerate(self._spans, 1))
21 style_map = {index: get_style(span.style) for index, span in enumerated_spans}
22 style_map[0] = get_style(self.style)
23
24 spans = [
25 (0, False, 0),
26 *((span.start, False, index) for index, span in enumerated_spans),
27 *((span.end, True, index) for index, span in enumerated_spans),
28 (len(text), True, 0),
29 ]
30 spans.sort(key=itemgetter(0, 1))
31
32 stack: List[int] = []
33 stack_append = stack.append
34 stack_pop = stack.remove
35
36 style_cache: Dict[Tuple[Style, ...], Style] = {}
37 style_cache_get = style_cache.get
38 combine = Style.combine
39
40 def get_current_style() -> Style:
41 """Construct current style from stack."""
42 styles = tuple(style_map[_style_id] for _style_id in sorted(stack))
43 cached_style = style_cache_get(styles)
44 if cached_style is not None:
45 return cached_style
46 current_style = combine(styles)
47 style_cache[styles] = current_style
48 return current_style
49
50 for (offset, leaving, style_id), (next_offset, _, _) in zip(spans, spans[1:]):
51 if leaving:
52 stack_pop(style_id)
53 else:
54 stack_append(style_id)
55 if next_offset > offset:
56 yield _Segment(text[offset:next_offset], get_current_style())
57 if end:
58 yield _Segment(end)
Path 2: 439 calls (0.35)
Console (439)
'\n' (434) 'X' (4) ' ' (1)
Segment (878)
None (439)
1def render(self, console: "Console", end: str = "") -> Iterable["Segment"]:
2 """Render the text as Segments.
3
4 Args:
5 console (Console): Console instance.
6 end (Optional[str], optional): Optional end character.
7
8 Returns:
9 Iterable[Segment]: Result of render that may be written to the console.
10 """
11 _Segment = Segment
12 text = self.plain
13 if not self._spans:
14 yield Segment(text)
15 if end:
16 yield _Segment(end)
17 return
18 get_style = partial(console.get_style, default=Style.null())
19
20 enumerated_spans = list(enumerate(self._spans, 1))
21 style_map = {index: get_style(span.style) for index, span in enumerated_spans}
22 style_map[0] = get_style(self.style)
23
24 spans = [
25 (0, False, 0),
26 *((span.start, False, index) for index, span in enumerated_spans),
27 *((span.end, True, index) for index, span in enumerated_spans),
28 (len(text), True, 0),
29 ]
30 spans.sort(key=itemgetter(0, 1))
31
32 stack: List[int] = []
33 stack_append = stack.append
34 stack_pop = stack.remove
35
36 style_cache: Dict[Tuple[Style, ...], Style] = {}
37 style_cache_get = style_cache.get
38 combine = Style.combine
39
40 def get_current_style() -> Style:
41 """Construct current style from stack."""
42 styles = tuple(style_map[_style_id] for _style_id in sorted(stack))
43 cached_style = style_cache_get(styles)
44 if cached_style is not None:
45 return cached_style
46 current_style = combine(styles)
47 style_cache[styles] = current_style
48 return current_style
49
50 for (offset, leaving, style_id), (next_offset, _, _) in zip(spans, spans[1:]):
51 if leaving:
52 stack_pop(style_id)
53 else:
54 stack_append(style_id)
55 if next_offset > offset:
56 yield _Segment(text[offset:next_offset], get_current_style())
57 if end:
58 yield _Segment(end)
Path 3: 205 calls (0.16)
Console (205)
'' (205)
Segment (1340)
1def render(self, console: "Console", end: str = "") -> Iterable["Segment"]:
2 """Render the text as Segments.
3
4 Args:
5 console (Console): Console instance.
6 end (Optional[str], optional): Optional end character.
7
8 Returns:
9 Iterable[Segment]: Result of render that may be written to the console.
10 """
11 _Segment = Segment
12 text = self.plain
13 if not self._spans:
14 yield Segment(text)
15 if end:
16 yield _Segment(end)
17 return
18 get_style = partial(console.get_style, default=Style.null())
19
20 enumerated_spans = list(enumerate(self._spans, 1))
21 style_map = {index: get_style(span.style) for index, span in enumerated_spans}
22 style_map[0] = get_style(self.style)
23
24 spans = [
25 (0, False, 0),
26 *((span.start, False, index) for index, span in enumerated_spans),
27 *((span.end, True, index) for index, span in enumerated_spans),
28 (len(text), True, 0),
29 ]
30 spans.sort(key=itemgetter(0, 1))
31
32 stack: List[int] = []
33 stack_append = stack.append
34 stack_pop = stack.remove
35
36 style_cache: Dict[Tuple[Style, ...], Style] = {}
37 style_cache_get = style_cache.get
38 combine = Style.combine
39
40 def get_current_style() -> Style:
41 """Construct current style from stack."""
42 styles = tuple(style_map[_style_id] for _style_id in sorted(stack))
43 cached_style = style_cache_get(styles)
44 if cached_style is not None:
45 return cached_style
46 current_style = combine(styles)
47 style_cache[styles] = current_style
48 return current_style
49
50 for (offset, leaving, style_id), (next_offset, _, _) in zip(spans, spans[1:]):
51 if leaving:
52 stack_pop(style_id)
53 else:
54 stack_append(style_id)
55 if next_offset > offset:
56 yield _Segment(text[offset:next_offset], get_current_style())
57 if end:
58 yield _Segment(end)
Path 4: 7 calls (0.01)
Console (7)
'' (7)
Segment (7)
None (7)
1def render(self, console: "Console", end: str = "") -> Iterable["Segment"]:
2 """Render the text as Segments.
3
4 Args:
5 console (Console): Console instance.
6 end (Optional[str], optional): Optional end character.
7
8 Returns:
9 Iterable[Segment]: Result of render that may be written to the console.
10 """
11 _Segment = Segment
12 text = self.plain
13 if not self._spans:
14 yield Segment(text)
15 if end:
16 yield _Segment(end)
17 return
18 get_style = partial(console.get_style, default=Style.null())
19
20 enumerated_spans = list(enumerate(self._spans, 1))
21 style_map = {index: get_style(span.style) for index, span in enumerated_spans}
22 style_map[0] = get_style(self.style)
23
24 spans = [
25 (0, False, 0),
26 *((span.start, False, index) for index, span in enumerated_spans),
27 *((span.end, True, index) for index, span in enumerated_spans),
28 (len(text), True, 0),
29 ]
30 spans.sort(key=itemgetter(0, 1))
31
32 stack: List[int] = []
33 stack_append = stack.append
34 stack_pop = stack.remove
35
36 style_cache: Dict[Tuple[Style, ...], Style] = {}
37 style_cache_get = style_cache.get
38 combine = Style.combine
39
40 def get_current_style() -> Style:
41 """Construct current style from stack."""
42 styles = tuple(style_map[_style_id] for _style_id in sorted(stack))
43 cached_style = style_cache_get(styles)
44 if cached_style is not None:
45 return cached_style
46 current_style = combine(styles)
47 style_cache[styles] = current_style
48 return current_style
49
50 for (offset, leaving, style_id), (next_offset, _, _) in zip(spans, spans[1:]):
51 if leaving:
52 stack_pop(style_id)
53 else:
54 stack_append(style_id)
55 if next_offset > offset:
56 yield _Segment(text[offset:next_offset], get_current_style())
57 if end:
58 yield _Segment(end)
Path 5: 1 calls (0.0)
Console (1)
'\n' (1)
Segment (1) None (1)
GeneratorExit (1)
1def render(self, console: "Console", end: str = "") -> Iterable["Segment"]:
2 """Render the text as Segments.
3
4 Args:
5 console (Console): Console instance.
6 end (Optional[str], optional): Optional end character.
7
8 Returns:
9 Iterable[Segment]: Result of render that may be written to the console.
10 """
11 _Segment = Segment
12 text = self.plain
13 if not self._spans:
14 yield Segment(text)
15 if end:
16 yield _Segment(end)
17 return
18 get_style = partial(console.get_style, default=Style.null())
19
20 enumerated_spans = list(enumerate(self._spans, 1))
21 style_map = {index: get_style(span.style) for index, span in enumerated_spans}
22 style_map[0] = get_style(self.style)
23
24 spans = [
25 (0, False, 0),
26 *((span.start, False, index) for index, span in enumerated_spans),
27 *((span.end, True, index) for index, span in enumerated_spans),
28 (len(text), True, 0),
29 ]
30 spans.sort(key=itemgetter(0, 1))
31
32 stack: List[int] = []
33 stack_append = stack.append
34 stack_pop = stack.remove
35
36 style_cache: Dict[Tuple[Style, ...], Style] = {}
37 style_cache_get = style_cache.get
38 combine = Style.combine
39
40 def get_current_style() -> Style:
41 """Construct current style from stack."""
42 styles = tuple(style_map[_style_id] for _style_id in sorted(stack))
43 cached_style = style_cache_get(styles)
44 if cached_style is not None:
45 return cached_style
46 current_style = combine(styles)
47 style_cache[styles] = current_style
48 return current_style
49
50 for (offset, leaving, style_id), (next_offset, _, _) in zip(spans, spans[1:]):
51 if leaving:
52 stack_pop(style_id)
53 else:
54 stack_append(style_id)
55 if next_offset > offset:
56 yield _Segment(text[offset:next_offset], get_current_style())
57 if end:
58 yield _Segment(end)