Created
September 24, 2025 15:05
-
-
Save haydenflinner/daa58868272c896f6497414d2c0b0547 to your computer and use it in GitHub Desktop.
Nushell script demonstrating mouse handler.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Mouse event handler with escape option | |
| while true { | |
| let event = input listen | |
| # Check for keyboard input to exit | |
| if $event.type == "key" { | |
| if $event.code == "Esc" { | |
| print "Exiting on Escape key..." | |
| break | |
| } else { | |
| print $"Exiting on key press: ($event.code)" | |
| break | |
| } | |
| } | |
| # Handle mouse events | |
| if $event.type == "mouse" { | |
| match $event.kind { | |
| "Left_down" => { print $"Left click at ($event.col), ($event.row)" } | |
| "Right_down" => { print $"Right click at ($event.col), ($event.row)" } | |
| "moved" => { print $"Mouse moved to ($event.col), ($event.row)" } | |
| } | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It seems that moved events are throttled to only one somehow. And the coordinates are those of the window itself, not the per-program space. So would likely need to take over the screen contents to make use of this, maybe with alt-screen. Columnar/x coords work fine though, it's only vertically that things change as you print.