-
Notifications
You must be signed in to change notification settings - Fork 1
/
tests.php
183 lines (130 loc) · 4.56 KB
/
tests.php
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<?php
require __DIR__ . '/vendor/autoload.php';
use Brick\Console\Console;
$console = new Console();
/* Erase screen */
$console->eraseScreen();
/* Test colors */
$console->setBackgroundColor(Console::COLOR_BLACK);
$console->setTextColor(Console::COLOR_RED);
$console->println('Red on black');
$console->setTextColor(Console::COLOR_GREEN);
$console->println('Green on black');
$console->setTextColor(Console::COLOR_YELLOW);
$console->println('Yellow on black');
$console->setTextColor(Console::COLOR_BLUE);
$console->println('Blue on black');
$console->setTextColor(Console::COLOR_MAGENTA);
$console->println('Magenta on black');
$console->setTextColor(Console::COLOR_CYAN);
$console->println('Cyan on black');
$console->setTextColor(Console::COLOR_WHITE);
$console->println('Green on black');
$console->setTextColor(Console::COLOR_WHITE);
$console->setBackgroundColor(Console::COLOR_RED);
$console->println('White on red');
$console->setBackgroundColor(Console::COLOR_GREEN);
$console->println('White on green');
$console->setBackgroundColor(Console::COLOR_YELLOW);
$console->println('White on yellow');
$console->setBackgroundColor(Console::COLOR_BLUE);
$console->println('White on blue');
$console->setBackgroundColor(Console::COLOR_MAGENTA);
$console->println('White on magenta');
$console->setBackgroundColor(Console::COLOR_CYAN);
$console->println('White on cyan');
$console->setTextColor(Console::COLOR_BLACK);
$console->setBackgroundColor(Console::COLOR_WHITE);
$console->println('Black on white');
$console->setTextMode(Console::MODE_DEFAULT);
$console->println('Back to default');
$console->setTextMode(Console::MODE_BOLD);
$console->println('Bright');
$console->setTextMode(Console::MODE_DEFAULT);
$console->setTextMode(Console::MODE_HALF_BRIGHT);
$console->println('Dim');
$console->setTextMode(Console::MODE_DEFAULT);
$console->setTextMode(Console::MODE_UNDERSCORE);
$console->println('Underscore');
$console->setTextMode(Console::MODE_DEFAULT);
$console->setTextMode(Console::MODE_BLINK);
$console->println('Blink');
$console->setTextMode(Console::MODE_DEFAULT);
$console->setTextMode(Console::MODE_ITALIC);
$console->println('Italic');
$console->setTextMode(Console::MODE_DEFAULT);
$console->setTextMode(Console::MODE_REVERSE);
$console->println('Reverse');
$console->setTextMode(Console::MODE_DEFAULT);
$console->setTextMode(Console::MODE_HIDDEN);
$console->println('Hidden');
$console->setTextMode(Console::MODE_DEFAULT);
/* Test cursor positioning : draw a red cross */
$draw = function () use ($console) {
$console->setTextColor(Console::COLOR_RED);
$console->setBackgroundColor(Console::COLOR_RED);
echo "X";
$console->setTextMode(Console::MODE_DEFAULT);
$console->moveCursorBackward();
};
$console->saveCursorPosition();
$console->moveCursorUp(3);
$console->moveCursorForward(20);
$draw();
$console->moveCursorDown(2);
$draw();
$console->moveCursorBackward(1);
$console->moveCursorUp(1);
$draw();
$console->moveCursorForward(2);
$draw();
$console->moveCursorBackward();
$draw();
$console->setTextMode(Console::MODE_DEFAULT);
$console->restoreCursorPosition();
/* Test cursor absolute positioning */
$console->saveCursorPosition();
$console->setCursorHome();
$console->setBackgroundColor(Console::COLOR_RED);
$console->setTextColor(Console::COLOR_WHITE);
echo "HOME";
$console->setTextMode(Console::MODE_DEFAULT);
$console->setCursorPosition(3, 5);
$console->setBackgroundColor(Console::COLOR_RED);
$console->setTextColor(Console::COLOR_WHITE);
echo "WRITING AT POSITION 3,5";
$console->setTextMode(Console::MODE_DEFAULT);
$console->restoreCursorPosition();
/* Test erase to end of line */
echo "No 'X' should appear here -> XXXXXXXXXX";
$console->moveCursorBackward(10);
$console->eraseToEndOfLine();
echo "\n";
echo 'XXXXXXXXXX';
$console->eraseToStartOfLine();
echo " <- No 'X' should appear here\n";
echo "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla eget volutpat nunc.";
$console->moveCursorBackward(51);
$console->eraseLine();
echo "<-- No text should appear on either side -->\n";
echo 'Press ENTER to test erase screen up';
$line = readline('');
$console->saveCursorPosition();
$console->moveCursorUp(15);
$console->eraseUp();
$console->restoreCursorPosition();
echo 'Press ENTER to test erase screen down';
$line = readline('');
$console->saveCursorPosition();
$console->moveCursorUp(10);
$console->eraseDown();
$console->restoreCursorPosition();
echo 'Showing/hiding cursor... ';
for ($i = 0; $i < 10; $i++) {
$console->hideCursor();
usleep(100000);
$console->showCursor();
usleep(100000);
}
echo "\n";
echo "End of tests.\n";