From 67f9df3c5daf0bea5536babbfaf430ae885dc193 Mon Sep 17 00:00:00 2001 From: Paul-16098 Date: Wed, 18 Feb 2026 23:23:25 +0800 Subject: [PATCH 1/3] chore(cli): Add flag `--sixel` for force sixel output Fixes #125 --- src/config.rs | 14 ++++++++++---- src/main.rs | 21 +++++++++++++++++---- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/config.rs b/src/config.rs index 5c5db78..0a6c7fd 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,5 +1,5 @@ use clap::ArgMatches; -use std::time::Duration; +use std::{process::exit, time::Duration}; use viuer::Config as ViuerConfig; pub struct Config<'a> { @@ -35,6 +35,12 @@ impl<'a> Config<'a> { .expect("Y offset must be present"); let use_blocks = matches.get_flag("blocks"); + let use_sixel = matches.get_flag("sixel"); + if use_blocks && use_sixel { + println!("The --blocks and --sixel options cannot be used together."); + exit(1) + } + let transparent = matches.get_flag("transparent"); let viuer_config = ViuerConfig { @@ -44,10 +50,10 @@ impl<'a> Config<'a> { y, transparent, absolute_offset, - use_kitty: !use_blocks, - use_iterm: !use_blocks, + use_kitty: (!use_blocks && !use_sixel), + use_iterm: (!use_blocks && !use_sixel), #[cfg(any(feature = "sixel", feature = "icy_sixel"))] - use_sixel: !use_blocks, + use_sixel: (!use_blocks && use_sixel), ..Default::default() }; diff --git a/src/main.rs b/src/main.rs index 5c5b893..23121e6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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) @@ -60,7 +60,19 @@ fn main() { .long("recursive") .action(SetTrue) .help("Recurse down directories if passed one"), - ) + ); + + if cfg!(feature = "sixel") { + arg_build = arg_build.arg( + Arg::new("sixel") + .short('s') + .long("sixel") + .action(SetTrue) + .help("Force sixel output"), + ); + } + + arg_build = arg_build .arg( Arg::new("blocks") .short('b') @@ -117,8 +129,9 @@ fn main() { .long("help") .action(Help) .help("Print help information"), - ) - .get_matches(); + ); + + let matches = arg_build.get_matches(); let conf = Config::new(&matches); From cd06b05951a7115595ab2f6c1e8247da21a2d138 Mon Sep 17 00:00:00 2001 From: Paul-16098 Date: Wed, 18 Feb 2026 23:40:47 +0800 Subject: [PATCH 2/3] fix(config): Correct logic for use_kitty and use_sixel flags --- src/config.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/config.rs b/src/config.rs index 0a6c7fd..ea21519 100644 --- a/src/config.rs +++ b/src/config.rs @@ -50,10 +50,12 @@ impl<'a> Config<'a> { y, transparent, absolute_offset, - use_kitty: (!use_blocks && !use_sixel), - use_iterm: (!use_blocks && !use_sixel), + // if flag `use_blocks` or `use_sixel` is set, return false + use_kitty: (!use_blocks || !use_sixel), + use_iterm: (!use_blocks || !use_sixel), #[cfg(any(feature = "sixel", feature = "icy_sixel"))] - use_sixel: (!use_blocks && use_sixel), + // just `use_sixel` is set and `use_blocks` is not set, return true + use_sixel: (use_sixel && !use_blocks), ..Default::default() }; From 2b481dd66cfb4480928297db37a4b8efb564d4ae Mon Sep 17 00:00:00 2001 From: Paul-16098 Date: Thu, 19 Feb 2026 00:08:20 +0800 Subject: [PATCH 3/3] fix(config): Improve handling of mutually exclusive flags for blocks and sixel --- src/config.rs | 18 ++++++++++++++---- src/main.rs | 26 ++++++++++++++++---------- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/config.rs b/src/config.rs index ea21519..e81e175 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,5 +1,5 @@ use clap::ArgMatches; -use std::{process::exit, time::Duration}; +use std::time::Duration; use viuer::Config as ViuerConfig; pub struct Config<'a> { @@ -35,12 +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 { - println!("The --blocks and --sixel options cannot be used together."); - exit(1) + 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 { @@ -51,8 +53,16 @@ impl<'a> Config<'a> { transparent, absolute_offset, // 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"))] // just `use_sixel` is set and `use_blocks` is not set, return true use_sixel: (use_sixel && !use_blocks), diff --git a/src/main.rs b/src/main.rs index 23121e6..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; @@ -60,26 +60,32 @@ fn main() { .long("recursive") .action(SetTrue) .help("Recurse down directories if passed one"), + ) + .arg( + Arg::new("blocks") + .short('b') + .long("blocks") + .action(SetTrue) + .help("Force block output"), ); - if cfg!(feature = "sixel") { + 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") - .short('s') .long("sixel") .action(SetTrue) .help("Force sixel output"), ); + output_group = output_group.arg("sixel"); } arg_build = arg_build - .arg( - Arg::new("blocks") - .short('b') - .long("blocks") - .action(SetTrue) - .help("Force block output"), - ) + .group(output_group) .arg( Arg::new("name") .short('n')