Skip to content

Commit b677f46

Browse files
committed
Show a progress bar when running the tests
1 parent 2bbab79 commit b677f46

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

docx2md.php

+19-3
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,21 @@ private function cleanData($data)
660660
return $cleanedData;
661661
}
662662

663+
/**
664+
* Generate a progress bar based on the input parameters
665+
*
666+
* @param integer $done
667+
* @param integer $total
668+
* @return string
669+
*/
670+
private function progress($done, $total)
671+
{
672+
$perc = floor(($done / $total) * 100);
673+
$left = 100 - $perc;
674+
675+
return sprintf("\033[0G\033[2K[%'={$perc}s>%-{$left}s] - {$perc}%% - {$done}/{$total}", '', '');
676+
}
677+
663678
/**
664679
* Test markdown converter
665680
*
@@ -672,14 +687,15 @@ private function runTests(array $args)
672687
$formatter = ' %s. %s' . self::WHITE . ': %s' . PHP_EOL;
673688
$output = self::WHITE;
674689

675-
echo 'Running tests...';
676-
677690
$files = glob("{$src}/docx/*.docx");
678691
$size = sizeof($files);
679692
$charCount = 0;
680693

681694
foreach ($files as $n => $file1) {
682695
$n++;
696+
697+
echo $this->progress($n, $size);
698+
683699
$file2 = basename($file1, '.docx') . '.md';
684700

685701
$markdown = $this->docx2md(array('', '-i', $file1, $file2), true)
@@ -706,7 +722,7 @@ private function runTests(array $args)
706722
$output .= $sprintf;
707723
}
708724

709-
echo ' finished' . ' ' . self::GREEN . html_entity_decode('√') . ' ' . self::GREEN . PHP_EOL . rtrim($output, PHP_EOL);
725+
echo PHP_EOL . rtrim($output, PHP_EOL);
710726

711727
if ($args) {
712728
// If performing conversion after running tests, print a separator

0 commit comments

Comments
 (0)