#ui #rofi #launcher

rustofi

Library to build simple 'Rofi User Interface' applications

5 releases

0.2.2 Nov 19, 2019
0.2.1 Nov 19, 2019
0.1.6 Nov 15, 2019

#636 in GUI

GPL-3.0+

39KB
575 lines

Rustofi

Rustofi is a library for building RUI (Rofi User Interface) applications. It supports getting user selection, user entry and can run associated callbacks on item selection.

Usage

Add this to your Cargo.toml

[dependencies]
rustofi = "0.2.2"

then to use in your Rust 2018 application you'll probably want these imports

use rustofi::{AppRoot, RustofiOption, RustofiOptionType};
use rustofi::window::{Window, Location};

Example

Simple

The example simple just displays a rofi window in a loop and returns the text selected.

git clone https://github.com/krruzic/rustofi
cd rustofi
cargo run --example simple

Todo App

A more complicated example todo_app is a persistent Todo List that can

  • create new Todos
  • delete Todos
  • mark Todos as finished
git clone https://github.com/krruzic/rustofi
cd rustofi
cargo run --example todo_app

lib.rs:

This Rust library enables the construction of complex multipage applications that use Rofi to display their UI. The basic idea is to create a AppPage or SearchPage as an application main menu and feed it in possible selections and actions. These selections and actions can then navigate you to an ItemList, an EntryBox an ActionList or another main menu.

Typically you will want to create an AppPage with some options and actions, then display it in a loop checking the return for the RustofiOptionType to exit on. AppPage and SearchPage will automatically add an exit option to simplify the loop exit cases, while ItemList and ActionList will add a cancel option.

Simplest Possible Example

The below example gets even simpler than creating an AppRoot, just displaying a list of strings and utilizing a callback to print the selected item. Notice the loop in main checking the return variant of the rofi window

use rustofi::components::ItemList;
use rustofi::RustofiResult;

fn simple_app() -> RustofiResult {
    let rustofi_entries = vec![
        "Entry 1".to_string(),
        "Entry 2".to_string(),
        "Entry 3".to_string(),
    ];
    ItemList::new(rustofi_entries, Box::new(simple_callback)).display("Select an entry".to_string())
}

pub fn simple_callback(s: &String) -> RustofiResult {
    println!("Clicked on item: {}", s);
    RustofiResult::Success
}

fn main() {
    loop {
        match simple_app() {
            RustofiResult::Error => break,
            RustofiResult::Exit => break,
            RustofiResult::Cancel => break,
            RustofiResult::Blank => break,
            _ => {}
        }
    }
}

Dependencies

~2.5MB
~53K SLoC