diff options
Diffstat (limited to 'libbutl/pager.cxx')
-rw-r--r-- | libbutl/pager.cxx | 56 |
1 files changed, 21 insertions, 35 deletions
diff --git a/libbutl/pager.cxx b/libbutl/pager.cxx index a3eb5e1..e647948 100644 --- a/libbutl/pager.cxx +++ b/libbutl/pager.cxx @@ -1,9 +1,7 @@ // file : libbutl/pager.cxx -*- C++ -*- // license : MIT; see accompanying LICENSE file -#ifndef __cpp_modules_ts -#include <libbutl/pager.mxx> -#endif +#include <libbutl/pager.hxx> #include <errno.h> // E* @@ -14,46 +12,20 @@ # include <libbutl/win32-utility.hxx> #endif -#ifndef __cpp_lib_modules_ts #include <string> #include <vector> -#include <iostream> - +#include <cstddef> // size_t #include <cstring> // strchr() #include <utility> // move() + #ifndef _WIN32 # include <chrono> # include <thread> // this_thread::sleep_for() #endif -#endif - -// Other includes. - -#ifdef __cpp_modules_ts -module butl.pager; - -// Only imports additional to interface. -#ifdef __clang__ -#ifdef __cpp_lib_modules_ts -import std.core; -import std.io; -#endif -import butl.process; -import butl.fdstream; -#endif - -#ifndef _WIN32 -import std.threading; -#endif -import butl.utility; // operator<<(ostream, exception), throw_generic_error() -import butl.optional; -import butl.fdstream; // fdclose() -#else -#include <libbutl/utility.mxx> -#include <libbutl/optional.mxx> -#include <libbutl/fdstream.mxx> -#endif +#include <libbutl/utility.hxx> +#include <libbutl/optional.hxx> +#include <libbutl/fdstream.hxx> using namespace std; @@ -124,6 +96,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 +135,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 |