MCPcopy
hub / github.com/Textualize/rich / get_style_at_offset

Method get_style_at_offset

rich/text.py:552–570  ·  view source on GitHub ↗

Get the style of a character at give offset. Args: console (~Console): Console where text will be rendered. offset (int): Offset in to text (negative indexing supported) Returns: Style: A Style instance.

(self, console: "Console", offset: int)

Source from the content-addressed store, hash-verified

550 self.right_crop(len(suffix))
551
552 def get_style_at_offset(self, console: "Console", offset: int) -> Style:
553 """Get the style of a character at give offset.
554
555 Args:
556 console (~Console): Console where text will be rendered.
557 offset (int): Offset in to text (negative indexing supported)
558
559 Returns:
560 Style: A Style instance.
561 """
562 # TODO: This is a little inefficient, it is only used by full justify
563 if offset < 0:
564 offset = len(self) + offset
565 get_style = console.get_style
566 style = get_style(self.style).copy()
567 for start, end, span_style in self._spans:
568 if end > offset >= start:
569 style += get_style(span_style, default="")
570 return style
571
572 def extend_style(self, spaces: int) -> None:
573 """Extend the Text given number of spaces where the spaces have the same style as the last character.

Callers 6

test_apply_metaFunction · 0.95
test_onFunction · 0.95
test_render_metaFunction · 0.80
test_assemble_metaFunction · 0.80
test_get_style_at_offsetFunction · 0.80
justifyMethod · 0.80

Calls 2

get_styleFunction · 0.85
copyMethod · 0.45

Tested by 5

test_apply_metaFunction · 0.76
test_onFunction · 0.76
test_render_metaFunction · 0.64
test_assemble_metaFunction · 0.64
test_get_style_at_offsetFunction · 0.64