-
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy path05-cursor.php
More file actions
38 lines (28 loc) · 870 Bytes
/
05-cursor.php
File metadata and controls
38 lines (28 loc) · 870 Bytes
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
<?php
require __DIR__ . '/../vendor/autoload.php';
$stdio = new Clue\React\Stdio\Stdio();
$value = 10;
$stdio->on("\033[A", function () use (&$value, $stdio) {
$value++;
$stdio->setPrompt('Value: ' . $value);
});
$stdio->on("\033[B", function () use (&$value, $stdio) {
--$value;
$stdio->setPrompt('Value: ' . $value);
});
// hijack enter to just print our current value
$stdio->on("\n", function () use ($stdio, &$value) {
$stdio->write("Your choice was $value\n");
});
// quit on "q"
$stdio->on('q', function () use ($stdio) {
$stdio->end();
});
// user can still type all keys, but we simply hide user input
$stdio->setEcho(false);
// instead of showing user input, we just show a custom prompt
$stdio->setPrompt('Value: ' . $value);
$stdio->write('Welcome to this cursor demo
Use cursor UP/DOWN to change value.
Use "q" to quit
');