-
-
Notifications
You must be signed in to change notification settings - Fork 158
Expand file tree
/
Copy pathConsole.php
More file actions
165 lines (135 loc) · 4.66 KB
/
Console.php
File metadata and controls
165 lines (135 loc) · 4.66 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
159
160
161
162
163
164
165
<?php
declare(strict_types=1);
namespace Tempest\Console;
use BackedEnum;
use Closure;
use Stringable;
use Symfony\Component\Process\Process;
use Tempest\Highlight\Language;
use UnitEnum;
interface Console
{
public function call(string|array $command, string|array $arguments = []): ExitCode|int;
/**
* Reads a line from the console input.
*/
public function readln(): string;
/**
* Reads the specified number of bytes from the console input.
*/
public function read(int $bytes): string;
/**
* Writes the specified `$contents` to the console output.
*/
public function write(string $contents): self;
/**
* Writes the specified `$contents` to the console output and appends a new line.
*/
public function writeln(string $line = ''): self;
/**
* Writes the specified `$contents` to the console output, without formatting.
*/
public function writeRaw(string $contents): self;
/**
* Writes the specified `$contents` to the console output with the specified syntax highlighting.
*/
public function writeWithLanguage(string $contents, Language $language): self;
/**
* @param \Tempest\Validation\Rule[] $validation
*/
public function component(InteractiveConsoleComponent $component, array $validation = []): mixed;
/**
* Asks the user a question and returns the answer.
*
* @param null|iterable|class-string<BackedEnum> $options
* @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;
/**
* Asks the user a question and returns the answer.
*/
public function confirm(string $question, bool $default = false, ?string $yes = null, ?string $no = null): bool;
/**
* Prompts the user for a password and returns it.
*/
public function password(string $label = 'Password', bool $confirm = false, array $validation = []): ?string;
/**
* Progresses through the specified `$data` using the specified `$handler`.
*/
public function progressBar(iterable $data, Closure $handler): array;
/**
* Asks the user to select an option from a list using a closure.
*
* @param Closure(string $search): array $search
*/
public function search(string $label, Closure $search, bool $multiple = false, null|string|array $default = null): mixed;
/**
* Displays the progress of a task.
*/
public function task(string $label, null|Process|Closure $handler): bool;
/**
* Displays a header.
*/
public function header(string $header, ?string $subheader = null): self;
/**
* Displays information to the user.
*/
public function info(string $contents, ?string $title = null): self;
/**
* Displays an error message to the user.
*/
public function error(string $contents, ?string $title = null): self;
/**
* Displays a warning to the user.
*/
public function warning(string $contents, ?string $title = null): self;
/**
* Displays a success message to the user.
*/
public function success(string $contents, ?string $title = null): self;
/**
* Displays a key/value pair in a line.
*/
public function keyValue(string $key, ?string $value = null, bool $useAvailableWidth = false): self;
/**
* Displays instructions to the user. Can be an array of lines.
*/
public function instructions(array|string $lines): self;
/**
* Applies the specified `$callback` when the `$condition` is `true`.
*
* @param mixed|Closure(self): bool $condition
* @param Closure(self): self $callback
*/
public function when(mixed $condition, Closure $callback): self;
/**
* Applies the specified `$callback` unless the `$condition` is `true`.
*
* @param mixed|Closure(self): bool $condition
* @param Closure(self): self $callback
*/
public function unless(mixed $condition, Closure $callback): self;
public function withLabel(string $label): self;
/**
* Whether the console is interactive.
*/
public function supportsPrompting(): bool;
/**
* Forces the console to not be interactive.
*/
public function disablePrompting(): self;
/**
* Whether the console is in forced mode (skipping confirmations).
*/
public bool $isForced { get; }
}