--- trunk/src/utils/ProgressBar.cpp 2010/04/08 19:49:38 1432 +++ branches/development/src/utils/ProgressBar.cpp 2013/02/20 15:39:39 1850 @@ -35,15 +35,30 @@ * * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). - * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). - * [4] Vardeman, Stocker & Gezelter, in progress (2010). + * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). + * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). + * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). */ #include +#include + +#ifdef _MSC_VER +#include +#include +#include +#define isatty _isatty +#define fileno _fileno +#else +#include #include +#include +#endif + #ifdef IS_MPI #include #endif + #include "utils/ProgressBar.hpp" using namespace std; @@ -81,9 +96,19 @@ namespace OpenMD { // only do the progress bar if we are actually running in a tty: if (isatty(fileno(stdout)) && (getenv("SGE_TASK_ID")==NULL)) { // get the window width: + +#ifdef _MSC_VER + CONSOLE_SCREEN_BUFFER_INFO csbi; + HANDLE hConsole = GetStdHandle( STD_OUTPUT_HANDLE ); + int ret = GetConsoleScreenBufferInfo(hConsole, &csbi); + if(ret) { + width = csbi.dwSize.X - 1; + } +#else struct winsize w; ioctl(fileno(stdout), TIOCGWINSZ, &w); width = w.ws_col; +#endif // handle the case when the width is returned as a nonsensical value. if (width <= 0) width = 80; @@ -110,8 +135,13 @@ namespace OpenMD { struct tm * ender = localtime(&end_); char buffer[22]; strftime(buffer, 22, "%a %b %d @ %I:%M %p", ender); - + +#ifdef _MSC_VER + csbi.dwCursorPosition.X = 0; + SetConsoleCursorPosition(hConsole, csbi.dwCursorPosition); +#else cout << '\r'; +#endif cout.width(3); cout << right << int(percent); cout.width(3);