Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option for height offset fix #67 #68

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions completion/_catimg
Original file line number Diff line number Diff line change
Expand Up @@ -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]' \
Expand Down
5 changes: 4 additions & 1 deletion man/catimg.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 7 additions & 2 deletions src/catimg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 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" \
Expand Down Expand Up @@ -72,13 +73,14 @@ int main(int argc, char *argv[])
opterr = 0;

uint32_t cols = 0, rows = 0, precision = 0;
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;
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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down