gpui-commands 0.1.0

Unified action registration, keybinding, and command palette for GPUI
Documentation
  • Coverage
  • 100%
    4 out of 4 items documented0 out of 0 items with examples
  • Size
  • Source code size: 226.3 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 348.0 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 1m 7s Average build duration of successful builds.
  • all releases: 1m 7s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • MrSheerluck

gpui-commands

A coherence layer for the GPUI framework: one registry, one API, and a searchable command palette for every command an application supports.

GPUI already provides the building blocks - the actions! macro declares action structs, cx.bind_keys maps keys to actions, and .on_action() wires handlers. But there is no single registry tracking every command an app supports, no metadata (name, category, description) attached to actions, and no reusable command palette. gpui-commands sits on top of GPUI's existing system and provides that missing coherence layer.

Installation

[dependencies]
gpui = "0.2"
gpui-commands = "0.1"

Quick start

use gpui::*;
use gpui_commands::{Command, CommandPalette, CommandRegistry};

actions!(editor, [SaveFile, ToggleSidebar, FormatDocument]);

fn build_app(cx: &mut App) {
    let mut registry = CommandRegistry::new();

    registry.register(
        Command::new("Save File", SaveFile)
            .category("File")
            .keybinding("cmd-s")
            .handler(|window, cx| {
                // save logic
            }),
    );

    registry.register(
        Command::new("Toggle Sidebar", ToggleSidebar)
            .category("View")
            .keybinding("cmd-b")
            .handler(|window, cx| {
                // toggle logic
            }),
    );

    // Palette-only commands are valid too (no keybinding, no category).
    registry.register(
        Command::new("Format Document", FormatDocument)
            .category("Edit")
            .handler(|window, cx| {
                // format logic
            }),
    );

    // One call binds every registered keybinding with GPUI.
    registry.install_keybindings(cx);

    // The palette takes over the window's root view (call after creating
    // your windows). Press cmd-shift-p to open it.
    CommandPalette::install(registry, cx);
}

See examples/basic.rs for a runnable app:

cargo run --example basic

The command palette

Press cmd-shift-p (configurable via install_with_trigger) and a dimmed overlay appears with a search card: type to filter commands with fuzzy subsequence matching (tgsb finds "Toggle Sidebar"), ↑/↓ to move the highlight, Enter or a click to execute, Escape or a click outside the card to dismiss. Every command row shows its name, category, and bound shortcut.

API

  • Command::new(name, action) - start building a command (name is what the palette shows; action is the underlying GPUI action). Builder steps: .category(...), .keybinding(...), .handler(f) (required before registering).
  • CommandRegistry::new() / register(command) / commands() / install_keybindings(cx) - the single source of truth. Registering the same action type twice, or a command without a handler, panics - matching GPUI's own convention.
  • CommandPalette::install(registry, cx) / install_with_trigger(registry, trigger, cx) - store the registry as a global, bind the trigger, and mount the palette.

How it works

Keybindings are ordinary GPUI keybindings: cmd-s dispatches the SaveFile action, which your app handles with its own .on_action listeners exactly as before - the crate never hijacks dispatch. The .handler() closures are the palette's activation path: when you press Enter in the palette, the selected command's handler runs with (&mut Window, &mut App). The palette is installed as the window's permanent root view, keeping the app's root alive inside it - so app state and focus survive open/close cycles.

License

MIT