-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathcrazy-redraw.php
More file actions
62 lines (49 loc) · 1.55 KB
/
crazy-redraw.php
File metadata and controls
62 lines (49 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
declare(strict_types=1);
use PhpSchool\CliMenu\CliMenu;
use PhpSchool\CliMenu\Builder\CliMenuBuilder;
use PhpSchool\CliMenu\MenuItem\LineBreakItem;
use PhpSchool\CliMenu\MenuItem\MenuItemInterface;
require_once(__DIR__ . '/../vendor/autoload.php');
$itemCallable = function (CliMenu $menu) {
$colour = function () {
return array_rand(array_flip(['blue', 'green', 'red', 'yellow']));
};
$int = function () {
return rand(1, 20);
};
$bg = $colour();
while (($fg = $colour()) === $bg) {
}
$menu->getStyle()->setBg($bg);
$menu->getStyle()->setFg($fg);
$menu->getStyle()->setPadding($int());
$menu->getStyle()->setMargin($int());
$items = $menu->getItems();
array_walk($items, function (MenuItemInterface $item) use ($menu) {
$menu->removeItem($item);
});
$items = array_filter($items, function (MenuItemInterface $item) {
return !$item instanceof LineBreakItem;
});
foreach (range(0, rand(1, 5)) as $i) {
$items[] = new LineBreakItem(array_rand(array_flip(['♥', '★', '^'])), rand(1, 3));
}
shuffle($items);
array_walk(
$items,
function (MenuItemInterface $item) use ($menu) {
$menu->addItem($item);
}
);
$menu->redraw(true);
};
$menu = (new CliMenuBuilder)
->setTitle('Basic CLI Menu')
->setWidth(80)
->addItem('First Item', $itemCallable)
->addItem('Second Item', $itemCallable)
->addItem('Third Item', $itemCallable)
->addLineBreak('-')
->build();
$menu->open();