remove redundant args error

This commit is contained in:
Alexander Mohr 2025-06-01 10:12:44 +02:00
parent 89b3f6f2d3
commit 0c86a97ab4
3 changed files with 28 additions and 26 deletions

View file

@ -3,7 +3,6 @@ use std::{env, fs, path::PathBuf, str::FromStr};
use clap::{Parser, ValueEnum};
use serde::{Deserialize, Serialize};
use serde_json::Value;
use thiserror::Error;
use crate::Error;
@ -111,12 +110,6 @@ impl FromStr for Layer {
}
}
#[derive(Debug, Error)]
pub enum ArgsError {
#[error("input is not valid {0}")]
InvalidParameter(String),
}
impl FromStr for Anchor {
type Err = String;
@ -132,7 +125,7 @@ impl FromStr for Anchor {
}
impl FromStr for Mode {
type Err = ArgsError;
type Err = Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
@ -144,7 +137,7 @@ impl FromStr for Mode {
"ssh" => Ok(Mode::Ssh),
"emoji" => Ok(Mode::Emoji),
"auto" => Ok(Mode::Auto),
_ => Err(ArgsError::InvalidParameter(
_ => Err(Error::InvalidArgument(
format!("{s} is not a valid argument, see help for details").to_owned(),
)),
}
@ -152,14 +145,14 @@ impl FromStr for Mode {
}
impl FromStr for WrapMode {
type Err = ArgsError;
type Err = Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"none" => Ok(WrapMode::None),
"word" => Ok(WrapMode::Word),
"inherit" => Ok(WrapMode::Inherit),
_ => Err(ArgsError::InvalidParameter(
_ => Err(Error::InvalidArgument(
format!("{s} is not a valid argument, see help for details").to_owned(),
)),
}
@ -167,13 +160,13 @@ impl FromStr for WrapMode {
}
impl FromStr for SortOrder {
type Err = ArgsError;
type Err = Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"alphabetical" => Ok(SortOrder::Alphabetical),
"default" => Ok(SortOrder::Default),
_ => Err(ArgsError::InvalidParameter(
_ => Err(Error::InvalidArgument(
format!("{s} is not a valid argument, see help for details").to_owned(),
)),
}
@ -181,13 +174,13 @@ impl FromStr for SortOrder {
}
impl FromStr for KeyDetectionType {
type Err = ArgsError;
type Err = Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"value" => Ok(KeyDetectionType::Value),
"code" => Ok(KeyDetectionType::Code),
_ => Err(ArgsError::InvalidParameter(
_ => Err(Error::InvalidArgument(
format!("{s} is not a valid argument, see help for details").to_owned(),
)),
}

View file

@ -1160,7 +1160,9 @@ fn sort_menu_items_by_score<T: Clone>(
}
fn window_show_resize<T: Clone + 'static>(config: &Config, ui: &Rc<UiElements<T>>) {
let Some(geometry) = get_monitor_geometry(ui) else { return };
let Some(geometry) = get_monitor_geometry(ui) else {
return;
};
// Calculate target width from config, return early if not set
let Some(target_width) = percent_or_absolute(&config.width(), geometry.width()) else {
@ -1188,7 +1190,11 @@ fn window_show_resize<T: Clone + 'static>(config: &Config, ui: &Rc<UiElements<T>
}
}
fn calculate_dynamic_lines_window_height<T: Clone + 'static>(config: &Config, ui: &UiElements<T>, geometry: Rectangle) -> i32 {
fn calculate_dynamic_lines_window_height<T: Clone + 'static>(
config: &Config,
ui: &UiElements<T>,
geometry: Rectangle,
) -> i32 {
if config.dynamic_lines_limit() {
calculate_row_height(ui, visible_row_count(ui), config)
.min(percent_or_absolute(&config.height(), geometry.height()).unwrap_or(0))
@ -1231,7 +1237,7 @@ fn calculate_row_height<T: Clone + 'static>(
if baseline > 0 {
let factor = if lines > 1 {
1.4 // todo find a better way to do this
// most likely it will not work with all styles
// most likely it will not work with all styles
} else {
1.0
};
@ -1277,7 +1283,7 @@ fn visible_row_count<T: Clone + 'static>(ui: &UiElements<T>) -> i32 {
.filter(|(_, menu)| menu.visible)
.count(),
)
.unwrap_or(i32::MAX)
.unwrap_or(i32::MAX)
}
fn handle_selected_item<T>(
@ -1416,10 +1422,10 @@ fn create_menu_row<T: Clone + 'static + Send>(
element_to_add.icon_path.as_ref().map(AsRef::as_ref),
&meta.config,
)
.or(lookup_icon(
label_img.as_ref().map(AsRef::as_ref),
&meta.config,
));
.or(lookup_icon(
label_img.as_ref().map(AsRef::as_ref),
&meta.config,
));
if let Some(image) = img {
image.set_widget_name("img");

View file

@ -1,4 +1,5 @@
use std::fmt;
use thiserror::Error;
/// Configuration and command line parsing
#[path = "lib/config.rs"]
@ -13,9 +14,8 @@ pub mod gui;
#[path = "lib/modes/mod.rs"]
pub mod modes;
/// Defines error the lib can encounter
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Error)]
pub enum Error {
/// Failed to update a cache file with the given reason.
UpdateCacheError(String),
@ -42,6 +42,8 @@ pub enum Error {
Graphics(String),
/// Nothing selected
NoSelection,
/// Invalid argument
InvalidArgument(String),
}
impl fmt::Display for Error {
@ -75,6 +77,7 @@ impl fmt::Display for Error {
Error::NoSelection => {
write!(f, "NoSelection")
}
Error::InvalidArgument(s) => write!(f, "Invalid argument {s}"),
}
}
}
}