textual-drivers: Textual's default Drivers, but with more features #6622
NSPC911
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hello everyone! I introduce you to
textual-drivers. It adds two new functions for use in the driver.lock_stdin()It is a context manager that pauses the driver's stdin reader thread, disables all terminal event reporting enabled by Textual, and drains remaining bytes to allow you to send and receive an ANSI sequence.
register_event_handler()This is the most game-changing of the two. It lets you register a custom
Event()class to be sent when a given pattern is received viastdin.Doing this will cause Textual to send the
DNDevent, and it can be handled using@on(DND)oron_dnd!To make use of this, you can just
and do this change
And the rest is automatically handled!
Using this feature, I was able to add proper Drag and Drop support in Textual, something that would not have been possible before. View the full documentation for it at the wiki. You can test it using the latest kitty-nightly version by running
For a real implementation of DNDApp, check NSPC911/rovr#300.
I'm not sure if the base features (
lock_stdinandregister_event_handler) will be added to Textual, neither do I plan to upstream this as a PR (too big + vibe-coded), so for now, this will be opt-in.All reactions