Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions src/Detection/CloneDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
use ShipMonk\CopyPasteDetector\Hashing\SubtreeHasher;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\StreamOutput;
use function array_push;
use function count;
use function max;
use function stream_isatty;
use function usort;

/**
Expand Down Expand Up @@ -159,18 +161,21 @@ private function createProgressBar(int $max): ?ProgressBar
}

$progressBar = new ProgressBar($this->output, $max);
$progressBar->setRedrawFrequency(max(1, (int) ($max / 50)));
$progressBar->minSecondsBetweenRedraws(0.1);
$progressBar->maxSecondsBetweenRedraws(1.0);

// Percentage Fill style - clean visual percentage
// Animate in place only on a TTY. --ansi forces "decorated" output even in
// CI, but the in-place redraw escape sequences aren't collapsed by CI log
// viewers, leaving every frame stacked. Off a TTY, redraw on its own line.
$interactive = $this->outputIsInteractive();
$progressBar->setOverwrite($interactive);
$progressBar->setRedrawFrequency(max(1, (int) ($max / ($interactive ? 50 : 10))));
$progressBar->minSecondsBetweenRedraws($interactive ? 0.1 : 1.0);
$progressBar->maxSecondsBetweenRedraws($interactive ? 1.0 : 10.0);

if ($this->output->isDebug() || $this->output->isVeryVerbose()) {
// Detailed format with ETA and memory
$progressBar->setFormat(
' %current%/%max% %bar% %percent:3s%% %remaining:-10s% %memory:6s%',
);
} else {
// Simpler format
$progressBar->setFormat(
' %current%/%max% %bar% %percent:3s%% %remaining:-10s%',
);
Expand All @@ -186,6 +191,17 @@ private function createProgressBar(int $max): ?ProgressBar
return $progressBar;
}

private function outputIsInteractive(): bool
{
$output = $this->output;

if ($output instanceof StreamOutput) {
return stream_isatty($output->getStream());
}

return false;
}

/**
* Build hash index from subtrees
*
Expand Down