KeyHandler

Type Alias KeyHandler 

Source
pub type KeyHandler = Box<dyn Fn(&KeyDownEvent) -> bool + Send + Sync>;
Expand description

Callback type for key event interception.

This callback is invoked before the terminal processes a key event, allowing you to intercept and handle specific key combinations.

§Arguments

  • event - The key down event from GPUI

§Returns

  • true - Consume the event (terminal will not process it)
  • false - Let the terminal handle the event normally

§Thread Safety

This callback must be Send + Sync.

§Example

terminal.with_key_handler(|event| {
    let keystroke = &event.keystroke;

    // Intercept Ctrl++ for font size increase
    if keystroke.modifiers.control && (keystroke.key == "+" || keystroke.key == "=") {
        // Handle font size increase
        return true; // Consume the event
    }

    // Intercept Ctrl+- for font size decrease
    if keystroke.modifiers.control && keystroke.key == "-" {
        // Handle font size decrease
        return true;
    }

    false // Let terminal handle all other keys
});

Aliased Type§

pub struct KeyHandler(/* private fields */);