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

Method stylize_before

rich/text.py:483–507  ·  view source on GitHub ↗

Apply a style to the text, or a portion of the text. Styles will be applied before other styles already present. Args: style (Union[str, Style]): Style instance or style definition to apply. start (int): Start offset (negative indexing is supported). Defaults to 0.

(
        self,
        style: Union[str, Style],
        start: int = 0,
        end: Optional[int] = None,
    )

Source from the content-addressed store, hash-verified

481 self._spans.append(Span(start, min(length, end), style))
482
483 def stylize_before(
484 self,
485 style: Union[str, Style],
486 start: int = 0,
487 end: Optional[int] = None,
488 ) -> None:
489 """Apply a style to the text, or a portion of the text. Styles will be applied before other styles already present.
490
491 Args:
492 style (Union[str, Style]): Style instance or style definition to apply.
493 start (int): Start offset (negative indexing is supported). Defaults to 0.
494 end (Optional[int], optional): End offset (negative indexing is supported), or None for end of text. Defaults to None.
495 """
496 if style:
497 length = len(self)
498 if start < 0:
499 start = length + start
500 if end is None:
501 end = length
502 if end < 0:
503 end = length + end
504 if start >= length or end <= start:
505 # Span not in text or not valid
506 return
507 self._spans.insert(0, Span(start, min(length, end), style))
508
509 def apply_meta(
510 self, meta: Dict[str, Any], start: int = 0, end: Optional[int] = None

Callers 3

test_stylize_beforeFunction · 0.95
__rich_console__Method · 0.80

Calls 1

SpanClass · 0.85

Tested by 1

test_stylize_beforeFunction · 0.76