Crates.io | rofi |
lib.rs | rofi |
version | 0.4.0 |
source | src |
created_at | 2020-06-10 08:25:17.246527 |
updated_at | 2024-01-16 08:56:15.650656 |
description | Library to crate rofi windows and parse the output |
homepage | https://github.com/tiborschneider/rofi-rs |
repository | https://github.com/tiborschneider/rofi-rs |
max_upload_size | |
id | 252275 |
size | 47,533 |
Spawn rofi windows, and parse the result appropriately.
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)
}
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)
}
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)
}
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
}