From b2a83ba28ef61f5c6aa32f3d81233e95cab1f3b0 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 14 Jul 2020 14:09:00 +0200 Subject: Override TERM environment variable on Windows when running less --- libbutl/pager.cxx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/libbutl/pager.cxx b/libbutl/pager.cxx index a3eb5e1..44aa83e 100644 --- a/libbutl/pager.cxx +++ b/libbutl/pager.cxx @@ -124,6 +124,18 @@ namespace butl args.push_back (nullptr); + // On Windows if we are using default less, then set the TERM environment + // variable to cygwin. Failed that, some environments like git-bash may + // set it to some strange values (like xterm-256color) which confuses + // less. + // + const char* env[] = {nullptr, nullptr}; + +#ifdef _WIN32 + if (pager == nullptr) + env[0] = "TERM=cygwin"; +#endif + if (verbose) { for (const char* const* p (args.data ()); *p != nullptr; ++p) @@ -151,7 +163,9 @@ namespace butl // try { - p_ = process (args.data (), -1); // Redirect child's STDIN to a pipe. + // Redirect child's STDIN to a pipe. + // + p_ = process (args.data (), -1, 1, 2, nullptr /* cwd */, env); // Wait a bit and see if the pager has exited before reading anything // (e.g., because exec() couldn't find the program). If you know a -- cgit v1.1