tui bind for viewers
Run a hook when a key is pressed anywhere in the TUI.
Command Type
built-in
Signature
> tui bind {flags} (key) (hook)
Parameters
key: Chord like 'ctrl+s', or a {modifier, keycode} record.hook: Closure run with the state record.
Input/output types:
| input | output |
|---|---|
| nothing | tui |
| tui | tui |
| any | tui |
Examples
Reload the rows with Ctrl+R
> ls | tui table | tui bind ctrl+r {|| ls } | tui runSubmit the highlighted row's name with s
> ls | tui table | tui bind s {|state| {action: submit, selected: $state.selected.name} } | tui runUse a reedline-style key record
> [a b] | tui table | tui bind {modifier: control, keycode: char_q} {|| {action: quit} } | tui debug --keys ctrl+q | get actionNotes
The key is a chord string like ctrl+s, alt+r, f5, or x, or a reedline-style record {modifier: control, keycode: char_s} as in $env.config.keybindings.
The hook receives the state record ({action, focused, selected, page, values, rows, live}) as $in and as its first parameter. Return nothing to change nothing, a value to replace the data list, or {action: submit, selected: ...} / {action: quit} to end the TUI.
Binds take precedence over the built-in keys, except Ctrl+C. A bind without a modifier does not fire while typing in a search or text box.