Widget displaying an error message.
| 3034 | |
| 3035 | |
| 3036 | class ErrorMessage(Static): |
| 3037 | """Widget displaying an error message.""" |
| 3038 | |
| 3039 | DEFAULT_CSS = """ |
| 3040 | ErrorMessage { |
| 3041 | height: auto; |
| 3042 | padding: 1; |
| 3043 | margin: 0 0 1 0; |
| 3044 | background: $error-muted; |
| 3045 | color: white; |
| 3046 | border-left: wide $error; |
| 3047 | pointer: text; |
| 3048 | } |
| 3049 | """ |
| 3050 | """Tinted background + left border to visually separate errors from output.""" |
| 3051 | |
| 3052 | def __init__(self, error: str | Content, **kwargs: Any) -> None: |
| 3053 | """Initialize an error message. |
| 3054 | |
| 3055 | Args: |
| 3056 | error: Plain string, or `Content` for pre-styled bodies |
| 3057 | (e.g. with `link`-styled spans). |
| 3058 | **kwargs: Additional arguments passed to parent. |
| 3059 | """ |
| 3060 | self._content = error |
| 3061 | super().__init__(**kwargs) |
| 3062 | |
| 3063 | def render(self) -> Content: |
| 3064 | """Render with theme-aware colors. |
| 3065 | |
| 3066 | Returns: |
| 3067 | Styled error content; spans on a `Content` body are preserved. |
| 3068 | """ |
| 3069 | colors = theme.get_theme_colors(self) |
| 3070 | return Content.assemble( |
| 3071 | Content.styled("Error: ", f"bold {colors.error}"), |
| 3072 | self._content, |
| 3073 | ) |
| 3074 | |
| 3075 | def on_mount(self) -> None: |
| 3076 | """Set border style based on charset mode.""" |
| 3077 | if is_ascii_mode(): |
| 3078 | colors = theme.get_theme_colors(self) |
| 3079 | self.styles.border_left = ("ascii", colors.error) |
| 3080 | |
| 3081 | def on_click(self, event: Click) -> None: # noqa: PLR6301 # Textual event handler |
| 3082 | """Open clicked URLs.""" |
| 3083 | if event.style.link: |
| 3084 | open_style_link(event) |
| 3085 | |
| 3086 | |
| 3087 | class _MutedRichMarkdown: |
no outgoing calls
searching dependent graphs…