Merge pull request #103 from atanunq/NOBLES5E/master

Support -x, -y, and --absolute-offset
This commit is contained in:
Atanas Yankov 2022-10-23 11:56:10 +03:00 committed by GitHub
commit d377402ab0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 69 additions and 19 deletions

View file

@ -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 <width> Resize the image to a provided width
-h, --height <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 <frames-per-second> 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 <width>
Resize the image to a provided width
-h, --height <height>
Resize the image to a provided height
-x <x>
X offset [default: 0]
-y <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 <frames-per-second>
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
```

View file

@ -23,19 +23,26 @@ impl<'a> Config<'a> {
.map(|s| s.as_str())
.collect();
let once = matches.get_flag("once");
let static_gif = matches.get_flag("static");
let loop_gif = files.len() <= 1 && !once;
let transparent = matches.get_flag("transparent");
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 use_blocks = matches.get_flag("blocks");
let transparent = matches.get_flag("transparent");
let viuer_config = ViuerConfig {
transparent,
width,
height,
absolute_offset: false,
x,
y,
transparent,
absolute_offset,
use_kitty: !use_blocks,
use_iterm: !use_blocks,
#[cfg(feature = "sixel")]
@ -48,6 +55,10 @@ impl<'a> Config<'a> {
.cloned()
.map(|f| Duration::from_secs_f32(1.0 / f as f32));
let once = matches.get_flag("once");
let static_gif = matches.get_flag("static");
let loop_gif = files.len() <= 1 && !once;
Config {
files,
loop_gif,

View file

@ -33,6 +33,27 @@ fn main() {
.value_parser(value_parser!(u32))
.help("Resize the image to a provided height"),
)
.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"),
)
.arg(
Arg::new("absolute-offset")
.short('a')
.long("absolute-offset")
.action(SetTrue)
.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")
.short('r')