Skip to content

Commit

Permalink
Fix bug with redirecting/piping output
Browse files Browse the repository at this point in the history
  • Loading branch information
danny-burrows committed Dec 29, 2023
1 parent 1510245 commit 23d4065
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/terminal.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <unistd.h>

#include "terminal.h"

#define TERM_PADDING_X 8
Expand All @@ -12,6 +14,13 @@ void get_term_size(int *restrict width, int *restrict height) {
}

void get_ideal_image_size(int *restrict width, int *restrict height, const int image_width, const int image_height, bool squashing_enabled) {
// Check if output is not a terminal (if not we're probably piping the output) and thus return original size.
if (isatty(STDOUT_FILENO) == false) {
*width = image_width;
*height = image_height;
return;
}

*width = squashing_enabled ? image_width * 2 : image_width; // <- NOTE: This is to offset narrow chars.
*height = image_height;
double aspect_ratio = (double)*width / (double)*height;
Expand Down Expand Up @@ -40,4 +49,4 @@ void get_ideal_image_size(int *restrict width, int *restrict height, const int i
}
}

}
}

0 comments on commit 23d4065

Please sign in to comment.