Reputation: 31
I'm using the Lumen framework for a side project and have created an artisan command that writes a small table to the terminal. What I'm having trouble doing, is clearing the terminal and redrawing the table.
public function fire()
{
$scraper = new scraper();
$scores = $scraper->scrape();
$i = 1;
while($i = 1) {
$table = new Table($this->getOutput());
$table->setHeaders(array('', 'Score', 'Status'));
foreach($scores as $game) {
$table->addRow([$game->team1['name'], $game->team1['score'], new TableCell($game->gameStatus, array('rowspan' => 2))]);
$table->addRow([$game->team2['name'], $game->team2['score']]);
$table->addRow([new TableSeparator(), new TableSeparator(), new TableSeparator()]);
}
$table->render();
sleep(5);
// Somehow clear the terminal
}
}
Does anyone have any ideas?
Upvotes: 3
Views: 4341
Reputation: 11971
A dirty fix would be something like this:
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
system('cls');
} else {
system('clear');
}
Upvotes: 7