From 1db58d93389f36cb1abe1720108105b807c48303 Mon Sep 17 00:00:00 2001 From: Philip Miller Date: Wed, 6 Feb 2019 15:11:03 -0500 Subject: [PATCH] port to windows (VS 2015) and add CMakeLists.txt --- .gitignore | 2 ++ CMakeLists.txt | 15 +++++++++++++++ test.cpp | 8 ++++++++ tqdm.h | 7 ++++++- 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 CMakeLists.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2907da9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +_build/ +build/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..e89ba72 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,15 @@ +message(STATUS "reading ${CMAKE_CURRENT_LIST_FILE}") +project(tqdm_test) + +if (NOT DEFINED CMAKE_DEBUG_POSTFIX) + set(CMAKE_DEBUG_POSTFIX "_d") + include(GNUInstallDirs) +endif() + +add_executable(${PROJECT_NAME} "") +set_target_properties(${PROJECT_NAME} PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}) + +target_sources(${PROJECT_NAME} + PRIVATE + test.cpp + ) diff --git a/test.cpp b/test.cpp index fd96dff..c96596f 100644 --- a/test.cpp +++ b/test.cpp @@ -1,5 +1,13 @@ #include "tqdm.h" +#if _MSC_VER +#include +void usleep(int usec) +{ + std::this_thread::sleep_for(std::chrono::microseconds(usec)); +} +#endif + int main() { int N = 2000; diff --git a/tqdm.h b/tqdm.h index 665e251..5970e62 100644 --- a/tqdm.h +++ b/tqdm.h @@ -1,6 +1,11 @@ #ifndef TQDM_H #define TQDM_H +#if _MSC_VER +#include +#define isatty _isatty +#else #include +#endif #include #include #include @@ -160,7 +165,7 @@ class tqdm { } } for (int i = 0; i < ifills; i++) std::cout << bars[8]; - if (!in_screen and (curr != tot)) printf("%s",bars[(int)(8.0*(fills-ifills))]); + if (!in_screen && (curr != tot)) printf("%s",bars[(int)(8.0*(fills-ifills))]); for (int i = 0; i < width-ifills-1; i++) std::cout << bars[0]; printf("%s ", right_pad.c_str()); if (use_colors) printf("\033[1m\033[31m");