Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
namespace App\Concerns;
use Hugga\Console;
use Hugga\Output\Drawing\Table;
/** @codeCoverageIgnore wrapper for console methods */
trait WritesToConsole
{
/** @var Console */
protected $console;
public function setConsole(Console $console)
{
$this->console = $console;
}
/**
* Write $message to stdout
*
* @param string $message
* @param int $weight
*/
protected function write(string $message, int $weight = Console::WEIGHT_NORMAL): void
{
$this->console->write($message, $weight);
}
/**
* Write $message to stderr
*
* @param string $message
* @param int $weight
*/
protected function writeError(string $message, int $weight = Console::WEIGHT_HIGH): void
{
$this->console->writeError($message, $weight);
}
/**
* Shortcut to ->write('Your message' . PHP_EOL);
*
* @param string $message
* @param int $weight
*/
protected function line(string $message, int $weight = Console::WEIGHT_NORMAL): void
{
$this->console->line($message, $weight);
}
/**
* Shortcut to ->write('${green;bold}Your message' . PHP_EOL)
*
* @param string $message
* @param int $weight
*/
protected function info(string $message, int $weight = Console::WEIGHT_NORMAL)
{
$this->console->info($message, $weight);
}
/**
* Shortcut to ->write('${red;bold}Your message' . PHP_EOL, WEIGHT_HIGHER);
*
* @param string $message
* @param int $weight
*/
protected function warn(string $message, int $weight = Console::WEIGHT_HIGHER)
{
$this->console->warn($message, $weight);
}
/**
* Write a highlighted error message (red bg; spacing) to stderr
*
* @param string $message
* @param int $weight
*/
public function error(string $message, int $weight = Console::WEIGHT_HIGH): void
{
$this->console->error($message, $weight);
}
public function table(iterable $rows, array $columns = null)
{
$table = new Table($this->console, $rows, $columns);
$table->draw();
}
}