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