我使用Lumen框架进行辅助项目,并创建了一个将小表写入终端的工匠命令。我正在做的事情是清理终端并重新绘制表格。
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
}
}
有没有人有任何想法?
答案 0 :(得分:1)
肮脏的修复将是这样的:
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
system('cls');
} else {
system('clear');
}