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

Method on

rich/text.py:523–541  ·  view source on GitHub ↗

Apply event handlers (used by Textual project). Example: >>> from rich.text import Text >>> text = Text("hello world") >>> text.on(click="view.toggle('world')") Args: meta (Dict[str, Any]): Mapping of meta information. **h

(self, meta: Optional[Dict[str, Any]] = None, **handlers: Any)

Source from the content-addressed store, hash-verified

521 self.stylize(style, start=start, end=end)
522
523 def on(self, meta: Optional[Dict[str, Any]] = None, **handlers: Any) -> "Text":
524 """Apply event handlers (used by Textual project).
525
526 Example:
527 >>> from rich.text import Text
528 >>> text = Text("hello world")
529 >>> text.on(click="view.toggle('world')")
530
531 Args:
532 meta (Dict[str, Any]): Mapping of meta information.
533 **handlers: Keyword args are prefixed with "@" to defined handlers.
534
535 Returns:
536 Text: Self is returned to method may be chained.
537 """
538 meta = {} if meta is None else meta
539 meta.update({f"@{key}": value for key, value in handlers.items()})
540 self.stylize(Style.from_meta(meta))
541 return self
542
543 def remove_suffix(self, suffix: str) -> None:
544 """Remove a suffix if it exists.

Callers 4

test_onFunction · 0.95
test_onFunction · 0.45

Calls 3

stylizeMethod · 0.95
from_metaMethod · 0.80
updateMethod · 0.45

Tested by 4

test_onFunction · 0.76
test_onFunction · 0.36