Total Complexity | 9 |
Total Lines | 56 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
4 | final class ProgressLine |
||
5 | { |
||
6 | protected $padding; |
||
7 | |||
8 | protected $outPad; |
||
9 | protected $outMessage; |
||
10 | |||
11 | protected $showResult; |
||
12 | |||
13 | public function __construct() |
||
14 | { |
||
15 | $this->showResult = false; |
||
16 | $this->padding = 0; |
||
17 | } |
||
18 | |||
19 | public function setShowResult($showResult) |
||
20 | { |
||
21 | $this->showResult = (bool) $showResult; |
||
22 | } |
||
23 | |||
24 | public function prefix($message = '') |
||
25 | { |
||
26 | $this->outMessage = $message; |
||
27 | |||
28 | $this->outPad = (0 < $this->padding) ? str_repeat(' ', (int) $this->padding) : null; |
||
29 | return $this->outPad.$this->outMessage; |
||
30 | } |
||
31 | |||
32 | public function suffix($result = true) |
||
33 | { |
||
34 | $totalLen = strlen($this->outPad.$this->outMessage); |
||
35 | $output = null; |
||
36 | |||
37 | //overwrite current line |
||
38 | $output .= "\033[" . $totalLen . 'D'; |
||
39 | $output .= str_repeat(' ', $this->padding); |
||
40 | $output .= $this->outMessage; |
||
41 | |||
42 | $padLen = 74 - $totalLen; |
||
43 | if (0 < $padLen) { |
||
44 | $output .= str_repeat(' ', $padLen); |
||
45 | } |
||
46 | if ($this->showResult) { |
||
47 | $output .= '['; |
||
48 | $output .= $result ? "\e[32mOK" : "\e[31mKO"; |
||
49 | $output .= "\e[0m" . ']'; |
||
50 | } |
||
51 | |||
52 | $output .= "\r"; |
||
53 | |||
54 | return $output; |
||
55 | } |
||
56 | |||
57 | public function finish() |
||
60 | } |
||
61 | } |
||
62 |