1 | #!/usr/bin/php5 |
---|
2 | <?php |
---|
3 | /* |
---|
4 | * cacainfo.php sample program for libcaca php binding |
---|
5 | * Copyright (c) 2008 Nicolas Vion <nico@yojik.eu> |
---|
6 | * |
---|
7 | * This program is free software. It comes without any warranty, to |
---|
8 | * the extent permitted by applicable law. You can redistribute it |
---|
9 | * and/or modify it under the terms of the Do What The Fuck You Want |
---|
10 | * To Public License, Version 2, as published by Sam Hocevar. See |
---|
11 | * http://sam.zoy.org/wtfpl/COPYING for more details. |
---|
12 | */ |
---|
13 | |
---|
14 | |
---|
15 | //--- Just for fun ---// |
---|
16 | |
---|
17 | function just_for_fun() { |
---|
18 | |
---|
19 | $moo = <<<EOT |
---|
20 | (__) |
---|
21 | (oo) |
---|
22 | /------\/ |
---|
23 | / | || |
---|
24 | * /\---/\ |
---|
25 | ~~ ~~ |
---|
26 | EOT; |
---|
27 | |
---|
28 | $cv = caca_create_canvas(0, 0); |
---|
29 | caca_set_color_ansi($cv, CACA_LIGHTBLUE, CACA_DEFAULT); |
---|
30 | caca_import_string($cv, $moo, "text"); |
---|
31 | |
---|
32 | for($j = 0; $j < caca_get_canvas_height($cv); $j++) { |
---|
33 | for($i = 0; $i < caca_get_canvas_width($cv); $i += 2) { |
---|
34 | caca_set_color_ansi($cv, (caca_rand(1, 10) > 5 ? CACA_LIGHTBLUE : CACA_WHITE), CACA_DEFAULT); |
---|
35 | $a = caca_get_attr($cv, -1, -1); |
---|
36 | caca_put_attr($cv, $i, $j, $a); |
---|
37 | caca_put_attr($cv, $i + 1, $j, $a); |
---|
38 | } |
---|
39 | } |
---|
40 | caca_set_color_ansi($cv, CACA_LIGHTGREEN, CACA_DEFAULT); |
---|
41 | caca_put_str($cv, 8, 0, "Moo!"); |
---|
42 | caca_set_color_ansi($cv, CACA_LIGHTRED, CACA_DEFAULT); |
---|
43 | caca_put_char($cv, 8, 1, hexdec("2765")); //U+2765 |
---|
44 | caca_put_char($cv, 10, 1, hexdec("2764")); //U+2764 |
---|
45 | echo caca_export_string($cv, "utf8"); |
---|
46 | } |
---|
47 | |
---|
48 | |
---|
49 | if (!posix_isatty(STDOUT)) |
---|
50 | die("You have to run this program with php-cli!\n"); |
---|
51 | |
---|
52 | just_for_fun(); |
---|
53 | |
---|
54 | //--- Show caca's information ---// |
---|
55 | |
---|
56 | echo "libcaca version: ".caca_get_version()."\n\n"; |
---|
57 | echo "Available drivers:\n"; |
---|
58 | $list = caca_get_display_driver_list(); |
---|
59 | foreach($list as $type => $name) |
---|
60 | echo "* $name ($type)\n"; |
---|
61 | echo "\n"; |
---|
62 | |
---|
63 | echo "Available import formats:\n"; |
---|
64 | $list = caca_get_import_list(); |
---|
65 | foreach($list as $format => $name) |
---|
66 | echo "* $name ($format)\n"; |
---|
67 | echo "\n"; |
---|
68 | |
---|
69 | echo "Available export formats:\n"; |
---|
70 | $list = caca_get_export_list(); |
---|
71 | foreach($list as $format => $name) |
---|
72 | echo "* $name ($format)\n"; |
---|
73 | echo "\n"; |
---|
74 | |
---|
75 | echo "Available caca fonts:\n"; |
---|
76 | $list = caca_get_font_list(); |
---|
77 | foreach($list as $name) |
---|
78 | echo "* $name\n"; |
---|
79 | echo "\n"; |
---|
80 | |
---|
81 | ?> |
---|