6 releases (3 breaking)

0.4.0 Jan 16, 2024
0.3.0 Sep 19, 2021
0.2.2 Jun 10, 2020
0.1.0 Jun 10, 2020

#132 in GUI

Download history 15/week @ 2023-12-18 3/week @ 2023-12-25 16/week @ 2024-01-08 15/week @ 2024-01-15 1/week @ 2024-01-22 2/week @ 2024-02-05 9/week @ 2024-02-12 13/week @ 2024-02-19 41/week @ 2024-02-26 23/week @ 2024-03-04 39/week @ 2024-03-11 24/week @ 2024-03-18 18/week @ 2024-03-25 76/week @ 2024-04-01

161 downloads per month
Used in 2 crates

Apache-2.0

36KB
584 lines

Rofi Library for Rust

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 showing a message with no inputs

rofi can display a message without any inputs. This is commonly used for error reporting.

use rofi;

match rofi::Rofi::new_message("Something went wrong").run() {
    Err(rofi::Error::Blank) => () // the expected case
    Ok(_) => ()  // should not happen
    Err(_) => () // Something went wrong
}

Dependencies

~310–770KB
~18K SLoC