php - 从 Laravel 命令中清除控制台

标签 php laravel command-line terminal lumen

我正在为一个副项目使用 Lumen 框架,并创建了一个 artisan 命令,用于将一个小表写入终端。我遇到的麻烦是清理终端并重新绘制表格。

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 
    }
}

有没有人有什么想法?

最佳答案

脏修复应该是这样的:

if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
    system('cls');
} else {
    system('clear');
}

关于php - 从 Laravel 命令中清除控制台,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40409693/

相关文章:

php - 在 laravel 7 中找不到类 'SimpleSoftwareIO\QrCode\QrCodeServiceProvider'

php - WP 排队样式正确吗?

php - magento 中的 reindexall() 与 reindexeverything() 有什么区别?

laravel - 是否有任何与 JSON API 一起使用的 Laravel Profilers?

bash - 如何将 “escape hell”传递给docker run

php - 在准备好的语句的 where 子句中使用计数值

php - Laravel 将 2 个表单值放在一起并检查它们是否唯一

php - 在迁移期间使列默认值在 laravel 5.5 中不起作用

shell - Ping 和启动程序

bash - npm adduser 通过 bash