From 4ac6eb96d87f6d38a5ea42a046e5fa86f9655d65 Mon Sep 17 00:00:00 2001 From: Bob Polis Date: Mon, 29 Jan 2024 16:00:09 +0100 Subject: [PATCH] Get terminal settings before reconnecting stdout --- src/conversion.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/conversion.cpp b/src/conversion.cpp index 8ccca41..1209147 100644 --- a/src/conversion.cpp +++ b/src/conversion.cpp @@ -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);