Completed
Pull Request — master (#140)
by
unknown
02:21
created

Radio::handleCharacter()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 0
cts 0
cp 0
rs 9.7
c 0
b 0
f 0
cc 4
nc 4
nop 1
crap 20
1
<?php
2
3
namespace League\CLImate\TerminalObject\Dynamic;
4
5
class Radio extends Checkboxes
6
{
7
    /**
8
     * Build out the checkboxes
9
     *
10
     * @param array $options
11
     *
12
     * @return Checkbox\RadioGroup
13
     */
14 4
    protected function buildCheckboxes(array $options)
15
    {
16 4
        return new Checkbox\RadioGroup($options);
17
    }
18
19
    /**
20
     * Take the appropriate action based on the input character,
21
     * returns whether to stop listening or not
22
     *
23
     * @param string $char
24
     *
25
     * @return bool
26
     */
27
    protected function handleCharacter($char)
28
    {
29
        switch ($char) {
30
            case ' ':
31
            case "\n":
32
                $this->checkboxes->toggleCurrent();
33
                $this->output->sameLine()->write($this->util->cursor->defaultStyle());
34
                $this->output->sameLine()->write("\e[0m");
35
                return true; // Break the while loop as well
36
37
            case "\e":
38
                $this->handleAnsi();
39
                break;
40
        }
41
42
        return false;
43
    }
44
45
    /**
46
     * Format the prompt string
47
     *
48
     * @return string
49
     */
50
    protected function promptFormatted()
51
    {
52
        return $this->prompt . ' (press <Enter> to select)';
53
    }
54
}
55