Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 152b76f

Browse files
authored
fix: progress bar on CMD (#1609)
1 parent 43fbc52 commit 152b76f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

engine/cli/utils/download_progress.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,20 @@ bool DownloadProgress::Connect(const std::string& host, int port) {
3636

3737
bool DownloadProgress::Handle(const DownloadType& event_type) {
3838
assert(!!ws_);
39+
#if defined(_WIN32)
40+
HANDLE h_out = GetStdHandle(STD_OUTPUT_HANDLE);
41+
DWORD dw_original_out_mode = 0;
42+
if (h_out != INVALID_HANDLE_VALUE) {
43+
GetConsoleMode(h_out, &dw_original_out_mode);
44+
45+
// Enable ANSI escape code processing
46+
DWORD dw_requested_out_mode =
47+
dw_original_out_mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING;
48+
if (!SetConsoleMode(h_out, dw_requested_out_mode)) {
49+
SetConsoleMode(h_out, dw_original_out_mode);
50+
}
51+
}
52+
#endif
3953
std::unordered_map<std::string, uint64_t> totals;
4054
status_ = DownloadStatus::DownloadStarted;
4155
std::unique_ptr<indicators::DynamicProgress<indicators::ProgressBar>> bars;
@@ -124,6 +138,11 @@ bool DownloadProgress::Handle(const DownloadType& event_type) {
124138
ws_->dispatch(handle_message);
125139
}
126140
indicators::show_console_cursor(true);
141+
#if defined(_WIN32)
142+
if (dw_original_out_mode != 0 && h_out != INVALID_HANDLE_VALUE) {
143+
SetConsoleMode(h_out, dw_original_out_mode);
144+
}
145+
#endif
127146
if (status_ == DownloadStatus::DownloadError)
128147
return false;
129148
return true;

0 commit comments

Comments
 (0)