mirror of
https://github.com/p-ranav/indicators.git
synced 2025-12-14 03:00:20 +08:00
Fix Windows support for DynamicProgress
This commit is contained in:
@@ -26,12 +26,39 @@ static inline void show_console_cursor(bool const show) {
|
|||||||
SetConsoleCursorInfo(out, &cursorInfo);
|
SetConsoleCursorInfo(out, &cursorInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void erase_line() {
|
||||||
|
auto hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
|
if (!hStdout)
|
||||||
|
return;
|
||||||
|
|
||||||
|
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
|
||||||
|
GetConsoleScreenBufferInfo(hStdout, &csbiInfo);
|
||||||
|
|
||||||
|
COORD cursor;
|
||||||
|
|
||||||
|
cursor.X = 0;
|
||||||
|
cursor.Y = csbiInfo.dwCursorPosition.Y;
|
||||||
|
|
||||||
|
DWORD count = 0;
|
||||||
|
|
||||||
|
FillConsoleOutputCharacterA(hStdout, ' ', csbiInfo.dwSize.X, cursor, &count);
|
||||||
|
|
||||||
|
FillConsoleOutputAttribute(hStdout, csbiInfo.wAttributes, csbiInfo.dwSize.X,
|
||||||
|
cursor, &count);
|
||||||
|
|
||||||
|
SetConsoleCursorPosition(hStdout, cursor);
|
||||||
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
static inline void show_console_cursor(bool const show) {
|
static inline void show_console_cursor(bool const show) {
|
||||||
std::fputs(show ? "\033[?25h" : "\033[?25l", stdout);
|
std::fputs(show ? "\033[?25h" : "\033[?25l", stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void erase_line() {
|
||||||
|
std::fputs("\r\033[K", stdout);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // namespace indicators
|
} // namespace indicators
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
#include <indicators/color.hpp>
|
#include <indicators/color.hpp>
|
||||||
#include <indicators/setting.hpp>
|
#include <indicators/setting.hpp>
|
||||||
|
#include <indicators/cursor_control.hpp>
|
||||||
|
#include <indicators/cursor_movement.hpp>
|
||||||
#include <indicators/details/stream_helper.hpp>
|
#include <indicators/details/stream_helper.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
@@ -83,8 +85,11 @@ public:
|
|||||||
if (hide_bar_when_complete) {
|
if (hide_bar_when_complete) {
|
||||||
// Hide completed bars
|
// Hide completed bars
|
||||||
if (started_) {
|
if (started_) {
|
||||||
for (size_t i = 0; i < incomplete_count_; ++i)
|
for (size_t i = 0; i < incomplete_count_; ++i) {
|
||||||
std::cout << "\033[A\r\033[K" << std::flush;
|
move_up(1);
|
||||||
|
erase_line();
|
||||||
|
std::cout << std::flush;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
incomplete_count_ = 0;
|
incomplete_count_ = 0;
|
||||||
for (auto &bar : bars_) {
|
for (auto &bar : bars_) {
|
||||||
@@ -98,10 +103,8 @@ public:
|
|||||||
started_ = true;
|
started_ = true;
|
||||||
} else {
|
} else {
|
||||||
// Don't hide any bars
|
// Don't hide any bars
|
||||||
if (started_) {
|
if (started_)
|
||||||
for (size_t i = 0; i < total_count_; ++i)
|
move_up(static_cast<int>(total_count_));
|
||||||
std::cout << "\x1b[A";
|
|
||||||
}
|
|
||||||
for (auto &bar : bars_) {
|
for (auto &bar : bars_) {
|
||||||
bar.get().print_progress(true);
|
bar.get().print_progress(true);
|
||||||
std::cout << "\n";
|
std::cout << "\n";
|
||||||
|
|||||||
Reference in New Issue
Block a user