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)
| 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. |