fix(ui): config now takes precedence when no cli args on ui_scale

fixes #612
This commit is contained in:
Alex Pasmantier 2025-07-09 23:58:22 +02:00
parent 20a55cf142
commit c392ae891c
3 changed files with 26 additions and 7 deletions

View File

@ -389,11 +389,10 @@ pub struct Cli {
#[arg(
long,
value_name = "INTEGER",
default_value = "100",
verbatim_doc_comment,
value_parser = clap::value_parser!(u16).range(10..=100)
)]
pub ui_scale: u16,
pub ui_scale: Option<u16>,
/// Percentage of the screen to allocate to the preview panel (1-99).
///

View File

@ -3,8 +3,7 @@ use crate::{
channels::prototypes::{ChannelPrototype, Template},
cli::args::{Cli, Command},
config::{
DEFAULT_PREVIEW_SIZE, DEFAULT_UI_SCALE, KeyBindings, get_config_dir,
get_data_dir,
DEFAULT_PREVIEW_SIZE, KeyBindings, get_config_dir, get_data_dir,
},
errors::cli_parsing_error_exit,
screen::layout::Orientation,
@ -84,7 +83,7 @@ pub struct PostProcessedCli {
// UI and layout configuration
pub layout: Option<Orientation>,
pub ui_scale: u16,
pub ui_scale: Option<u16>,
pub height: Option<u16>,
pub width: Option<u16>,
pub inline: bool,
@ -154,7 +153,7 @@ impl Default for PostProcessedCli {
// UI and layout configuration
layout: None,
ui_scale: DEFAULT_UI_SCALE,
ui_scale: None,
height: None,
width: None,
inline: false,

View File

@ -196,7 +196,7 @@ fn apply_cli_overrides(args: &PostProcessedCli, config: &mut Config) {
config.keybindings =
merge_keybindings(config.keybindings.clone(), keybindings);
}
config.ui.ui_scale = args.ui_scale;
config.ui.ui_scale = args.ui_scale.unwrap_or(config.ui.ui_scale);
if let Some(input_header) = &args.input_header {
if let Ok(t) = Template::parse(input_header) {
config.ui.input_header = Some(t);
@ -798,4 +798,25 @@ mod tests {
Some(Template::parse("CLI Preview Footer").unwrap())
);
}
#[test]
fn test_apply_cli_overrides_ui_scale() {
// Test that the CLI ui_scale override is applied correctly
let mut config = Config::default();
let args = PostProcessedCli {
ui_scale: Some(90),
..Default::default()
};
apply_cli_overrides(&args, &mut config);
assert_eq!(config.ui.ui_scale, 90);
// Test that the config value is used when no CLI override is provided
let mut config = Config::default();
config.ui.ui_scale = 70;
let args = PostProcessedCli::default();
apply_cli_overrides(&args, &mut config);
assert_eq!(config.ui.ui_scale, 70);
}
}