diff --git a/src/config.rs b/src/config.rs index 5c5db78..e81e175 100644 --- a/src/config.rs +++ b/src/config.rs @@ -35,6 +35,14 @@ impl<'a> Config<'a> { .expect("Y offset must be present"); let use_blocks = matches.get_flag("blocks"); + + #[cfg(any(feature = "sixel", feature = "icy_sixel"))] + let use_sixel = matches.get_flag("sixel"); + + #[cfg(any(feature = "sixel", feature = "icy_sixel"))] + if use_blocks && use_sixel { + panic!("Internal error: both --blocks and --sixel options are set, but they are defined as mutually exclusive and clap should have prevented this state"); + } let transparent = matches.get_flag("transparent"); let viuer_config = ViuerConfig { @@ -44,10 +52,20 @@ impl<'a> Config<'a> { y, transparent, absolute_offset, - use_kitty: !use_blocks, - use_iterm: !use_blocks, + // if flag `use_blocks` or `use_sixel` is set, return false + #[cfg(any(feature = "sixel", feature = "icy_sixel"))] + use_kitty: (!use_blocks || !use_sixel), + #[cfg(not(any(feature = "sixel", feature = "icy_sixel")))] + use_kitty: (!use_blocks), + + #[cfg(any(feature = "sixel", feature = "icy_sixel"))] + use_iterm: (!use_blocks || !use_sixel), + #[cfg(not(any(feature = "sixel", feature = "icy_sixel")))] + use_iterm: (!use_blocks), + #[cfg(any(feature = "sixel", feature = "icy_sixel"))] - use_sixel: !use_blocks, + // just `use_sixel` is set and `use_blocks` is not set, return true + use_sixel: (use_sixel && !use_blocks), ..Default::default() }; diff --git a/src/main.rs b/src/main.rs index 5c5b893..988ac6b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ use clap::{ crate_description, crate_name, crate_version, value_parser, Arg, ArgAction::{Append, Help, SetTrue}, - Command, + ArgGroup, Command, }; mod app; @@ -10,7 +10,7 @@ mod config; use config::Config; fn main() { - let matches = Command::new(crate_name!()) + let mut arg_build = Command::new(crate_name!()) .version(crate_version!()) .about(crate_description!()) .arg_required_else_help(true) @@ -67,7 +67,25 @@ fn main() { .long("blocks") .action(SetTrue) .help("Force block output"), - ) + ); + + let mut output_group = ArgGroup::new("output") + .arg("blocks") + .multiple(false) + .required(false); + + if cfg!(any(feature = "sixel", feature = "icy_sixel")) { + arg_build = arg_build.arg( + Arg::new("sixel") + .long("sixel") + .action(SetTrue) + .help("Force sixel output"), + ); + output_group = output_group.arg("sixel"); + } + + arg_build = arg_build + .group(output_group) .arg( Arg::new("name") .short('n') @@ -117,8 +135,9 @@ fn main() { .long("help") .action(Help) .help("Print help information"), - ) - .get_matches(); + ); + + let matches = arg_build.get_matches(); let conf = Config::new(&matches);