Libcaca Ruby API

The classes available for libcaca are :

$ irb -rcaca
irb(main):001:0> class Object
irb(main):002:1>   def Object.my_instance_methods
irb(main):003:2>     instance_methods.sort - ancestors[1].instance_methods
irb(main):004:2>   end
irb(main):005:1>   def Object.my_methods
irb(main):006:2>     methods.sort - ancestors[1].methods
irb(main):007:2>   end
irb(main):008:1> end

irb(main):009:0> Caca.my_methods
=> ["version"]

irb(main):010:0> Caca::Display.my_instance_methods
=> ["canvas", "get_event", "height", "mouse=", "mouse_x", "mouse_y", "refresh",
"set_mouse", "set_time", "set_title", "time", "time=", "title=", "width"]

irb(main):011:0> Caca::Event.constants
=> ["Key", "Quit", "TYPE", "Mouse", "Resize"]

irb(main):012:0> Caca::Event.my_instance_methods
=> ["quit?"]

irb(main):013:0> Caca::Event::Key.my_instance_methods
=> ["ch", "utf32", "utf8"]

irb(main):014:0> Caca::Event::Mouse.my_instance_methods
=> ["button", "x", "y"]

irb(main):015:0> Caca::Event::Resize.my_instance_methods
=> ["w", "h"]

Samples

require 'caca'
c = Cucul::Canvas.new(20,10)
c.put_str(2, 3, "plop!")
c.draw_thin_polyline([[0,0], [0,2], [5,2], [0,0]])
d = Caca::Display.new(c)
d.title = "Test !"
d.refresh

# Redefine Event::Key#quit? so that q, Q, and Esc become exit keys
module Caca
        class Event::Key
                def quit?
                        "qQ^[".split('').member?(@ch.chr)
                end
        end
end

while((e = d.get_event(Caca::Event, -1)) && ! e.quit?)
    p e
    d.refresh
end