Skip to content

Commit 43ea953

Browse files
committed
fix(cli): restore build progress rendering
2 parents 035fb6d + 2305e64 commit 43ea953

9 files changed

Lines changed: 55 additions & 263 deletions

File tree

‎include/vix/cli/util/NetworkProgress.hpp‎

Lines changed: 0 additions & 55 deletions
This file was deleted.

‎src/commands/BuildCommand.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6198,7 +6198,8 @@ namespace vix::commands::BuildCommand
61986198

61996199
const bool legacyBuildQuiet =
62006200
opt_.quiet ||
6201-
!showRawBuildOutput;
6201+
(liveBuild &&
6202+
!showRawBuildOutput);
62026203

62036204
const process::ExecResult r =
62046205
measurePhase(

‎src/commands/InstallCommand.cpp‎

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include <vix/utils/Env.hpp>
2828
#include <vix/cli/util/Semver.hpp>
2929
#include <vix/cli/util/GitProgress.hpp>
30-
#include <vix/cli/util/NetworkProgress.hpp>
3130
#include <vix/cli/util/ProjectMutation.hpp>
3231

3332
#include <nlohmann/json.hpp>
@@ -464,11 +463,24 @@ namespace vix::commands
464463
std::vector<std::string> args,
465464
const fs::path &cwd);
466465

466+
static bool install_progress_is_tty()
467+
{
468+
#ifdef _WIN32
469+
if (_isatty(_fileno(stdout)) == 0)
470+
return false;
471+
#else
472+
if (::isatty(STDOUT_FILENO) == 0)
473+
return false;
474+
#endif
475+
const char *term = std::getenv("TERM");
476+
return (!term || std::string_view(term) != "dumb") && std::getenv("NO_COLOR") == nullptr;
477+
}
478+
467479
class GitInstallProgress
468480
{
469481
public:
470482
GitInstallProgress(std::string dependency, std::size_t packageIndex, std::size_t packageCount)
471-
: dependency_(std::move(dependency)), packageIndex_(packageIndex), packageCount_(packageCount), parser_([this](const auto &event)
483+
: dependency_(std::move(dependency)), packageIndex_(packageIndex), packageCount_(packageCount), started_(std::chrono::steady_clock::now()), tty_(install_progress_is_tty()), parser_([this](const auto &event)
472484
{ render(event); }) {}
473485

474486
void push(std::string_view chunk) { parser_.push(chunk); }
@@ -484,30 +496,50 @@ namespace vix::commands
484496
void finish()
485497
{
486498
parser_.finish();
487-
progress_.stop();
499+
if (visible_)
500+
{
501+
std::cout << "\r\033[2K" << std::flush;
502+
visible_ = false;
503+
}
488504
}
489505

490506
private:
491507
void render(const vix::cli::util::GitProgressEvent &event)
492508
{
509+
// CI output must remain useful without terminal control sequences.
510+
const auto now = std::chrono::steady_clock::now();
511+
// The first measurable Git event is deliberately not delayed. The
512+
// old delay made a real remote operation look hung.
513+
if (visible_ && event.phase == lastPhase_ && now - lastRender_ < std::chrono::milliseconds(100))
514+
return;
493515
std::ostringstream line;
494-
line << event.phase;
516+
line << " " << CYAN << "•" << RESET << " " << CYAN << BOLD << dependency_ << RESET;
495517
if (packageCount_ > 1)
496-
line << " " << dependency_ << " (" << (packageIndex_ + 1) << "/" << packageCount_ << " packages)";
497-
else
498-
line << " " << dependency_;
518+
line << " " << GRAY << "(" << (packageIndex_ + 1) << "/" << packageCount_ << " packages)" << RESET;
519+
line << " " << GRAY << event.phase;
499520
if (event.percent)
500521
line << " " << *event.percent << "%";
501522
if (!event.transferred.empty())
502523
line << " " << event.transferred;
503524
if (!event.speed.empty())
504525
line << " " << event.speed;
505-
progress_.update(line.str());
526+
line << RESET;
527+
if (tty_)
528+
std::cout << "\r\033[2K" << line.str() << std::flush;
529+
else
530+
std::cout << dependency_ << ": " << event.phase
531+
<< (event.percent ? std::string(" ") + std::to_string(*event.percent) + "%" : "") << "\n"
532+
<< std::flush;
533+
visible_ = true;
534+
lastRender_ = now;
535+
lastPhase_ = event.phase;
506536
}
507537
std::string dependency_;
508538
std::size_t packageIndex_{};
509539
std::size_t packageCount_{};
510-
vix::cli::util::NetworkProgress progress_{dependency_};
540+
std::chrono::steady_clock::time_point started_, lastRender_{};
541+
bool tty_{false}, visible_{false};
542+
std::string lastPhase_;
511543
vix::cli::util::GitProgressParser parser_;
512544
};
513545

‎src/commands/RegistryCommand.cpp‎

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
*/
1414
#include <vix/cli/commands/RegistryCommand.hpp>
1515
#include <vix/cli/util/Shell.hpp>
16-
#include <vix/cli/util/NetworkProgress.hpp>
1716
#include <vix/cli/util/Ui.hpp>
1817
#include <vix/cli/Style.hpp>
1918
#include <vix/utils/Env.hpp>
@@ -82,12 +81,9 @@ namespace vix::commands
8281
return name;
8382
}
8483

