From 3aca9a36816a10993ba2b8ced495c9bf55384cb9 Mon Sep 17 00:00:00 2001 From: Xiangru Lian Date: Wed, 17 Aug 2022 21:28:01 -0400 Subject: [PATCH 1/4] Support `-x`, `-y`, and `--absolute-offset`. --- src/config.rs | 18 +++++++++++++++++- src/main.rs | 19 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index 8527b96..2275177 100644 --- a/src/config.rs +++ b/src/config.rs @@ -25,6 +25,18 @@ impl<'a> Config<'a> { None }; + let x = if matches.is_present("x") { + matches.value_of_t_or_exit("x") + } else { + 0 + }; + + let y = if matches.is_present("y") { + matches.value_of_t_or_exit("y") + } else { + 0 + }; + let files = match matches.values_of("FILE") { None => Vec::new(), Some(values) => values.collect(), @@ -38,11 +50,15 @@ impl<'a> Config<'a> { let use_blocks = matches.is_present("blocks"); + let absolute_offset = matches.is_present("absolute-offset"); + let viuer_config = ViuerConfig { transparent, + x, + y, width, height, - absolute_offset: false, + absolute_offset: absolute_offset, use_kitty: !use_blocks, use_iterm: !use_blocks, #[cfg(feature = "sixel")] diff --git a/src/main.rs b/src/main.rs index d5c906a..7fad363 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,6 +39,25 @@ fn main() { .long("static") .help("Show only first frame of gif"), ) + .arg( + Arg::new("x") + .short('x') + .takes_value(true) + .help("X offset. Defaults to 0."), + ) + .arg( + Arg::new("y") + .short('y') + .takes_value(true) + .help("Y offset. Defaults to 0."), + ) + .arg( + Arg::new("absolute-offset") + .short('a') + .long("absolute-offset") + .takes_value(false) + .help("Make the x and y offset be relative to the top left terminal corner. If false, the y offset is relative to the cursor's position. Defaults to true."), + ) .arg( Arg::new("width") .short('w') From 5b57b09e89cea34afd6b0b48cf57a624ad19a82f Mon Sep 17 00:00:00 2001 From: Xiangru Lian Date: Wed, 17 Aug 2022 21:35:09 -0400 Subject: [PATCH 2/4] chore --- src/config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index 2275177..1a2a070 100644 --- a/src/config.rs +++ b/src/config.rs @@ -58,7 +58,7 @@ impl<'a> Config<'a> { y, width, height, - absolute_offset: absolute_offset, + absolute_offset, use_kitty: !use_blocks, use_iterm: !use_blocks, #[cfg(feature = "sixel")] From e5958a20de34f2cbd56ed43d83db96951e498bb7 Mon Sep 17 00:00:00 2001 From: Atanas Yankov Date: Sun, 23 Oct 2022 10:58:45 +0300 Subject: [PATCH 3/4] Add default values --- README.md | 42 ++++++++++++++++++++++++++++++------------ src/config.rs | 4 ++-- src/main.rs | 4 +++- 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index f86ac42..853ebaf 100644 --- a/README.md +++ b/README.md @@ -116,22 +116,40 @@ only if both options **-w** and **-h** are used together. ### Command line options ``` +View images right from the terminal. + Usage: viu [OPTIONS] [file]... Arguments: [file]... The images to be displayed. Set to - for standard input. Options: - -w, --width Resize the image to a provided width - -h, --height Resize the image to a provided height - -r, --recursive Recurse down directories if passed one - -b, --blocks Force block output - -n, --name Output the name of the file before displaying - -t, --transparent Display transparent images with transparent background - -f, --frame-rate Play the gif at a given frame rate - -1, --once Loop only once through the gif - -s, --static Show only the first frame of the gif - -H, --help Print help information - -V, --version Print version information - + -w, --width + Resize the image to a provided width + -h, --height + Resize the image to a provided height + -x + X offset [default: 0] + -y + Y offset [default: 0] + -a, --absolute-offset + Make the x and y offset be relative to the top left terminal corner. If not set, they are relative to the cursor's position. + -r, --recursive + Recurse down directories if passed one + -b, --blocks + Force block output + -n, --name + Output the name of the file before displaying + -t, --transparent + Display transparent images with transparent background + -f, --frame-rate + Play the gif at a given frame rate + -1, --once + Loop only once through the gif + -s, --static + Show only the first frame of the gif + -H, --help + Print help information + -V, --version + Print version information ``` diff --git a/src/config.rs b/src/config.rs index 0f171ea..148b565 100644 --- a/src/config.rs +++ b/src/config.rs @@ -24,8 +24,8 @@ impl<'a> Config<'a> { .collect(); let absolute_offset = matches.get_flag("absolute-offset"); - let x: u16 = matches.get_one("x").cloned().unwrap_or(0); - let y: i16 = matches.get_one("y").cloned().unwrap_or(0); + let x: u16 = matches.get_one("x").cloned().expect("X offset must be present"); + let y: i16 = matches.get_one("y").cloned().expect("Y offset must be present"); let use_blocks = matches.get_flag("blocks"); let transparent = matches.get_flag("transparent"); diff --git a/src/main.rs b/src/main.rs index a24da29..56c0fc8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,12 +36,14 @@ fn main() { .arg( Arg::new("x") .short('x') + .default_value("0") .value_parser(value_parser!(u16)) .help("X offset"), ) .arg( Arg::new("y") .short('y') + .default_value("0") .value_parser(value_parser!(i16)) .help("Y offset"), ) @@ -50,7 +52,7 @@ fn main() { .short('a') .long("absolute-offset") .action(SetTrue) - .help("Make the x and y offset be relative to the top left terminal corner. If false, they are relative to the cursor's position. Defaults to false."), + .help("Make the x and y offset be relative to the top left terminal corner. If not set, they are relative to the cursor's position."), ) .arg( Arg::new("recursive") From ad12cc4308469bf55b9c8a8a774137674cdf8c4e Mon Sep 17 00:00:00 2001 From: Atanas Yankov Date: Sun, 23 Oct 2022 11:09:00 +0300 Subject: [PATCH 4/4] Fmt --- src/config.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/config.rs b/src/config.rs index 148b565..7535659 100644 --- a/src/config.rs +++ b/src/config.rs @@ -24,8 +24,14 @@ impl<'a> Config<'a> { .collect(); let absolute_offset = matches.get_flag("absolute-offset"); - let x: u16 = matches.get_one("x").cloned().expect("X offset must be present"); - let y: i16 = matches.get_one("y").cloned().expect("Y offset must be present"); + let x: u16 = matches + .get_one("x") + .cloned() + .expect("X offset must be present"); + let y: i16 = matches + .get_one("y") + .cloned() + .expect("Y offset must be present"); let use_blocks = matches.get_flag("blocks"); let transparent = matches.get_flag("transparent");