zellij-nucleo

Crates.iozellij-nucleo
lib.rszellij-nucleo
version0.0.6
created_at2025-01-05 22:48:44.591206+00
updated_at2025-01-06 09:16:38.257492+00
descriptionnucleo-based picker library for zellij plugins
homepage
repositoryhttps://git.tozt.net/zellij-nucleo
max_upload_size
id1505120
size24,310
Jesse Luehrs (doy)

documentation

README

zellij-nucleo

This crate provides a fuzzy finder widget based on nucleo-matcher for use in zellij plugins. It can be used by your own plugins to allow easy searching through a list of options, and automatically handles the picker UI as needed.

Usage

A basic plugin that uses the zellij-nucleo crate to switch tabs can be structured like this:

use zellij_tile::prelude::*;

#[derive(Default)]
struct State {
    picker: zellij_nucleo::Picker<u32>,
}

register_plugin!(State);

impl ZellijPlugin for State {
    fn load(
        &mut self,
        configuration: std::collections::BTreeMap<String, String>,
    ) {
        request_permission(&[
            PermissionType::ReadApplicationState,
            PermissionType::ChangeApplicationState,
        ]);

        subscribe(&[EventType::TabUpdate]);
        self.picker.load(&configuration);
    }

    fn update(&mut self, event: Event) -> bool {
        match self.picker.update(&event) {
            Some(zellij_nucleo::Response::Select(entry)) => {
                go_to_tab(entry.data);
                close_self();
            }
            Some(zellij_nucleo::Response::Cancel) => {
                close_self();
            }
            None => {}
        }

        if let Event::TabUpdate(tabs) = event {
            self.picker.clear();
            self.picker.extend(tabs.iter().map(|tab| zellij_nucleo::Entry {
                data: u32::try_from(tab.position).unwrap(),
                string: format!("{}: {}", tab.position + 1, tab.name),
            }));
        }

        self.picker.needs_redraw()
    }

    fn render(&mut self, rows: usize, cols: usize) {
        self.picker.render(rows, cols);
    }
}

Notes

Unlike the nucleo crate, this can't run concurrently due to existing limitations with the zellij plugin interface. This shouldn't matter for reasonably short lists, but may be noticeable for larger lists.

Commit count: 0

cargo fmt