diff --git a/television/channels/prototypes.rs b/television/channels/prototypes.rs index 35ebf34..81eac5d 100644 --- a/television/channels/prototypes.rs +++ b/television/channels/prototypes.rs @@ -394,6 +394,8 @@ pub struct UiSpec { pub help_panel: Option, #[serde(default)] pub remote_control: Option, + #[serde(default)] + pub inline: Option, } pub const DEFAULT_PROTOTYPE_NAME: &str = "files"; @@ -411,6 +413,7 @@ impl From<&crate::config::UiConfig> for UiSpec { status_bar: Some(config.status_bar.clone()), help_panel: Some(config.help_panel.clone()), remote_control: Some(config.remote_control.clone()), + inline: config.inline, } } } diff --git a/television/cli/args.rs b/television/cli/args.rs index 6d45370..a8e6a59 100644 --- a/television/cli/args.rs +++ b/television/cli/args.rs @@ -463,11 +463,11 @@ pub struct Cli { /// space to meet the minimum height the terminal will scroll. #[arg( long, - default_value = "false", verbatim_doc_comment, - conflicts_with = "height" + conflicts_with = "height", + value_parser = clap::builder::FalseyValueParser::new() )] - pub inline: bool, + pub inline: Option, #[command(subcommand)] pub command: Option, diff --git a/television/cli/mod.rs b/television/cli/mod.rs index 7d54724..29f6142 100644 --- a/television/cli/mod.rs +++ b/television/cli/mod.rs @@ -88,7 +88,7 @@ pub struct PostProcessedCli { pub ui_scale: Option, pub height: Option, pub width: Option, - pub inline: bool, + pub inline: Option, // Behavior and matching configuration pub exact: bool, @@ -160,7 +160,7 @@ impl Default for PostProcessedCli { ui_scale: None, height: None, width: None, - inline: false, + inline: None, // Behavior and matching configuration exact: false, @@ -246,7 +246,10 @@ pub fn post_process(cli: Cli, readable_stdin: bool) -> PostProcessedCli { validate_adhoc_mode_constraints(&cli, readable_stdin); // Validate width flag requires inline or height - if cli.width.is_some() && !cli.inline && cli.height.is_none() { + if cli.width.is_some() + && !cli.inline.unwrap_or(false) + && cli.height.is_none() + { cli_parsing_error_exit( "--width can only be used in combination with --inline or --height", ); diff --git a/television/config/ui.rs b/television/config/ui.rs index 55ae396..c919526 100644 --- a/television/config/ui.rs +++ b/television/config/ui.rs @@ -111,6 +111,7 @@ pub struct UiConfig { #[serde(default = "default_input_prompt")] pub input_prompt: String, pub features: Features, + pub inline: Option, // Feature-specific configurations pub status_bar: StatusBarConfig, @@ -144,6 +145,7 @@ impl Default for UiConfig { help_panel: HelpPanelConfig::default(), remote_control: RemoteControlConfig::default(), theme_overrides: ThemeOverrides::default(), + inline: None, } } } diff --git a/television/main.rs b/television/main.rs index 5685c11..9eabf10 100644 --- a/television/main.rs +++ b/television/main.rs @@ -46,7 +46,7 @@ async fn main() -> Result<()> { let readable_stdin = is_readable_stdin(); - let args = post_process(cli, readable_stdin); + let mut args = post_process(cli, readable_stdin); debug!("PostProcessedCli: {:?}", args); // load the configuration file @@ -78,6 +78,9 @@ async fn main() -> Result<()> { let channel_prototype = determine_channel(&args, &config, readable_stdin, Some(&cable)); + // allow channel to override CLI arguments + apply_channel_overrides(&mut args, &channel_prototype); + CLIPBOARD.with(<_>::default); debug!("Creating application..."); @@ -96,7 +99,7 @@ async fn main() -> Result<()> { watch_interval, args.height, args.width, - args.inline, + args.inline.unwrap_or(false), ); let mut app = App::new( channel_prototype, @@ -135,6 +138,17 @@ async fn main() -> Result<()> { exit(0); } +fn apply_channel_overrides( + args: &mut PostProcessedCli, + channel_prototype: &ChannelPrototype, +) -> () { + if let Some(ui) = channel_prototype.ui.as_ref() { + if args.inline.is_none() { + args.inline = ui.inline; + } + } +} + /// Apply overrides from the CLI arguments to the configuration. /// /// This function mutates the configuration in place. @@ -383,6 +397,7 @@ fn apply_ui_overrides( status_bar: None, help_panel: None, remote_control: None, + inline: None, }); // Apply input header override @@ -764,6 +779,7 @@ mod tests { status_bar: None, help_panel: None, remote_control: None, + inline: None, }); let cable = Cable::from_prototypes(vec![channel_prototype]);