Get terminal settings before reconnecting stdout

This commit is contained in:
Bob Polis 2024-01-29 16:00:09 +01:00
parent 02a5601466
commit 4ac6eb96d8

View File

@ -7,7 +7,7 @@
#include "pixels.hpp"
static std::string resize_str() {
sc::term t {STDERR_FILENO};
sc::term t {STDOUT_FILENO};
int cols = t.cols() - 1;
int rows = t.rows() * 2 - 4;
std::ostringstream oss;
@ -24,11 +24,12 @@ void convert(const std::string& path) { // try to convert to ppm using ImageMagi
throw std::runtime_error {"could not fork"};
case 0: { // child
std::string resize {resize_str()};
throw_if_min1(dup2(pfd[1], STDOUT_FILENO));
throw_if_min1(close(pfd[0]));
throw_if_min1(close(pfd[1]));
std::string resize {resize_str()};
int res = execlp("magick", "magick", path.c_str(), "-resize", resize.c_str(), "ppm:-", nullptr);
if (res == -1) { // probably "magick" not found, try "convert"
res = execlp("convert", "convert", path.c_str(), "-resize", resize.c_str(), "ppm:-", nullptr);