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§
Required Methods§
Sourcefn init(api: Api<'rofi>) -> Result<Self, ()>
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}Sourcefn entry_content(&self, line: usize) -> String
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().
Provided Methods§
Sourcefn entry_style(&self, _line: usize) -> Style
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.
Sourcefn entry_attributes(&self, _line: usize) -> Attributes
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.
Sourcefn entry_icon(&mut self, _line: usize, _height: u32) -> Option<Surface>
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.
Sourcefn completed(&self, line: usize) -> String
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.
Sourcefn preprocess_input(&mut self, input: &str) -> String
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.
Sourcefn message(&mut self) -> String
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.