Skip to content

Commit

Permalink
fix: progress bar on CMD (#1609)
Browse files Browse the repository at this point in the history
  • Loading branch information
vansangpfiev authored Nov 1, 2024
1 parent 43fbc52 commit 152b76f
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions engine/cli/utils/download_progress.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ bool DownloadProgress::Connect(const std::string& host, int port) {

bool DownloadProgress::Handle(const DownloadType& event_type) {
assert(!!ws_);
#if defined(_WIN32)
HANDLE h_out = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD dw_original_out_mode = 0;
if (h_out != INVALID_HANDLE_VALUE) {
GetConsoleMode(h_out, &dw_original_out_mode);

// Enable ANSI escape code processing
DWORD dw_requested_out_mode =
dw_original_out_mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING;
if (!SetConsoleMode(h_out, dw_requested_out_mode)) {
SetConsoleMode(h_out, dw_original_out_mode);
}
}
#endif
std::unordered_map<std::string, uint64_t> totals;
status_ = DownloadStatus::DownloadStarted;
std::unique_ptr<indicators::DynamicProgress<indicators::ProgressBar>> bars;
Expand Down Expand Up @@ -124,6 +138,11 @@ bool DownloadProgress::Handle(const DownloadType& event_type) {
ws_->dispatch(handle_message);
}
indicators::show_console_cursor(true);
#if defined(_WIN32)
if (dw_original_out_mode != 0 && h_out != INVALID_HANDLE_VALUE) {
SetConsoleMode(h_out, dw_original_out_mode);
}
#endif
if (status_ == DownloadStatus::DownloadError)
return false;
return true;
Expand Down

0 comments on commit 152b76f

Please sign in to comment.