85-
static int normalize_registry_worktree(const fs::path &dir, bool quiet,
86-
vix::cli::util::NetworkProgress *progress = nullptr)
84+
static int normalize_registry_worktree(const fs::path &dir, bool quiet)
8785
{
88-
if (progress)
89-
progress->phase("Fetching registry index");
90-
else if (!quiet)
86+
if (!quiet)
9187
step("fetching origin (prune)...");
9288
{
9389
const std::string cmd =
@@ -97,9 +93,7 @@ namespace vix::commands
9793
return rc;
9894
}
9995

100-
if (progress)
101-
progress->phase("Preparing registry index");
102-
else if (!quiet)
96+
if (!quiet)
10397
step("checking out main...");
10498
{
10599
const std::string cmd =
@@ -109,7 +103,7 @@ namespace vix::commands
109103
return rc;
110104
}
111105

112-
if (!quiet && !progress)
106+
if (!quiet)
113107
step("resetting to origin/main...");
114108
{
115109
const std::string cmd =
@@ -191,50 +185,43 @@ namespace vix::commands
191185
vix::cli::util::warn_line(std::cerr, "Tip: re-run with VIX_DEBUG=1 to see git output");
192186
};
193187

194-
vix::cli::util::NetworkProgress progress("registry");
195-
196188
if (!fs::exists(dir))
197189
{
198190
if (!quiet)
199-
progress.phase("Connecting to registry");
191+
step("cloning index (depth=1)...");
200192
const std::string cmd =
201193
"git clone -q --depth 1 " + registry_repo_url() + " " + dir.string();
202194

203195
const int rc = git_run(cmd);
204196
if (rc != 0)
205197
{
206-
progress.failure();
207198
print_sync_failure();
208199
return rc;
209200
}
210201

211-
const int nrc = normalize_registry_worktree(
212-
dir, quiet, quiet ? nullptr : &progress);
202+
const int nrc = normalize_registry_worktree(dir, quiet);
213203
if (nrc != 0)
214204
{
215-
progress.failure();
216205
print_sync_failure();
217206
return nrc;
218207
}
219208

220209
if (!quiet)
221-
progress.success("Registry synced: " + dir.string());
210+
vix::cli::util::ok_line(std::cout, "registry synced: " + dir.string());
222211
return 0;
223212
}
224213

225214
if (!quiet)
226-
progress.phase("Fetching registry index");
227-
const int nrc = normalize_registry_worktree(
228-
dir, quiet, quiet ? nullptr : &progress);
215+
step("normalizing worktree...");
216+
const int nrc = normalize_registry_worktree(dir, quiet);
229217
if (nrc != 0)
230218
{
231-
progress.failure();
232219
print_sync_failure();
233220
return nrc;
234221
}
235222

236223
if (!quiet)
237-
progress.success("Registry synced: " + dir.string());
224+
vix::cli::util::ok_line(std::cout, "registry synced: " + dir.string());
238225
return 0;
239226
}
240227
} // namespace

‎src/util/NetworkProgress.cpp‎

Lines changed: 0 additions & 104 deletions
This file was deleted.

0 commit comments

Comments
 (0)