Mode

Trait Mode 

Source
pub trait Mode<'rofi>: Sized + Sync {
    const NAME: &'static str;

    // Required methods
    fn init(api: Api<'rofi>) -> Result<Self, ()>;
    fn entries(&mut self) -> usize;
    fn entry_content(&self, line: usize) -> String;
    fn react(&mut self, event: Event, input: &mut String) -> Action;
    fn matches(&self, line: usize, matcher: Matcher<'_>) -> bool;

    // Provided methods
    fn entry_style(&self, _line: usize) -> Style { ... }
    fn entry_attributes(&self, _line: usize) -> Attributes { ... }
    fn entry_icon(&mut self, _line: usize, _height: u32) -> Option<Surface> { ... }
    fn completed(&self, line: usize) -> String { ... }
    fn preprocess_input(&mut self, input: &str) -> String { ... }
    fn message(&mut self) -> String { ... }
}
Expand description

A mode supported by Rofi.

You can implement this trait on your own type to define a mode, then export it in the shared library using export_mode!.

Required Associated Constants§

Source

const NAME: &'static str

The name of the mode.

This string must be nul-terminated and contain no intermediate nul characters. This means it will look something like:

const NAME: &'static str = "my-mode\0";

Required Methods§

Source

fn init(api: Api<'rofi>) -> Result<Self, ()>

Initialize the mode.

§Errors

This function is allowed to error, in which case Rofi will display a message:

Failed to initialize the mode: {your mode name}
Source

fn entries(&mut self) -> usize

Get the number of entries offered by the mode.

Source

fn entry_content(&self, line: usize) -> String

Get the text content of a particular entry in the list.

The line parameter is the index of the relevant entry. It is always < self.entries().

Source

fn react(&mut self, event: Event, input: &mut String) -> Action

Process the result of a user’s selection in response to them pressing enter, escape etc, returning the next action to be taken.

input contains the current state of the input text box and can be mutated to change its contents.

Source

fn matches(&self, line: usize, matcher: Matcher<'_>) -> bool

Find whether a specific line matches the given matcher.

The line parameter is the index of the relevant entry. It is always < self.entries().

Provided Methods§

Source

fn entry_style(&self, _line: usize) -> Style

Get the text style of an entry in the list.

The line parameter is the index of the relevant entry. It is always < self.entries().

The default implementation returns Style::NORMAL.

Source

fn entry_attributes(&self, _line: usize) -> Attributes

Get the text attributes associated with a particular entry in the list.

The line parameter is the index of the relevant entry. It is always < self.entries().

The default implementation returns an empty attribute list.

Source

fn entry_icon(&mut self, _line: usize, _height: u32) -> Option<Surface>

Get the icon of a particular entry in the list, if it has one.

The line parameter is the index of the relevant entry. It is always < self.entries().

The default implementation always returns None.

The given height is guaranteed to be <= i32::MAX; that is, you can always safely cast it to an i32.

You can load icons using Api::query_icon, or perform it manually with Cairo’s APIs.

Source

fn completed(&self, line: usize) -> String

Get the completed value of an entry.

This is called when the user triggers the kb-row-select keybind (control+space by default) which sets the content of the input box to the selected item. It is also used by the sorting algorithm.

Note that it is not called on an Event::Complete, Self::react is called then instead.

The line parameter is the index of the relevant entry. It is always < self.entries().

The default implementation forwards to Self::entry_content.

Source

fn preprocess_input(&mut self, input: &str) -> String

Preprocess the user’s input before using it to filter and/or sort. This is typically used to strip markup.

The default implementation returns the input unchanged.

Source

fn message(&mut self) -> String

Get the message to show in the message bar.

The returned string must be valid Pango markup.

The default implementation returns an empty string.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§