/
Radio.php
54 lines (48 loc) · 1.19 KB
/
Radio.php
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
<?php
namespace League\CLImate\TerminalObject\Dynamic;
class Radio extends Checkboxes
{
/**
* Build out the checkboxes
*
* @param array $options
*
* @return Checkbox\RadioGroup
*/
protected function buildCheckboxes(array $options)
{
return new Checkbox\RadioGroup($options);
}
/**
* Take the appropriate action based on the input character,
* returns whether to stop listening or not
*
* @param string $char
*
* @return bool
*/
protected function handleCharacter($char)
{
switch ($char) {
case ' ':
case "\n":
$this->checkboxes->toggleCurrent();
$this->output->sameLine()->write($this->util->cursor->defaultStyle());
$this->output->sameLine()->write("\e[0m");
return true; // Break the while loop as well
case "\e":
$this->handleAnsi();
break;
}
return false;
}
/**
* Format the prompt string
*
* @return string
*/
protected function promptFormatted()
{
return $this->prompt . ' (press <Enter> to select)';
}
}