【问题标题】:Clearing the Console from a Laravel Command从 Laravel 命令清除控制台
【发布时间】:2017-03-17 12:30:42
【问题描述】:

我正在将 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 
    }
}

有人有什么想法吗?

【问题讨论】:

  • 您能否详细说明“遇到麻烦”?
  • @JoeC “遇到麻烦”,因为我不确定如何完成清除控制台。

标签: php laravel command-line terminal lumen


【解决方案1】:

一个肮脏的修复应该是这样的:

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

【讨论】:

    猜你喜欢
    • 2016-08-29
    • 2016-02-08
    • 1970-01-01
    • 2017-08-08
    • 2023-03-13
    • 2016-01-13
    • 2015-04-06
    • 1970-01-01
    • 2022-06-14
    相关资源
    最近更新 更多