diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2016-05-15 17:11:27 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2016-05-31 18:42:55 +0300 |
commit | 61ef82ec2b2ca396667f92a4e5c6ceb729c42086 (patch) | |
tree | 57ca5868483f361a9da28bbfc32f0cc838787b3e /butl/pager.cxx | |
parent | 79bb0331cb93a736193e733b5ae26d040931a1aa (diff) |
Port to MinGW
Diffstat (limited to 'butl/pager.cxx')
-rw-r--r-- | butl/pager.cxx | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/butl/pager.cxx b/butl/pager.cxx index 4d0d9eb..9999bb0 100644 --- a/butl/pager.cxx +++ b/butl/pager.cxx @@ -7,17 +7,19 @@ #ifndef _WIN32 # include <unistd.h> // close(), STDOUT_FILENO # include <sys/ioctl.h> // ioctl() + +# include <chrono> +# include <thread> // this_thread::sleep_for() #else # ifndef WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN # endif -# include <windows.h> // GetConsoleScreenBufferInfo(), GetStdHandle() -# include <io.h> // _close() +# include <windows.h> // GetConsoleScreenBufferInfo(), GetStdHandle(), + // Sleep() +# include <io.h> // _close() #endif -#include <chrono> -#include <thread> // this_thread::sleep_for() -#include <cstring> // strchr() +#include <cstring> // strchr() #include <system_error> using namespace std; @@ -44,7 +46,9 @@ namespace butl col = static_cast<size_t> (w.ws_col); # endif #else -#error TODO: needs testing + // This works properly on PowerShell, while for the regular console + // (cmd.exe) it always returns 80 columns. + // CONSOLE_SCREEN_BUFFER_INFO w; if (GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE), &w)) col = static_cast<size_t> (w.srWindow.Right - w.srWindow.Left + 1); @@ -70,7 +74,8 @@ namespace butl prompt = "-Ps" + name + " (press q to quit, h for help)"; args.push_back ("less"); - args.push_back ("-R"); // Handle ANSI color. + args.push_back ("-R"); // Handle ANSI color. + args.push_back (prompt.c_str ()); } @@ -117,13 +122,19 @@ namespace butl // approach doesn't work; the pipe is buffered and therefore is always // ready for writing). // + // MINGW GCC 4.9 doesn't implement this_thread so use Win32 Sleep(). + // +#ifndef _WIN32 this_thread::sleep_for (chrono::milliseconds (50)); +#else + Sleep (50); +#endif bool r; if (p_.try_wait (r)) { #ifndef _WIN32 - ::close (p_.out_fd); + close (p_.out_fd); #else _close (p_.out_fd); #endif |