rofi-mode

rofi-mode provides a high-level ergonomic wrapper around Rofi's C plugin API.

Getting started

First of all, create a new library with cargo new --lib my_awesome_plugin and add these lines to the Cargo.toml:

toml [lib] crate-type = ["cdylib"]

That will force Cargo to generate your library as a .so file, which is what Rofi loads its plugins from.

Now in your lib.rs, create a struct and implement the [Mode] trait for it. For example, here is a no-op mode with no entries:

```rust struct Mode;

impl rofimode::Mode<'> for Mode { const NAME: &'static str = "an-example-mode\0"; fn init(api: rofimode::Api<'>) -> Result usize { 0 } fn entrycontent(&self, line: usize) -> rofimode::String { unreachable!() } fn react( &mut self, event: rofimode::Event, input: &mut rofimode::String, ) -> rofimode::Action { rofimode::Action::Exit } fn matches(&self, line: usize, _matcher: rofimode::Matcher<'_>) -> bool { unreachable!() } } ```

You then need to export your mode to Rofi via the [export_mode!] macro:

rust rofi_mode::export_mode!(Mode);

Build your library using cargo build then copy the resulting dylib file (e.g. /target/debug/libmy_awesome_plugin.so) into /lib/rofi so that Rofi will pick up on it when it starts up (alternatively, you can set the ROFI_PLUGIN_PATH environment variable to the directory your .so file is in). You can then run your mode from Rofi's command line:

sh rofi -modi an-example-mode -show an-example-mode

License: MIT