yet another change to line flag

This commit is contained in:
Alexander Mohr 2025-05-25 17:03:12 +02:00
parent 9f4dbf13b0
commit ec110d1d91
3 changed files with 46 additions and 48 deletions

View file

@ -180,8 +180,7 @@ impl FromStr for KeyDetectionType {
pub struct Config { pub struct Config {
/// Forks the menu so you can close the terminal /// Forks the menu so you can close the terminal
#[clap(short = 'f', long = "fork")] #[clap(short = 'f', long = "fork")]
#[serde(default = "default_false")] fork: Option<bool>,
fork: bool,
/// Selects a config file to use /// Selects a config file to use
#[clap(short = 'c', long = "conf")] #[clap(short = 'c', long = "conf")]
@ -189,8 +188,7 @@ pub struct Config {
/// Prints the version and then exits /// Prints the version and then exits
#[clap(short = 'v', long = "version")] #[clap(short = 'v', long = "version")]
#[serde(default = "default_false")] version: Option<bool>,
version: bool,
/// Defines the style sheet to be loaded. /// Defines the style sheet to be loaded.
/// Defaults to `$XDG_CONF_DIR/worf/style.css` /// Defaults to `$XDG_CONF_DIR/worf/style.css`
@ -227,13 +225,11 @@ pub struct Config {
/// Set to 'false' to disable images, defaults to true /// Set to 'false' to disable images, defaults to true
#[clap(short = 'I', long = "allow-images")] #[clap(short = 'I', long = "allow-images")]
#[serde(default = "default_true")] allow_images: Option<bool>,
allow_images: bool,
/// If `true` pango markup is parsed /// If `true` pango markup is parsed
#[clap(short = 'm', long = "allow-markup")] #[clap(short = 'm', long = "allow-markup")]
#[serde(default = "default_true")] allow_markup: Option<bool>,
allow_markup: bool,
#[clap(short = 'k', long = "cache-file")] #[clap(short = 'k', long = "cache-file")]
cache_file: Option<String>, // todo support this cache_file: Option<String>, // todo support this
@ -261,8 +257,7 @@ pub struct Config {
/// Defines whether the scrollbar is visible /// Defines whether the scrollbar is visible
#[clap(short = 'b', long = "hide-scroll")] #[clap(short = 'b', long = "hide-scroll")]
#[serde(default = "default_false")] hide_scroll: Option<bool>,
hide_scroll: bool,
/// Defines the matching method, defaults to contains /// Defines the matching method, defaults to contains
#[clap(short = 'M', long = "matching")] #[clap(short = 'M', long = "matching")]
@ -271,8 +266,7 @@ pub struct Config {
/// Control if search is case-insensitive or not. /// Control if search is case-insensitive or not.
/// Defaults to true /// Defaults to true
#[clap(short = 'i', long = "insensitive")] #[clap(short = 'i', long = "insensitive")]
#[serde(default = "default_true")] insensitive: Option<bool>,
insensitive: bool,
#[clap(short = 'q', long = "parse-search")] #[clap(short = 'q', long = "parse-search")]
parse_search: Option<bool>, // todo support this parse_search: Option<bool>, // todo support this
@ -284,7 +278,6 @@ pub struct Config {
)] )]
location: Option<Vec<Anchor>>, location: Option<Vec<Anchor>>,
// todo support this
#[clap(short = 'a', long = "no-actions")] #[clap(short = 'a', long = "no-actions")]
no_actions: Option<bool>, no_actions: Option<bool>,
@ -351,20 +344,13 @@ pub struct Config {
/// If set to `true` the search field willOption<> be hidden. /// If set to `true` the search field willOption<> be hidden.
#[clap(long = "hide-search")] #[clap(long = "hide-search")]
#[serde(default = "default_false")] hide_search: Option<bool>,
hide_search: bool,
#[clap(long = "dynamic-lines")] #[clap(long = "dynamic-lines")]
#[serde(default = "default_false")] dynamic_lines: Option<bool>, // todo support this
dynamic_lines: bool, // todo support this
layer: Option<String>, // todo support this layer: Option<String>, // todo support this
copy_exec: Option<String>, // todo support this copy_exec: Option<String>, // todo support this
#[clap(long = "single_click")] #[clap(long = "single_click")]
single_click: Option<bool>, // todo support this single_click: Option<bool>, // todo support this
#[clap(long = "pre-display-exec")] #[clap(long = "pre-display-exec")]
pre_display_exec: Option<bool>, // todo support this pre_display_exec: Option<bool>, // todo support this
@ -390,7 +376,7 @@ pub struct Config {
impl Config { impl Config {
#[must_use] #[must_use]
pub fn fork(&self) -> bool { pub fn fork(&self) -> bool {
self.fork self.fork.unwrap_or(false)
} }
#[must_use] #[must_use]
@ -431,7 +417,7 @@ impl Config {
#[must_use] #[must_use]
pub fn hide_scroll(&self) -> bool { pub fn hide_scroll(&self) -> bool {
self.hide_scroll self.hide_scroll.unwrap_or(false)
} }
#[must_use] #[must_use]
@ -496,7 +482,7 @@ impl Config {
#[must_use] #[must_use]
pub fn allow_images(&self) -> bool { pub fn allow_images(&self) -> bool {
self.allow_images self.allow_images.unwrap_or(true)
} }
#[must_use] #[must_use]
@ -535,12 +521,12 @@ impl Config {
#[must_use] #[must_use]
pub fn insensitive(&self) -> bool { pub fn insensitive(&self) -> bool {
self.insensitive self.insensitive.unwrap_or(true)
} }
#[must_use] #[must_use]
pub fn hide_search(&self) -> bool { pub fn hide_search(&self) -> bool {
self.hide_search self.hide_search.unwrap_or(false)
} }
#[must_use] #[must_use]
@ -550,7 +536,7 @@ impl Config {
#[must_use] #[must_use]
pub fn allow_markup(&self) -> bool { pub fn allow_markup(&self) -> bool {
self.allow_markup self.allow_markup.unwrap_or(false)
} }
#[must_use] #[must_use]
@ -589,10 +575,10 @@ impl Config {
pub fn lines_additional_space(&self) -> i32 { pub fn lines_additional_space(&self) -> i32 {
self.lines_additional_space.unwrap_or(0) self.lines_additional_space.unwrap_or(0)
} }
#[must_use] #[must_use]
pub fn version(&self) -> bool { pub fn version(&self) -> bool {
self.version self.version.unwrap_or(false)
} }
} }
@ -600,9 +586,9 @@ fn default_false() -> bool {
false false
} }
fn default_true() -> bool { // fn default_true() -> bool {
true // true
} // }
// //
// // TODO // // TODO

View file

@ -1162,20 +1162,32 @@ fn window_show_resize<T: Clone + 'static>(config: &Config, ui: &Rc<UiElements<T>
let height = { let height = {
let lock = ui.menu_rows.read().unwrap(); let lock = ui.menu_rows.read().unwrap();
lock.iter().find_map(|(fb, _)| { lock.iter()
let (_, _, _, baseline) = fb.measure(Orientation::Vertical, 10_000); .find_map(|(fb, _)| {
if baseline > 0 { let (_, _, _, baseline) = fb.measure(Orientation::Vertical, 10_000);
let factor = if lines > 1 { if baseline > 0 {
1.4 // todo find a better way to do this let factor = if lines > 1 {
// most likely it will not work with all styles 1.4 // todo find a better way to do this
// most likely it will not work with all styles
} else {
1.0
};
if config.allow_images() && baseline < i32::from(config.image_size()) {
Some(i32::from(config.image_size()))
} else {
Some((f64::from(baseline) * factor) as i32)
}
} else { } else {
1.0 None
}; }
Some((f64::from(baseline) * factor) as i32) })
} else { .or_else(|| {
None lock.iter().find_map(|(fb, _)| {
} let (_, nat, _, _) = fb.measure(Orientation::Vertical, 10_000);
}) if nat > 0 { Some(nat) } else { None }
})
})
}; };
log::debug!( log::debug!(

View file

@ -20,12 +20,12 @@ fn main() -> anyhow::Result<()> {
args args
} }
}; };
if config.version() { if config.version() {
println!("worf version {}", env!("CARGO_PKG_VERSION")); println!("worf version {}", env!("CARGO_PKG_VERSION"));
return Ok(()); return Ok(());
} }
fork_if_configured(&config); fork_if_configured(&config);
if let Some(show) = &config.show() { if let Some(show) = &config.show() {