Skip to content

Instantly share code, notes, and snippets.

@cablehead
Last active May 9, 2026 16:10
Show Gist options
  • Select an option

  • Save cablehead/e437951fb1ce1a55920bc9e153fbfdd2 to your computer and use it in GitHub Desktop.

Select an option

Save cablehead/e437951fb1ce1a55920bc9e153fbfdd2 to your computer and use it in GitHub Desktop.
(
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