Ffi-ncurses version 0.3.0


#1

ffi-ncurses version 0.3.0
by Sean O’Halpin
http://github.com/seanohalpin/ffi-ncurses

== DESCRIPTION

ffi-ncurses is an FFI wrapper for ncurses 5.x.

This is the first release of a gem on rubyforge.

Tested on Mac OS X 10.4 (Tiger) and Ubuntu 8.04 with ruby 1.8.6
using ruby-ffi (>= 0.2.0) and JRuby 1.1.6.

The API is a transliteration of the C API rather than an attempt to
provide an idiomatic Ruby object-oriented API. The intent is to
provide a ‘close to the metal’ wrapper around the ncurses library upon
which you can build your own abstractions.

This is still very much a work-in-progress, so expect some rough
edges. Having said that, you can do quite a lot with it as it is. The
main things left to be done are documentation, tests and access to
global variables in JRuby.

I don’t have an issue tracker set up yet but I’m happy to receive
feedback
via email.

See the examples directory for real working examples.

== INSTALL

$ sudo gem install ffi-ncurses

== CHANGES

  • Features
    • Use FFI::NCurses rather than NCurses
    • Removed dependency on rubygems
    • Reorganised library layout

From the README:

== Usage

Load the library with:

require ‘ffi-ncurses’

FFI::NCurses methods can be called as module methods:

begin
stdscr = FFI::NCurses.initscr
FFI::NCurses.clear
FFI::NCurses.addstr(“Hello world!”)
FFI::NCurses.refresh
FFI::NCurses.getch
ensure
FFI::NCurses.endwin
end

or as included methods:

require ‘ffi-ncurses’
include FFI::NCurses
begin
stdscr = initscr
start_color
curs_set 0
raw
cbreak
noecho
clear
move 10, 10
standout
addstr(“Hi!”)
standend
refresh
getch
ensure
endwin
end

There’s more in the README and examples, including how to create
windows, use
the mouse and how to interpret keypresses.

Regards,
Sean


#2

I noticed this tries to install the ruby-ffi gem on JRuby. Perhaps we
need to have a dummy ffi gem for JRuby that does nothing more than turn
on our built-in support, so that gem authors can depend on ‘ffi’?


#3

On Mon, Feb 16, 2009 at 12:57 AM, Charles Oliver N.
removed_email_address@domain.invalid wrote:

I noticed this tries to install the ruby-ffi gem on JRuby. Perhaps we need
to have a dummy ffi gem for JRuby that does nothing more than turn on our
built-in support, so that gem authors can depend on ‘ffi’?

Ouch! Didn’t try installing it as a gem in JRuby.

Is it possible to specify different gem dependencies by platform?

Regards,
Sean


#4

Sean O’Halpin wrote:

Ouch! Didn’t try installing it as a gem in JRuby.

Is it possible to specify different gem dependencies by platform?

No, it’s not. RubyGems dependency mechanism is pretty simplistic. I
think the only option with current RubyGems would be to have a dummy FFI
gem.

Granted, I’d love to see RubyGems handle this better; we get people
asking us about it every other day.

  • Charlie

#5

On Mon, Feb 16, 2009 at 2:50 AM, Charles Oliver N.
removed_email_address@domain.invalid wrote:

us about it every other day.

  • Charlie

Shame. I’ll document this way to install ffi-ncurses for the moment:

$ jruby -S gem install ffi-ncurses --ignore-dependencies

Regards,
Sean


#6

On Mon, Feb 16, 2009 at 8:25 AM, Sean O’Halpin removed_email_address@domain.invalid
wrote:

Regards,
Sean

That isn’t enough - I have to remove the dependency altogether. Hmmm.
A dummy FFI gem looks like the only solution at the moment.
In the meantime, I’ve released a new version of the gem without the
dependency on ffi.

To install:

ruby 1.8.6:

$ sudo gem install ffi ffi-ncurses

jruby 1.1.6:

$ jruby -S gem install ffi-ncurses

Regards,
Sean


#7

Excuse the question, but what exactly is ffi-ncurses advantage over
the already existing ncurses bindings for ruby?
I admit that I dont really know much about the benefits of ffi.


#8

On Tue, Feb 17, 2009 at 1:24 PM, Dominik H. removed_email_address@domain.invalid
wrote:

Excuse the question, but what exactly is ffi-ncurses advantage over
the already existing ncurses bindings for ruby?
I admit that I dont really know much about the benefits of ffi.

Dominik H.
removed_email_address@domain.invalid

Hi Dominik,

In order of importance:

  • The same code runs under both ruby 1.8.6 and JRuby 1.1.6
  • The FFI implementation doesn’t need a compiler on the target machine
    (not such a big deal on Linux, but handy on a Mac without XTools)
  • I intend to build a cross-platform text console library on top of
    this and didn’t want to use the existing Ncurses implementation which
    hasn’t been updated for a while and is a little idiosyncratic in its
    mapping of the C API to ruby
  • I wanted to learn to use the FFI :slight_smile:

Regards,
Sean


#9

Thank you for the fast answer.
And: I’m especially looking forward to that console library.


#10

Sean O’Halpin wrote:

That isn’t enough - I have to remove the dependency altogether. Hmmm.
A dummy FFI gem looks like the only solution at the moment.
In the meantime, I’ve released a new version of the gem without the
dependency on ffi.

Great, thanks…we’ll see about getting a dummy gem for JRuby; it might
be a good way to share some code with the MRI version too.

  • Charlie