-
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy path04-bindings.php
More file actions
38 lines (31 loc) · 972 Bytes
/
04-bindings.php
File metadata and controls
38 lines (31 loc) · 972 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();
$stdio->setPrompt('> ');
// add some special key bindings
$stdio->on('a', function () use ($stdio) {
$stdio->addInput('ä');
});
$stdio->on('o', function () use ($stdio) {
$stdio->addInput('ö');
});
$stdio->on('u', function () use ($stdio) {
$stdio->addInput('ü');
});
$stdio->on('?', function () use ($stdio) {
$stdio->write('Do you need help?');
});
// bind CTRL+E
$stdio->on("\x05", function () use ($stdio) {
$stdio->write("ignore CTRL+E" . PHP_EOL);
});
// bind CTRL+H
$stdio->on("\x08", function () use ($stdio) {
$stdio->write('Use "?" if you need help.' . PHP_EOL);
});
$stdio->write('Welcome to this interactive demo' . PHP_EOL);
// end once the user enters a command
$stdio->on('data', function ($line) use ($stdio) {
$line = rtrim($line, "\r\n");
$stdio->end('you just said: ' . $line . ' (' . strlen($line) . ')' . PHP_EOL);
});