From daa6f31be394e307ecf833bc0164e811636cd476 Mon Sep 17 00:00:00 2001 From: Henner Zeller Date: Tue, 30 Nov 2021 12:33:17 -0800 Subject: [PATCH] Make it possible to partially specify the geometry. Issues #66 #64 --- README.md | 5 ++++- man/timg.1 | 8 +++++++- man/timg.1.md | 6 +++++- src/timg.cc | 13 ++++++++++--- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 335a599..47acd71 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,10 @@ grid uses `--grid=2` and is pixelated with `-pq`). ``` usage: timg [options] [...] Options: - -gx : Output geometry in character cells. Terminal is 160x50 + -gx : Output geometry in character cells. Partial geometry + leaving out one value -gx or -gx is possible, + the other value it then derived from the terminal size. + Default derived from terminal size is 160x50 -p : Pixelation: 'h' = half blocks 'q' = quarter blocks 'k' = kitty graphics 'i' = iTerm2 graphics Default: Auto-detect graphics, otherwise 'quarter'. diff --git a/man/timg.1 b/man/timg.1 index 0c2a757..e5d9061 100644 --- a/man/timg.1 +++ b/man/timg.1 @@ -1,4 +1,4 @@ -.\" Automatically generated by Pandoc 2.9.2.1 +.\" Automatically generated by Pandoc 2.13 .\" .TH "timg" "1" "Feb 2021" "" "" .hy @@ -52,6 +52,12 @@ By default, the size is determined by the available space in the terminal. The image is scaled to fit inside the available box to fill the screen; see \f[B]-W\f[R] if you want to fill the width. +.RS +.PP +It is possible to only partially specify the size before or after the +\f[B]x\f[R] separator, like \f[B]-gx\f[R] or \f[B]-gx\f[R]. +The corresponding other value is then derived from the terminal size. +.RE .TP \f[B]-p\f[R] \f[I]<[h|q|k|i]>\f[R], \f[B]--pixelation\f[R]=\f[I][h|q|k|i]\f[R] Choice for pixelation of the content. diff --git a/man/timg.1.md b/man/timg.1.md index 565f0b5..182c58d 100644 --- a/man/timg.1.md +++ b/man/timg.1.md @@ -42,11 +42,15 @@ these file decoders (GraphicsMagick or libav respectively). ## General Options **-g** *<width>x<height>* -: Output image to fit inside given geometry. By default, the size is +: Output image to fit inside given geometry. By default, the size is determined by the available space in the terminal. The image is scaled to fit inside the available box to fill the screen; see **-W** if you want to fill the width. + It is possible to only partially specify the size before or after the + **x** separator, like **-gx** or **-gx**. The corresponding + other value is then derived from the terminal size. + **-p** *<[h|q|k|i]>*, **-\-pixelation**=*[h|q|k|i]* : Choice for pixelation of the content. Value 'h' chooses unicode half block characters, while 'q' chooses quarter blocks. diff --git a/src/timg.cc b/src/timg.cc index 423512b..a9074c3 100644 --- a/src/timg.cc +++ b/src/timg.cc @@ -154,7 +154,10 @@ static int usage(const char *progname, ExitCode exit_code, fprintf(stderr, "usage: %s [options] <%s> [<%s>...]\n", progname, kFileType, kFileType); fprintf(stderr, "\e[1mOptions\e[0m:\n" - "\t-gx : Output geometry in character cells. Terminal is %dx%d\n" + "\t-gx : Output geometry in character cells. Partial geometry\n" + "\t leaving out one value -gx or -gx is possible,\n" + "\t the other value it then derived from the terminal size.\n" + "\t Default derived from terminal size is %dx%d\n" "\t-p : Pixelation: 'h' = half blocks 'q' = quarter blocks\n" "\t 'k' = kitty graphics 'i' = iTerm2 graphics\n" "\t Default: Auto-detect graphics, otherwise 'quarter'.\n" @@ -393,8 +396,10 @@ int main(int argc, char *argv[]) { long_options, &option_index))!=-1) { switch (opt) { case 'g': - if (sscanf(optarg, "%dx%d", - &geometry_width, &geometry_height) < 2) { + // Parse xHEIGHT, WIDTHx, WIDTHxHEIGHT + if ((sscanf(optarg, "x%d", &geometry_height) == 0) && + (sscanf(optarg, "%dx%d", + &geometry_width, &geometry_height) < 1)) { fprintf(stderr, "Invalid size spec '%s'", optarg); return usage(argv[0], ExitCode::kParameterError, geometry_width, geometry_height); @@ -812,6 +817,8 @@ int main(int argc, char *argv[]) { if (verbose) { fprintf(stderr, "Terminal cells: %dx%d cell-pixels: %dx%d\n", term.cols, term.rows, term.font_width_px, term.font_height_px); + fprintf(stderr, "Active Geometry: %dx%d\n", + geometry_width, geometry_height); const Duration d = end_show - start_show; const uint64_t written_bytes = sequencer.bytes_total() - sequencer.bytes_skipped();