From c03b40a2808308fb1d10b0934156699f2a036caa Mon Sep 17 00:00:00 2001 From: acxz <17132214+acxz@users.noreply.github.com> Date: Sun, 27 Feb 2022 15:42:10 -0500 Subject: [PATCH 1/2] add option for height offset in vertical scaling this accounts for used spaced in the terminal such as a prompt --- completion/_catimg | 1 + man/catimg.1 | 5 ++++- src/catimg.c | 9 +++++++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/completion/_catimg b/completion/_catimg index 6e41580..b6e72bf 100644 --- a/completion/_catimg +++ b/completion/_catimg @@ -40,6 +40,7 @@ _arguments \ '-c[convert colors to a restricted palette]' \ '-h[display a help message]' \ '-H[specify the height of the displayed image]' \ + '-o[specify the height offset of the displayed image]' \ '-l[specify the amount of loops that catimg should repeat a GIF]' \ '-r[force the resolution of the image]: :->resolution' \ '-t[disable true color and use 256 color instead]' \ diff --git a/man/catimg.1 b/man/catimg.1 index 073c0e3..5db21fc 100644 --- a/man/catimg.1 +++ b/man/catimg.1 @@ -5,7 +5,7 @@ catimg \- fast image printing in to your terminal .SH SYNOPSIS .B catimg -[\fB-hct\fP] [\fB-w width\fP | \fB-H height\fP] [\fB-l loops\fP] [\fB-r resolution\fP] image +[\fB-hct\fP] [\fB-w width\fP | \fB-H height\fP] [\fB-o height offset\fP] [\fB-l loops\fP] [\fB-r resolution\fP] image .SH DESCRIPTION .B catimg @@ -22,6 +22,9 @@ Prints a help message \fB\-H\fR HEIGHT Specify the height of the displayed image, passing '0' will use terminal height. .TP +\fB\-o\fR HEIGHT_OFFSET +Specify the height offset of the displayed image, passing '0' will use no terminal height offset. +.TP \fB\-l\fR LOOPS Specify the amount of loops that catimg should repeat a GIF. A value of 1 means that the GIF will be displayed twice. A negative value implies infinity. .TP diff --git a/src/catimg.c b/src/catimg.c index 962ce5c..1e4e604 100644 --- a/src/catimg.c +++ b/src/catimg.c @@ -11,6 +11,7 @@ " -h: Displays this message\n" \ " -w: Terminal width/columns by default\n" \ " -H: Terminal height/row by default\n" \ + " -o: Terminal height offset by default\n" \ " -l: Loops are only useful with GIF files. A value of 1 means that the GIF will " \ "be displayed twice because it loops once. A negative value means infinite " \ "looping\n" \ @@ -72,13 +73,14 @@ int main(int argc, char *argv[]) opterr = 0; uint32_t cols = 0, rows = 0, precision = 0; + uint32_t height_offset = 0; // To account for the prompt in vertical scaling uint32_t max_cols = 0, max_rows = 0; uint8_t convert = 0; uint8_t true_color = 1; uint8_t adjust_to_height = 0, adjust_to_width = 0; float scale_cols = 0, scale_rows = 0; - while ((c = getopt (argc, argv, "H:w:l:r:hct")) != -1) + while ((c = getopt (argc, argv, "H:o:w:l:r:hct")) != -1) switch (c) { case 'H': rows = strtol(optarg, &num, 0); @@ -90,6 +92,9 @@ int main(int argc, char *argv[]) } adjust_to_height = 1; break; + case 'o': + height_offset = strtol(optarg, &num, 0); + break; case 'w': cols = strtol(optarg, &num, 0) >> 1; if (adjust_to_height) { @@ -138,7 +143,7 @@ int main(int argc, char *argv[]) // if precision is 2 we can use the terminal full width/height. Otherwise we can only use half max_cols = terminal_columns() / (2 / precision); - max_rows = terminal_rows() * precision; + max_rows = (terminal_rows() - height_offset) * precision; if (strcmp(file, "-") == 0) { img_load_from_stdin(&img); From b78a726b76ec15cc8d26ea05a084766c6a12b77a Mon Sep 17 00:00:00 2001 From: acxz <17132214+acxz@users.noreply.github.com> Date: Mon, 28 Feb 2022 10:30:02 -0500 Subject: [PATCH 2/2] height_offset defaulted to 1 most prompts are size 1 --- src/catimg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/catimg.c b/src/catimg.c index 1e4e604..fe4f7a8 100644 --- a/src/catimg.c +++ b/src/catimg.c @@ -11,7 +11,7 @@ " -h: Displays this message\n" \ " -w: Terminal width/columns by default\n" \ " -H: Terminal height/row by default\n" \ - " -o: Terminal height offset by default\n" \ + " -o: Terminal height offset by default 1\n" \ " -l: Loops are only useful with GIF files. A value of 1 means that the GIF will " \ "be displayed twice because it loops once. A negative value means infinite " \ "looping\n" \ @@ -73,7 +73,7 @@ int main(int argc, char *argv[]) opterr = 0; uint32_t cols = 0, rows = 0, precision = 0; - uint32_t height_offset = 0; // To account for the prompt in vertical scaling + uint32_t height_offset = 1; // To account for the prompt in vertical scaling uint32_t max_cols = 0, max_rows = 0; uint8_t convert = 0; uint8_t true_color = 1;