[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libcaca] [PATH] Add set_cursor to the ruby binding.



Hi,

I implemented caca_set_cursor for the ruby binding. The ruby method is
called 'cursor='. I've noticed the other set methods have a set_* method in
addtion to a '=' method. I wasn't sure what the purpose of that was, but should
I make a set_cursor method as well?

The patch is attached to the email, and also in my repo here, in a
branch named 'ruby-stuffs':
git://github.com/mcfiredrill/libcaca.git

Let me know what you think of the patch!

Thanks!
-Tony

---
 ruby/caca-display.c  |   10 ++++++++++
 ruby/t/tc_display.rb |    4 ++++
 2 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/ruby/caca-display.c b/ruby/caca-display.c
index 934ae9d..9ceb3d6 100644
--- a/ruby/caca-display.c
+++ b/ruby/caca-display.c
@@ -263,6 +263,15 @@ static VALUE set_driver2(VALUE self, VALUE driver)
     return self;
 }
 
+static VALUE set_cursor(VALUE self, VALUE flag)
+{
+    if(caca_set_cursor(_SELF, flag)<0)
+    {
+        rb_raise(rb_eRuntimeError, strerror(errno));
+    }
+    return self;
+}
+
 void Init_caca_display(VALUE mCaca)
 {
     cDisplay = rb_define_class_under(mCaca, "Display", rb_cObject);
@@ -287,4 +296,5 @@ void Init_caca_display(VALUE mCaca)
     rb_define_method(cDisplay, "driver=", set_driver, 1);
     rb_define_method(cDisplay, "set_mouse", set_mouse2, 1);
     rb_define_method(cDisplay, "get_event", get_event, 2);
+    rb_define_method(cDisplay, "cursor=", set_cursor, 1);
 }
diff --git a/ruby/t/tc_display.rb b/ruby/t/tc_display.rb
index 7f9abd0..ff2b64e 100644
--- a/ruby/t/tc_display.rb
+++ b/ruby/t/tc_display.rb
@@ -27,4 +27,8 @@ class TC_Canvas < Test::Unit::TestCase
         d = Caca::Display.new(c)
         d.title = "Test !"
     end
+    def test_set_cursor
+        d = Caca::Display.new()
+        d.cursor = 1
+    end
 end
-- 
1.7.3.4

-- 
This is the Caca Labs mailing-list, see http://caca.zoy.org/
Trouble unsubscribing? Please contact <sam@zoy.org>
List archives are at http://caca.zoy.org/list/