Widget displaying an app message.
| 3138 | |
| 3139 | |
| 3140 | class AppMessage(Static): |
| 3141 | """Widget displaying an app message.""" |
| 3142 | |
| 3143 | # Disable Textual's auto_links to prevent a flicker cycle: Style.__add__ |
| 3144 | # calls .copy() for linked styles, generating a fresh random _link_id on |
| 3145 | # each render. This means highlight_link_id never stabilizes, causing an |
| 3146 | # infinite hover-refresh loop. |
| 3147 | auto_links = False |
| 3148 | |
| 3149 | DEFAULT_CSS = """ |
| 3150 | AppMessage { |
| 3151 | height: auto; |
| 3152 | padding: 0 1; |
| 3153 | margin: 0 0 1 0; |
| 3154 | color: $text-muted; |
| 3155 | text-style: italic; |
| 3156 | pointer: text; |
| 3157 | } |
| 3158 | """ |
| 3159 | |
| 3160 | def __init__( |
| 3161 | self, |
| 3162 | message: str | Content, |
| 3163 | *, |
| 3164 | markdown: bool = False, |
| 3165 | **kwargs: Any, |
| 3166 | ) -> None: |
| 3167 | """Initialize a system message. |
| 3168 | |
| 3169 | Args: |
| 3170 | message: The system message as a string or pre-styled `Content`. |
| 3171 | markdown: When `True`, render `message` as markdown via Rich's |
| 3172 | markdown renderer (tables, headings, bold, etc.). |
| 3173 | |
| 3174 | Requires a string message — `Content` objects already carry |
| 3175 | their own structure. |
| 3176 | **kwargs: Additional arguments passed to parent. |
| 3177 | |
| 3178 | Raises: |
| 3179 | TypeError: If `markdown=True` is combined with a non-string |
| 3180 | `message`. |
| 3181 | """ |
| 3182 | self._content = message |
| 3183 | self._is_markdown = markdown |
| 3184 | if markdown: |
| 3185 | if not isinstance(message, str): |
| 3186 | msg = "AppMessage(markdown=True) requires a string message" |
| 3187 | raise TypeError(msg) |
| 3188 | rendered = _MutedRichMarkdown(message) |
| 3189 | elif isinstance(message, Content): |
| 3190 | rendered = message |
| 3191 | else: |
| 3192 | rendered = Content.styled(message, "dim italic") |
| 3193 | super().__init__(rendered, **kwargs) |
| 3194 | |
| 3195 | def on_click(self, event: Click) -> None: # noqa: PLR6301 # Textual event handler |
| 3196 | """Open style-embedded hyperlinks on single click.""" |
| 3197 | open_style_link(event) |
no outgoing calls
searching dependent graphs…