Skip to main content

Module key

Module key 

Source
Expand description

Cleanroom Rust port of upstream Go source file: key/key.go Upstream Target Tag / Version: v2.1.0

# Keymappings

Types and functions for generating user-definable keymappings useful in Bubble Tea components. There are a few different ways you can define a keymapping with this package. Here’s one example:

use rusty_bubbles::key;

struct KeyMap {
    up: key::Binding,
    down: key::Binding,
}

fn default_key_map() -> KeyMap {
    KeyMap {
        // actual keybindings
        up: key::new_binding(
            key::with_keys(&["k", "up"]),
            // corresponding help text
            key::with_help("↑/k", "move up"),
        ),
        down: key::new_binding(
            key::with_keys(&["j", "down"]),
            key::with_help("↓/j", "move down"),
        ),
    }
}

The help information, which is not used in the example above, can be used to render help text for keystrokes in your views.

Structs§

Binding
Binding describes a set of keybindings and, optionally, their associated help text.
Help
Help is help information for a given keybinding.

Functions§

matches
Matches checks if the given key matches the given bindings.
new_binding
NewBinding returns a new keybinding from a set of BindingOpt options.
with_disabled
WithDisabled initializes a disabled keybinding.
with_help
WithHelp initializes a keybinding with the given help text.
with_keys
WithKeys initializes a keybinding with the given keystrokes.

Type Aliases§

BindingOpt
BindingOpt is an initialization option for a keybinding. It’s used as an argument to new_binding.