-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathexample.php
More file actions
executable file
·50 lines (42 loc) · 1.12 KB
/
example.php
File metadata and controls
executable file
·50 lines (42 loc) · 1.12 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
#!/usr/bin/env php
<?php
$termbox_h = <<<'EOD'
struct tb_event {
uint8_t type;
uint8_t mod;
uint16_t key;
uint32_t ch;
int32_t w;
int32_t h;
int32_t x;
int32_t y;
};
int tb_init();
int tb_shutdown();
int tb_present();
int tb_poll_event(struct tb_event *event);
int tb_printf(int x, int y, uint32_t fg, uint32_t bg, const char *fmt, ...);
EOD;
$termbox = FFI::cdef($termbox_h, '../libtermbox2.so');
$ev = $termbox->new('struct tb_event');
$termbox->tb_init();
$y = 0;
$termbox->tb_printf(0, $y++, 0x02 | 0x0100, 0x00, 'hello from php');
$termbox->tb_printf(0, $y++, 0x03, 0x00, 'press any key');
$termbox->tb_present();
$termbox->tb_poll_event(FFI::addr($ev));
$termbox->tb_printf(0, $y++, 0x04, 0x00,
'event: type=%d mod=%d key=%d ch=%d w=%d h=%d x=%d y=%d',
$ev->type,
$ev->mod,
$ev->key,
$ev->ch,
$ev->w,
$ev->h,
$ev->x,
$ev->y);
$termbox->tb_present();
$termbox->tb_printf(0, $y++, 0x05, 0x00, 'press any key to quit');
$termbox->tb_present();
$termbox->tb_poll_event(FFI::addr($ev));
$termbox->tb_shutdown();