add usage discamler

This commit is contained in:
Alexander Mohr 2025-05-04 13:27:48 +02:00
parent 4c8a9771db
commit 2c801a7593
3 changed files with 16 additions and 17 deletions

View file

@ -7,6 +7,9 @@ It started out as a drop in replacement for wofi, so styles and config in most p
with a few exception documented below. with a few exception documented below.
Worf has more features than wofi though, so there won't be 100% compatibility. Worf has more features than wofi though, so there won't be 100% compatibility.
**While the main branch in general is stable and I am using this on a daily basis, it is not ready yet
to be used as a library, a lot of things are still moving around.**
It supports various modes: It supports various modes:
* Math * Math
* DRun * DRun
@ -15,7 +18,6 @@ It supports various modes:
* Run * Run
* Emoji * Emoji
* // WebSearch * // WebSearch
* Auto * Auto
Auto mode tries to detect the desired mode automatically, to achieve this some modes require a prefix in the search. Auto mode tries to detect the desired mode automatically, to achieve this some modes require a prefix in the search.

View file

@ -46,10 +46,9 @@ pub enum WrapMode {
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
pub enum SortOrder { pub enum SortOrder {
Default, Default,
Alphabetical Alphabetical,
} }
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
pub enum Mode { pub enum Mode {
/// searches `$PATH` for executables and allows them to be run by selecting them. /// searches `$PATH` for executables and allows them to be run by selecting them.
@ -132,8 +131,6 @@ impl FromStr for WrapMode {
} }
} }
impl FromStr for SortOrder { impl FromStr for SortOrder {
type Err = ArgsError; type Err = ArgsError;

View file

@ -1,4 +1,4 @@
use crate::config::{Config, expand_path, SortOrder}; use crate::config::{Config, SortOrder, expand_path};
use crate::desktop::{ use crate::desktop::{
copy_to_clipboard, create_file_if_not_exists, find_desktop_files, get_locale_variants, copy_to_clipboard, create_file_if_not_exists, find_desktop_files, get_locale_variants,
is_executable, load_cache_file, lookup_name_with_locale, save_cache_file, spawn_fork, is_executable, load_cache_file, lookup_name_with_locale, save_cache_file, spawn_fork,
@ -432,7 +432,7 @@ struct SshProvider<T: Clone> {
} }
impl<T: Clone> SshProvider<T> { impl<T: Clone> SshProvider<T> {
fn new(menu_item_data: T, order: SortOrder) -> Self { fn new(menu_item_data: T, order: &SortOrder) -> Self {
let re = Regex::new(r"(?m)^\s*Host\s+(.+)$").unwrap(); let re = Regex::new(r"(?m)^\s*Host\s+(.+)$").unwrap();
let mut items: Vec<_> = dirs::home_dir() let mut items: Vec<_> = dirs::home_dir()
.map(|home| home.join(".ssh").join("config")) .map(|home| home.join(".ssh").join("config"))
@ -462,7 +462,7 @@ impl<T: Clone> SshProvider<T> {
}) })
.collect(); .collect();
gui::apply_sort(&mut items, &order); gui::apply_sort(&mut items, order);
Self { elements: items } Self { elements: items }
} }
} }
@ -547,7 +547,7 @@ struct EmojiProvider<T: Clone> {
} }
impl<T: Clone> EmojiProvider<T> { impl<T: Clone> EmojiProvider<T> {
fn new(data: T, sort_order: SortOrder) -> Self { fn new(data: T, sort_order: &SortOrder) -> Self {
let emoji = emoji::search::search_annotation_all(""); let emoji = emoji::search::search_annotation_all("");
let mut menus = emoji let mut menus = emoji
.into_iter() .into_iter()
@ -563,7 +563,7 @@ impl<T: Clone> EmojiProvider<T> {
) )
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
gui::apply_sort(&mut menus, &sort_order); gui::apply_sort(&mut menus, sort_order);
Self { Self {
elements: menus, elements: menus,
@ -588,7 +588,7 @@ struct DMenuProvider {
} }
impl DMenuProvider { impl DMenuProvider {
fn new(sort_order: SortOrder) -> Result<DMenuProvider, Error> { fn new(sort_order: &SortOrder) -> Result<DMenuProvider, Error> {
let mut input = String::new(); let mut input = String::new();
io::stdin() io::stdin()
.read_to_string(&mut input) .read_to_string(&mut input)
@ -600,7 +600,7 @@ impl DMenuProvider {
.map(|s| MenuItem::new(s.clone(), None, None, vec![], None, 0.0, None)) .map(|s| MenuItem::new(s.clone(), None, None, vec![], None, 0.0, None))
.collect(); .collect();
gui::apply_sort(&mut items, &sort_order); gui::apply_sort(&mut items, sort_order);
Ok(Self { items }) Ok(Self { items })
} }
@ -642,8 +642,8 @@ impl AutoItemProvider {
drun: DRunProvider::new(AutoRunType::DRun, config.no_actions(), config.sort_order()), drun: DRunProvider::new(AutoRunType::DRun, config.no_actions(), config.sort_order()),
file: FileItemProvider::new(AutoRunType::File, config.sort_order()), file: FileItemProvider::new(AutoRunType::File, config.sort_order()),
math: MathProvider::new(AutoRunType::Math), math: MathProvider::new(AutoRunType::Math),
ssh: SshProvider::new(AutoRunType::Ssh, config.sort_order()), ssh: SshProvider::new(AutoRunType::Ssh, &config.sort_order()),
emoji: EmojiProvider::new(AutoRunType::Emoji, config.sort_order()), emoji: EmojiProvider::new(AutoRunType::Emoji, &config.sort_order()),
last_mode: None, last_mode: None,
} }
} }
@ -865,7 +865,7 @@ fn ssh_launch<T: Clone>(menu_item: &MenuItem<T>, config: &Config) -> Result<(),
/// * if it was not able to spawn the process /// * if it was not able to spawn the process
/// * if it didn't find a terminal /// * if it didn't find a terminal
pub fn ssh(config: &Config) -> Result<(), Error> { pub fn ssh(config: &Config) -> Result<(), Error> {
let provider = SshProvider::new(0,config.sort_order() ); let provider = SshProvider::new(0, &config.sort_order());
let selection_result = gui::show(config.clone(), provider, true, None); let selection_result = gui::show(config.clone(), provider, true, None);
if let Ok(mi) = selection_result { if let Ok(mi) = selection_result {
ssh_launch(&mi, config)?; ssh_launch(&mi, config)?;
@ -896,7 +896,7 @@ pub fn math(config: &Config) {
/// ///
/// Forwards errors from the gui. See `gui::show` for details. /// Forwards errors from the gui. See `gui::show` for details.
pub fn emoji(config: &Config) -> Result<(), Error> { pub fn emoji(config: &Config) -> Result<(), Error> {
let provider = EmojiProvider::new(0, config.sort_order()); let provider = EmojiProvider::new(0, &config.sort_order());
let selection_result = gui::show(config.clone(), provider, true, None)?; let selection_result = gui::show(config.clone(), provider, true, None)?;
match selection_result.action { match selection_result.action {
None => Err(Error::MissingAction), None => Err(Error::MissingAction),
@ -909,7 +909,7 @@ pub fn emoji(config: &Config) -> Result<(), Error> {
/// ///
/// Forwards errors from the gui. See `gui::show` for details. /// Forwards errors from the gui. See `gui::show` for details.
pub fn dmenu(config: &Config) -> Result<(), Error> { pub fn dmenu(config: &Config) -> Result<(), Error> {
let provider = DMenuProvider::new(config.sort_order())?; let provider = DMenuProvider::new(&config.sort_order())?;
let selection_result = gui::show(config.clone(), provider, true, None); let selection_result = gui::show(config.clone(), provider, true, None);
match selection_result { match selection_result {