Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash in App.notify relating to markup #5599

Open
darrenburns opened this issue Mar 1, 2025 · 1 comment
Open

Crash in App.notify relating to markup #5599

darrenburns opened this issue Mar 1, 2025 · 1 comment

Comments

@darrenburns
Copy link
Member

If you run the app below and press space, it will crash.

from textual.app import App, ComposeResult
from textual.widgets import Label


class NotifyCrash(App[None]):
    def compose(self) -> ComposeResult:
        yield Label("Press Space to crash!")

    def key_space(self) -> None:
        json = '{"booleans": [true, false]}'
        self.notify(json)


if __name__ == "__main__":
    NotifyCrash().run()

It doesn't crash if I escape markup using textual.markup.escape, like this: self.notify(escape(json)).

Confirmed on Textual 2.1.1 and 1.0.0.

@darrenburns darrenburns changed the title Crash in App.notify Crash in App.notify relating to markup Mar 1, 2025
@python-and-novella
Copy link
Contributor

The notify treats [true, false] as markup.

The solution is:

from textual.app import App, ComposeResult
from textual.widgets import Label
from textual.markup import escape

class NotifyCrash(App[None]):
    def compose(self) -> ComposeResult:
        yield Label("Press Space to crash!")

    def key_space(self) -> None:
        json = '{"booleans": [true, false]}'
        self.notify(escape(json))


if __name__ == "__main__":
    NotifyCrash().run()

BTW, notify's parameter message can parse markup, but the '[red]hello' works well, the '[#ff0]hello' raises error.

from textual.app import App

class MyApp(App):
    def key_q(self):
        self.notify(message='[red]hello')
    def key_w(self):
        self.notify(message='[#ff0]hello')

if __name__ == '__main__':
    app = MyApp()
    app.run()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants