1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpSchool\CliMenu\MenuItem; |
4
|
|
|
|
5
|
|
|
use Assert\Assertion; |
6
|
|
|
use PhpSchool\CliMenu\MenuStyle; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @author Michael Woodward <[email protected]> |
10
|
|
|
*/ |
11
|
|
|
class LineBreakItem implements MenuItemInterface |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
private $breakChar; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var int |
20
|
|
|
*/ |
21
|
|
|
private $lines; |
22
|
|
|
|
23
|
|
|
public function __construct(string $breakChar = ' ', int $lines = 1) |
24
|
|
|
{ |
25
|
|
|
$this->breakChar = $breakChar; |
26
|
|
|
$this->lines = $lines; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* The output text for the item |
31
|
|
|
*/ |
32
|
|
|
public function getRows(MenuStyle $style, bool $selected = false) : array |
33
|
|
|
{ |
34
|
|
|
return explode( |
35
|
|
|
"\n", |
36
|
|
|
rtrim(str_repeat(sprintf( |
37
|
|
|
"%s\n", |
38
|
|
|
mb_substr(str_repeat($this->breakChar, $style->getContentWidth()), 0, $style->getContentWidth()) |
39
|
|
|
), $this->lines)) |
40
|
|
|
); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Can the item be selected |
45
|
|
|
*/ |
46
|
|
|
public function canSelect() : bool |
47
|
|
|
{ |
48
|
|
|
return false; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Execute the items callable if required |
53
|
|
|
*/ |
54
|
|
|
public function getSelectAction() : ?callable |
55
|
|
|
{ |
56
|
|
|
return null; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Return the raw string of text |
61
|
|
|
*/ |
62
|
|
|
public function getText() : string |
63
|
|
|
{ |
64
|
|
|
return $this->breakChar; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Set the raw string of text |
69
|
|
|
*/ |
70
|
|
|
public function setText(string $text) : void |
71
|
|
|
{ |
72
|
|
|
$this->breakChar = $text; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Whether or not the menu item is showing the menustyle extra value |
77
|
|
|
*/ |
78
|
|
|
public function showsItemExtra() : bool |
79
|
|
|
{ |
80
|
|
|
return false; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function getLines() : int |
84
|
|
|
{ |
85
|
|
|
return $this->lines; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Enable showing item extra |
90
|
|
|
*/ |
91
|
|
|
public function showItemExtra() : void |
92
|
|
|
{ |
93
|
|
|
//noop |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Disable showing item extra |
98
|
|
|
*/ |
99
|
|
|
public function hideItemExtra() : void |
100
|
|
|
{ |
101
|
|
|
//noop |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|