Nushell
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
  • 한국어
GitHub
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
  • 한국어
GitHub
  • Categories

    • Bits
    • Bytes
    • Chart
    • Conversions
    • Core
    • Database
    • Dataframe
    • Dataframe Or Lazyframe
    • Date
    • Debug
    • Default
    • Env
    • Experimental
    • Expression
    • Filesystem
    • Filters
    • Formats
    • Generators
    • Hash
    • History
    • Lazyframe
    • Math
    • Misc
    • Network
    • Path
    • Platform
    • Plugin
    • Prompt
    • Random
    • Removed
    • Shells
    • Strings
    • System
    • Viewers

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:

inputoutput
nothingtui
tuitui
anytui

Examples

Reload the rows with Ctrl+R

> ls | tui table | tui bind ctrl+r {|| ls } | tui run

Submit the highlighted row's name with s

> ls | tui table | tui bind s {|state| {action: submit, selected: $state.selected.name} } | tui run

Use a reedline-style key record

> [a b] | tui table | tui bind {modifier: control, keycode: char_q} {|| {action: quit} } | tui debug --keys ctrl+q | get action

Notes

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.