Crate rofi

Source
Expand description

§Rofi ui manager

Spawn rofi windows, and parse the result appropriately.

§Simple example

use rofi;
use std::{fs, env};

let dir_entries = fs::read_dir(env::current_dir().unwrap())
    .unwrap()
    .map(|d| format!("{:?}", d.unwrap().path()))
    .collect::<Vec<String>>();

match rofi::Rofi::new(&dir_entries).run() {
    Ok(choice) => println!("Choice: {}", choice),
    Err(rofi::Error::Interrupted) => println!("Interrupted"),
    Err(e) => println!("Error: {}", e)
}

§Example of returning an index

rofi can also be used to return an index of the selected item:

use rofi;
use std::{fs, env};

let dir_entries = fs::read_dir(env::current_dir().unwrap())
    .unwrap()
    .map(|d| format!("{:?}", d.unwrap().path()))
    .collect::<Vec<String>>();

match rofi::Rofi::new(&dir_entries).run_index() {
    Ok(element) => println!("Choice: {}", element),
    Err(rofi::Error::Interrupted) => println!("Interrupted"),
    Err(rofi::Error::NotFound) => println!("User input was not found"),
    Err(e) => println!("Error: {}", e)
}

§Example of using pango formatted strings

rofi can display pango format. Here is a simple example (you have to call the self..pango function).

use rofi;
use rofi::pango::{Pango, FontSize};
use std::{fs, env};

let entries: Vec<String> = vec![
    Pango::new("Option 1").size(FontSize::Small).fg_color("#666000").build(),
    Pango::new("Option 2").size(FontSize::Large).fg_color("#deadbe").build(),
];

match rofi::Rofi::new(&entries).pango().run() {
    Ok(element) => println!("Choice: {}", element),
    Err(rofi::Error::Interrupted) => println!("Interrupted"),
    Err(e) => println!("Error: {}", e)
}

§Example of using custom keyboard shortcuts with rofi

use rofi;
use std::{fs, env};

let dir_entries = fs::read_dir(env::current_dir().unwrap())
    .unwrap()
    .map(|d| format!("{:?}", d.unwrap().path()))
    .collect::<Vec<String>>();
let mut r = rofi::Rofi::new(&dir_entries);
match r.kb_custom(1, "Alt+n").unwrap().run() {
    Ok(choice) => println!("Choice: {}", choice),
    Err(rofi::Error::CustomKeyboardShortcut(exit_code)) => println!("exit code: {:?}", exit_code),
    Err(rofi::Error::Interrupted) => println!("Interrupted"),
    Err(e) => println!("Error: {}", e)
}

Modules§

pango
Pango markup language support https://developer.gnome.org/pygtk/stable/pango-markup-language.html

Structs§

Rofi
Rofi Window Builder
RofiChild
Rofi child process.

Enums§

Error
Rofi Error Type
Format
Different modes, how rofi should return the results
Width
Width of the rofi window to overwrite the default width from the rogi theme.