From 14f0c215ebd552f248406b55af96f31de8462784 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 28 May 2021 14:09:32 -0400 Subject: [PATCH] make console detection smarter and don't use a pager at all with OpenMPI --- src/lammps.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/lammps.cpp b/src/lammps.cpp index a218b9e08a..131d2e66f6 100644 --- a/src/lammps.cpp +++ b/src/lammps.cpp @@ -55,6 +55,10 @@ #include #include +#if !defined(_WIN32) +#include // for isatty() +#endif + #include "lmpinstalledpkgs.h" #include "lmpgitversion.h" @@ -1114,12 +1118,24 @@ void _noopt LAMMPS::help() FILE *fp = screen; const char *pager = nullptr; - // if output is "stdout", use a pipe to a pager for paged output. + // if output is a console, use a pipe to a pager for paged output. // this will avoid the most important help text to rush past the // user. scrollback buffers are often not large enough. this is most // beneficial to windows users, who are not used to command line. - if (fp == stdout) { +#if defined(_WIN32) + int use_pager = _isatty(fileno(fp)); +#else + int use_pager = isatty(fileno(fp)); +#endif + + // cannot use this with OpenMPI since its console is non-functional + +#if defined(OPEN_MPI) + use_pager = 0; +#endif + + if (use_pager) { pager = getenv("PAGER"); if (pager == nullptr) pager = "more"; #if defined(_WIN32) @@ -1130,7 +1146,7 @@ void _noopt LAMMPS::help() // reset to original state, if pipe command failed if (fp == nullptr) { - fp = stdout; + fp = screen; pager = nullptr; } }