Last active
May 9, 2026 16:10
-
-
Save cablehead/e437951fb1ce1a55920bc9e153fbfdd2 to your computer and use it in GitHub Desktop.
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
| ( | |
| interleave | |
| { generate {|_ = 0| | |
| let ev = (try { input listen --types [key] --timeout 200ms } catch { null }) | |
| {out: (if $ev != null { {kind: key, event: $ev} }), next: 0} | |
| } | |
| } | |
| { generate {|_ = 0| sleep 1sec; {out: {kind: tick, event: (date now)}, next: 0} } } | |
| ) | |
| | where $it != null | |
| | take until {|msg| | |
| $msg.kind == "key" and ( | |
| $msg.event.code == "q" or | |
| ($msg.event.code == "c" and "keymodifiers(control)" in $msg.event.modifiers) | |
| ) | |
| } | |
| | each {|msg| | |
| match $msg { | |
| {kind: key, event: $e} => { print $"key: ($e.code)\r" } | |
| {kind: tick, event: $t} => { print $"tick: ($t | format date '%H:%M:%S')\r" } | |
| } | |
| } | |
| | ignore | |
| ^stty sane |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment