-
-
Notifications
You must be signed in to change notification settings - Fork 158
Expand file tree
/
Copy pathHasConsole.php
More file actions
158 lines (130 loc) · 3.65 KB
/
HasConsole.php
File metadata and controls
158 lines (130 loc) · 3.65 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
declare(strict_types=1);
namespace Tempest\Console;
use Closure;
use Stringable;
use Symfony\Component\Process\Process;
use Tempest\Container\Inject;
use UnitEnum;
trait HasConsole
{
#[Inject]
private readonly Console $console;
public function readln(): string
{
return $this->console->readln();
}
public function read(int $bytes): string
{
return $this->console->read($bytes);
}
public function write(string $contents): self
{
$this->console->write($contents);
return $this;
}
public function writeln(string $line = ''): self
{
$this->console->writeln($line);
return $this;
}
/**
* @param mixed|null $default
* @param \Tempest\Validation\Rule[] $validation
*/
public function ask(
string $question,
null|iterable|string $options = null,
mixed $default = null,
bool $multiple = false,
bool $multiline = false,
?string $placeholder = null,
?string $hint = null,
array $validation = [],
): null|int|string|Stringable|UnitEnum|array {
return $this->console->ask(
question: $question,
options: $options,
default: $default,
multiple: $multiple,
multiline: $multiline,
placeholder: $placeholder,
hint: $hint,
validation: $validation,
);
}
public function confirm(
string $question,
bool $default = false,
?string $yes = null,
?string $no = null,
): bool {
return $this->console->confirm(
question: $question,
default: $default,
yes: $yes,
no: $no,
);
}
public function password(string $label = 'Password', bool $confirm = false, array $validation = []): string
{
return $this->console->password(
label: $label,
confirm: $confirm,
validation: $validation,
);
}
public function progressBar(iterable $data, Closure $handler): array
{
return $this->console->progressBar(
data: $data,
handler: $handler,
);
}
/**
* @param Closure(string $search): array $search
*/
public function search(string $label, Closure $search, bool $multiple = false, null|string|array $default = null): mixed
{
return $this->console->search(
label: $label,
search: $search,
multiple: $multiple,
default: $default,
);
}
public function info(string $contents, ?string $title = null): self
{
$this->console->info($contents, $title);
return $this;
}
public function error(string $contents, ?string $title = null): self
{
$this->console->error($contents, $title);
return $this;
}
public function warning(string $contents, ?string $title = null): self
{
$this->console->warning($contents, $title);
return $this;
}
public function success(string $contents, ?string $title = null): self
{
$this->console->success($contents, $title);
return $this;
}
public function keyValue(string $key, ?string $value = null): self
{
$this->console->keyValue($key, $value);
return $this;
}
public function header(string $header, ?string $subheader = null): self
{
$this->console->header($header, $subheader);
return $this;
}
public function task(string $label, null|Process|Closure $handler): bool
{
return $this->console->task($label, $handler);
}
}