The Accidental Rubyist

invalid byte sequence in UTF-8

Charming ruby with curses

with 12 comments

The other day I did something good. I fished out my Programming Ruby book and skimmed through it. I found many interesting things there, and i was drawn to this sample curses program. I downloaded it – a paddle that moves up and down.

In about 2 hours, I had a snake program up and running. The player (a snake) navigates around an empty screen which has some Sprites — good and bad. He gobbles them up. The time is displayed on top (how very professional!) and the players lives etc. You can download and play it if you like (for absolutely free).

Python seems to provide a lot more with its curses wrapper. Anyway, to get more out of ruby curses you need to install ncurses. (sudo gem install ncurses). I am on the lookout for more work done with ruby using ncurses, especially libraries/code that could help me create forms with menus — something close to pine or nano, an editing textarea widget like nano would be great.

Would it be of any use to anyone (or the ruby community) if I ported some of python’s ncurses wrapper to ruby ? I assume if i can understand some python (I once ported pythons Medusa, aka asyncore, to Java successfully). Suggestions and some details would be welcome.

Edit: See rbcurse on rubyforge or github.

About these ads

Written by totalrecall

September 12, 2008 at 11:50 pm

Posted in ruby

12 Responses

Subscribe to comments with RSS.

  1. Please, yes! :)

    jgwong

    September 12, 2008 at 9:45 pm

  2. Absolutely! I do a ton of scripting for server tasks and having a full-featured curses interface would be a big bonus.

    James

    September 12, 2008 at 10:38 pm

  3. Some more details on what exactly would be most useful would be welcome. I am new to curses but have been using CUI programs all my life … vim, earlier mutt, now alpine. You could either mention specific ncurses routines, or point me to some functionality in the above programs.

    Are we talking about higher level features / widgets like an editable textarea, or is there a lot of lower-level stuff needed to be exposed.

    I just saw a neat Textpad class in python (comes with the distro), that offers minimal emacs like keys. It should be possible to make a similar class in ruby. But I don’t want to duplicate what others may have done. AEditor and Diakonos speak of using ncurses, but the screenshots are of FoxGUI.

    totalrecall

    September 12, 2008 at 10:49 pm

  4. http://www.clifford.at/stfl/ has ruby bindings

    Martin DeMello

    September 12, 2008 at 11:17 pm

  5. STFL looks great. Will install and explore it in greater detail tomorrow.

    totalrecall

    September 12, 2008 at 11:49 pm

  6. Martin,
    I have spent several hours trying to get STFL to compile (I am on OSX). There seem to be many basic issues with the Makefiles. One has to put the include path in many places, not just one (and in the language folders too).

    I browsed a lot and found that “-liconv” has to be added since there were missing references.

    It still crashed out compiling python. So i removed perl and python leaving only ruby. However, it is unable to compile the stfl.bundle.

    I went into the ruby folder and got it to compile with path changes. An stfl.bundle _was_ created. However on running I still get:

    $ ruby example.rb
    /opt/local/lib/ruby/site_ruby/1.8/powerpc-darwin9.4.0/stfl.bundle: dlopen(/opt/local/lib/ruby/site_ruby/1.8/powerpc-darwin9.4.0/stfl.bundle, 9): Symbol not found: _stfl_api_allow_null_pointers (LoadError)
    Referenced from: /opt/local/lib/ruby/site_ruby/1.8/powerpc-darwin9.4.0/stfl.bundle
    Expected in: flat namespace
    – /opt/local/lib/ruby/site_ruby/1.8/powerpc-darwin9.4.0/stfl.bundle
    from example.rb:23

    (I do have ncursesw and swig+ruby).

    Is STFL easier to compile on other platforms ?

    totalrecall

    September 13, 2008 at 1:37 pm

  7. yes, everything other than the python bindings (which i had to comment out in the makefile) built happily out of the box in linux.

    Martin DeMello

    October 5, 2008 at 10:06 pm

  8. [...] Charming ruby with curses September 20087 comments 5 [...]

  9. $ ruby snakes.rb
    snakes.rb:291:in `subwin’: failed to create window (RuntimeError)
    from snakes.rb:291

    Andrew Pennebaker

    April 6, 2011 at 12:23 pm

  10. Andrew
    snakes is an old program. Probably an issue with ruby version. This is so old. I just rvm’ed to 1.8.7 and ran the snakes.rb on my disk and it works.

    What’s your setup and ruby version? You should first see if any other curses programs work. If you’ve installed the ncurses gem, you could try their examples.

    totalrecall

    April 6, 2011 at 12:36 pm

  11. $ ruby –version
    ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]

    If you cut out the offending code, the game works.

    # screen = stdscr.subwin(27, 81, 0, 0)
    # screen.box(0,0)
    # setpos(0,30); addstr(“Snakes with Ruby/Curses”)

    mcandre

    April 6, 2011 at 10:46 pm

  12. A few months late, but check out ‘Raggle’. It is an RSS reader written in Ruby using curses, and has a pretty decent interface IMO, some of the things you mention you are on the lookout for like menus etc.

    Mike 'Fuzzy' Partin

    November 1, 2011 at 8:43 am


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: