1libcaca-ruby-api(3caca) libcaca libcaca-ruby-api(3caca)
2
3
4
6 libcaca-ruby-api - Libcaca Ruby API
7
9 The classes available for libcaca are :
10
11 · Caca::Canvas : functions that have a caca_canvas_t* as first argument
12 · Caca::Dither : functions that have a caca_dither_t* as first argument
13 · Caca::Font : functions that have a caca_font_t* as first argument
14 (The constructor can currently only accept the name of a builtin
15 font)
16 · Caca::Display
17 · Caca::Event
18 · Caca::Event::Key
19 · Caca::Event::Key::Press
20 · Caca::Event::Key::Release
21 · Caca::Event::Mouse
22 · Caca::Event::Mouse::Press
23 · Caca::Event::Mouse::Release
24 · Caca::Event::Mouse::Motion
25 · Caca::Event::Resize
26 · Caca::Event::Quit
27 The character set conversion functions are not available yet in the
28 binding.
29 $ irb -rcaca
30 irb(main):001:0> class Object
31 irb(main):002:1> def Object.my_instance_methods
32 irb(main):003:2> instance_methods.sort - ancestors[1].instance_methods
33 irb(main):004:2> end
34 irb(main):005:1> def Object.my_methods
35 irb(main):006:2> methods.sort - ancestors[1].methods
36 irb(main):007:2> end
37 irb(main):008:1> end
38 irb(main):009:0> Caca.constants
39 => ['BROWN', 'BOLD', 'GREEN', 'LIGHTMAGENTA', 'LIGHTBLUE', 'BLINK',
40 irb(main):010:0> Caca.my_methods
41 => ['version']
42 irb(main):011:0> Caca::Canvas.my_methods
43 => ['export_list', 'import_list']
44 irb(main):012:0> Caca::Canvas.my_instance_methods
45 => ['attr=', 'blit', 'clear', 'create_frame',
46 irb(main):013:0> Caca::Font.my_methods
47 => ['list']
48 irb(main):014:0> Caca::Font.my_instance_methods
49 => ['blocks', 'height', 'width']
50 irb(main):015:0> Caca::Dither.my_instance_methods
51 => ['algorithm=', 'algorithm_list', 'antialias=', 'antialias_list',
52 irb(main):010:0> Caca::Display.my_instance_methods
53 => ['canvas', 'get_event', 'height', 'mouse=', 'mouse_x', 'mouse_y', 'refresh',
54 irb(main):011:0> Caca::Event.constants
55 => ['Key', 'Quit', 'TYPE', 'Mouse', 'Resize']
56 irb(main):012:0> Caca::Event.my_instance_methods
57 => ['quit?']
58 irb(main):013:0> Caca::Event::Key.my_instance_methods
59 => ['ch', 'utf32', 'utf8']
60 irb(main):014:0> Caca::Event::Mouse.my_instance_methods
61 => ['button', 'x', 'y']
62 irb(main):015:0> Caca::Event::Resize.my_instance_methods
63 => ['w', 'h']
65 $ ruby -rcaca -e 'c=Caca::Canvas.new(6, 3).fill_box(0,0,2,2,'#'[0]);
66 c2=Caca::Canvas.new(1,1).put_str(0,0,'x'); c.blit(1,1,c2); puts
67 c.export_to_memory('irc')'
68 ###
69 #x#
70 ###
71 $ ruby -e 'puts Caca::Canvas.new(6,3).draw_thin_polyline([[0,0], [0,2],
72 [5,2],[0,0]]).export_to_memory('irc')'
73 -.
74 | `.
75 ----`-
76 $ ruby -rcaca -e 'p Caca::Canvas.export_list'
77 [['caca', 'native libcaca format'], ['ansi', 'ANSI'], ['utf8', 'UTF-8
78 withANSI escape codes'], ['utf8cr', 'UTF-8 with ANSI escape codes and
79 MS-DOS\r'], ['html', 'HTML'], ['html3', 'backwards-compatible HTML'],
80 ['irc', 'IRC with mIRC colours'], ['ps', 'PostScript document'], ['svg',
81 $ ruby -rcaca -e 'p Caca::Font.list'
82 ['Monospace9', 'Monospace Bold 12']
83 require 'caca'
84 c = Caca::Canvas.new(20,10)
85 c.put_str(2,3, 'plop!')
86 c.draw_thin_polyline([[0,0],[0,2], [5,2], [0,0]])
87 d = Caca::Display.new(c)
88 d.title= 'Test !'
89 d.refresh
90
91 #Redefine Event::Key#quit? so that q, Q, and Esc become exit keys
92 module Caca
93 class Event::Key
94 def quit?
95 'qQ^['.split('').member?(@ch.chr)
96 end
97 end
98 end
99
100 while((e= d.get_event(Caca::Event, -1)) && ! e.quit?)
101 p e
102 d.refresh
103 end
104Version 0.99.beta17 29 Apr 2010 libcaca-ruby-api(3caca)