Skip to content

Commit

Permalink
Merge pull request #6 from cs278/fix-output
Browse files Browse the repository at this point in the history
Fix output
  • Loading branch information
cs278 authored Nov 5, 2020
2 parents 4c761fa + 8e4a363 commit f439c98
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/AuditCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
use Composer\Command\BaseCommand;
use Composer\Package\PackageInterface;
use Composer\Semver\Semver;
use Symfony\Component\Console\Cursor;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Yaml\Yaml;

Expand Down Expand Up @@ -129,6 +131,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
}

self::clearLine(
$output instanceof ConsoleOutputInterface
? $output->getErrorOutput()
: $output
);

if ($advisories !== []) {
// Advise the user of the advisories.
$totalAdvisories = array_sum(array_map(static function (array $packageAdvisories): int {
Expand Down Expand Up @@ -224,4 +232,20 @@ private static function formatHyperlink(OutputInterface $output, string $link, ?

return sprintf($format, $link, $label);
}

private static function clearLine(OutputInterface $output): void
{
if ($output->isDecorated()) {
if (\class_exists(Cursor::class)) {
(new Cursor($output))
->clearLine()
->moveToColumn(1);
} else {
$output->write("\x1b[2K");
$output->write(sprintf("\x1b[%dG", 1));
}
} else {
$output->writeln('');
}
}
}

0 comments on commit f439c98

Please sign in to comment.