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
|
|
|
/** |
24
|
|
|
* @var int |
25
|
|
|
*/ |
26
|
|
|
private $numberOfRows = 0; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var int |
30
|
|
|
*/ |
31
|
|
|
private $startRowNumber = 0; |
32
|
|
|
|
33
|
|
|
public function __construct(string $breakChar = ' ', int $lines = 1) |
34
|
|
|
{ |
35
|
|
|
$this->breakChar = $breakChar; |
36
|
|
|
$this->lines = $lines; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Returns the number of terminal rows the item takes |
41
|
|
|
*/ |
42
|
|
|
public function getNumberOfRows() : int |
43
|
|
|
{ |
44
|
|
|
return $this->numberOfRows; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Sets the row number the item starts at in the frame |
49
|
|
|
*/ |
50
|
|
|
public function setStartRowNumber(int $rowNumber) : void |
51
|
|
|
{ |
52
|
|
|
$this->startRowNumber = $rowNumber; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Returns the row number the item starts at in the frame |
57
|
|
|
*/ |
58
|
|
|
public function getStartRowNumber() : int |
59
|
|
|
{ |
60
|
|
|
return $this->startRowNumber; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* The output text for the item |
65
|
|
|
*/ |
66
|
|
|
public function getRows(MenuStyle $style, bool $selected = false) : array |
67
|
|
|
{ |
68
|
|
|
$rows = explode( |
69
|
|
|
"\n", |
70
|
|
|
rtrim(str_repeat(sprintf( |
71
|
|
|
"%s\n", |
72
|
|
|
mb_substr(str_repeat($this->breakChar, $style->getContentWidth()), 0, $style->getContentWidth()) |
73
|
|
|
), $this->lines)) |
74
|
|
|
); |
75
|
|
|
|
76
|
|
|
$this->numberOfRows = count($rows); |
77
|
|
|
|
78
|
|
|
return $rows; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Can the item be selected |
83
|
|
|
*/ |
84
|
|
|
public function canSelect() : bool |
85
|
|
|
{ |
86
|
|
|
return false; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Execute the items callable if required |
91
|
|
|
*/ |
92
|
|
|
public function getSelectAction() : ?callable |
93
|
|
|
{ |
94
|
|
|
return null; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Return the raw string of text |
99
|
|
|
*/ |
100
|
|
|
public function getText() : string |
101
|
|
|
{ |
102
|
|
|
return $this->breakChar; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Whether or not the menu item is showing the menustyle extra value |
107
|
|
|
*/ |
108
|
|
|
public function showsItemExtra() : bool |
109
|
|
|
{ |
110
|
|
|
return false; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Enable showing item extra |
115
|
|
|
*/ |
116
|
|
|
public function showItemExtra() : void |
117
|
|
|
{ |
118
|
|
|
//noop |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Disable showing item extra |
123
|
|
|
*/ |
124
|
|
|
public function hideItemExtra() : void |
125
|
|
|
{ |
126
|
|
|
//noop |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|