From 61ef82ec2b2ca396667f92a4e5c6ceb729c42086 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Sun, 15 May 2016 17:11:27 +0300 Subject: Port to MinGW --- butl/pager.cxx | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'butl/pager.cxx') 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 // close(), STDOUT_FILENO # include // ioctl() + +# include +# include // this_thread::sleep_for() #else # ifndef WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN # endif -# include // GetConsoleScreenBufferInfo(), GetStdHandle() -# include // _close() +# include // GetConsoleScreenBufferInfo(), GetStdHandle(), + // Sleep() +# include // _close() #endif -#include -#include // this_thread::sleep_for() -#include // strchr() +#include // strchr() #include using namespace std; @@ -44,7 +46,9 @@ namespace butl col = static_cast (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 (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 -- cgit v1.1