[ANN] ffi-ncurses v0.4.0 released

Hi,

I'm pleased to announce version 0.4.0 of the ffi-ncurses gem which
provides an FFI wrapper to the ncursesw library for creating
fullscreen terminal applications with cursor positioning, colour and
text windows.

This release has much better support for Unicode (aka widechars) both
on input and output and fully implements the ncursesw widechar
routines. It has been tested on Ubuntu 10.04 and 11.04 with MRI 1.8.7,
1.9.2 and jruby-head in 1.8.7 and 1.9.2 modes. A previous version was
tested on Mac OS X 10.4 - this version should still work but I have
not been able to test it yet.

It also contains some more substantial examples, in particular
showing how to handle Unicode input (in examples/getkey.rb), how to
temporarily leaves ncurses (examples/temp_leave.rb) and how to use
pads and popup windows (examples/viewer.rb).

I've tried to retain backward compatibility for those libraries that
depend on it but if I've missed something, please let me know on the
github issues page (https://github.com/seanohalpin/ffi-ncurses/issues).

To install:

  $ [sudo] gem install ffi-ncurses

To run the examples, change to a scratch directory then

  $ gem unpack ffi-ncurses
  $ cd ffi-ncurses-0.4.0/examples
  $ ./run-all.sh

Main Changes

···

------------

* Uses the ncursesw (widechar) version of ncurses by default.

* Supports all functions in ncursesw except the =vwprintw/vwscanw=
  family.

* Added =ACS= constants (box characters). See =examples/acs.rb= and
  =examples/wacs.rb=.

* Added support for =libpanelw=. See =examples/panel_simple.rb=.

* Methods with boolean arguments now accept =true= or =false= as well
  as 1 or 0.

* Better examples. See =examples/viewer.rb= for a simple but complete
  file viewing application.

* Sets the locale (using FFI::Locale.setlocale(LC_ALL, "")) in ruby
  1.8.x to enable UTF-8 input. This adds a dependency on the
  ffi-locale gem. See =examples/getkey.rb= to see how to distinguish
  between function keys and Unicode characters.

* Start of a compatibility layer for the existing C extension-based
  Ncurses Ruby libraries - require 'ffi-ncurses/ncurses'. Runs all
  the examples from ncurses-ruby without changes (except those relying
  on menus and forms). See =examples/ncurses/*.rb=.

Source code available at https://github.com/seanohalpin/ffi-ncurses/.

Regards,
Sean

This is really cool :slight_smile:

Could you add an example with nonblocking input? (ie for a game loop that
gets input from user but continues playing even if user doesn't do anything)
I don't seem to be able to figure out how to do it, my efforts were based on
threads like this:

require 'ffi-ncurses'
include FFI::NCurses

begin
  initscr
  raw
  keypad stdscr, true
  noecho
  curs_set 0
  ch = 0

  key_getter = Thread.new do
    while ch != KEY_CTRL_Q
      ch = getch
      addstr "You pressed #{ch}\n"
      refresh
    end
  end

  1.upto 5 do |i|
    sleep 1
    addstr "Running for #{i} seconds\n"
  end

  key_getter.kill

ensure
  endwin
end

This approach works for the equivalent gets/puts:

line = ""
line_getter = Thread.new do
  while line != "quit\n"
    line = gets
    puts "You wrote #{line}\n"
  end
end

1.upto 5 do |i|
  sleep 1
  puts "Running for #{i} seconds\n"
end

line_getter.kill

···

On Sun, Sep 25, 2011 at 5:25 PM, Sean O'Halpin <sean.ohalpin@gmail.com>wrote:

Hi,

I'm pleased to announce version 0.4.0 of the ffi-ncurses gem which
provides an FFI wrapper to the ncursesw library for creating
fullscreen terminal applications with cursor positioning, colour and
text windows.

This release has much better support for Unicode (aka widechars) both
on input and output and fully implements the ncursesw widechar
routines. It has been tested on Ubuntu 10.04 and 11.04 with MRI 1.8.7,
1.9.2 and jruby-head in 1.8.7 and 1.9.2 modes. A previous version was
tested on Mac OS X 10.4 - this version should still work but I have
not been able to test it yet.

It also contains some more substantial examples, in particular
showing how to handle Unicode input (in examples/getkey.rb), how to
temporarily leaves ncurses (examples/temp_leave.rb) and how to use
pads and popup windows (examples/viewer.rb).

I've tried to retain backward compatibility for those libraries that
depend on it but if I've missed something, please let me know on the
github issues page (https://github.com/seanohalpin/ffi-ncurses/issues\).

To install:

$ [sudo] gem install ffi-ncurses

To run the examples, change to a scratch directory then

$ gem unpack ffi-ncurses
$ cd ffi-ncurses-0.4.0/examples
$ ./run-all.sh

Main Changes
------------

* Uses the ncursesw (widechar) version of ncurses by default.

* Supports all functions in ncursesw except the =vwprintw/vwscanw=
family.

* Added =ACS= constants (box characters). See =examples/acs.rb= and
=examples/wacs.rb=.

* Added support for =libpanelw=. See =examples/panel_simple.rb=.

* Methods with boolean arguments now accept =true= or =false= as well
as 1 or 0.

* Better examples. See =examples/viewer.rb= for a simple but complete
file viewing application.

* Sets the locale (using FFI::Locale.setlocale(LC_ALL, "")) in ruby
1.8.x to enable UTF-8 input. This adds a dependency on the
ffi-locale gem. See =examples/getkey.rb= to see how to distinguish
between function keys and Unicode characters.

* Start of a compatibility layer for the existing C extension-based
Ncurses Ruby libraries - require 'ffi-ncurses/ncurses'. Runs all
the examples from ncurses-ruby without changes (except those relying
on menus and forms). See =examples/ncurses/*.rb=.

Source code available at https://github.com/seanohalpin/ffi-ncurses/\.

Regards,
Sean

Hi Josh,

To get non-blocking input in ncurses you have to change the input mode
using either nodelay or timeout. For example:

require 'ffi-ncurses'

def KEY(ch)
  ch[0].ord
end

include FFI::NCurses
initscr
begin
  cbreak
  noecho
  curs_set 0
  timeout(100) # delay in milliseconds
  counter = 0
  move 0, 0
  scrollok(stdscr, true)
  while (ch = getch) != KEY("q")
    flushinp
    addstr sprintf("You pressed %d\n", ch)
    refresh
  end
ensure
  endwin
end

See "man timeout" for more details. Thanks for the feedback. I'll add
this (and a threaded example) to the examples directory.

Regards,
Sean

Thanks a lot, Sean :slight_smile:

···

On Mon, Sep 26, 2011 at 3:05 AM, Sean O'Halpin <sean.ohalpin@gmail.com>wrote:

Hi Josh,

To get non-blocking input in ncurses you have to change the input mode
using either nodelay or timeout. For example:

require 'ffi-ncurses'

def KEY(ch)
ch[0].ord
end

include FFI::NCurses
initscr
begin
cbreak
noecho
curs_set 0
timeout(100) # delay in milliseconds
counter = 0
move 0, 0
scrollok(stdscr, true)
while (ch = getch) != KEY("q")
   flushinp
   addstr sprintf("You pressed %d\n", ch)
   refresh
end
ensure
endwin
end

See "man timeout" for more details. Thanks for the feedback. I'll add
this (and a threaded example) to the examples directory.

Regards,
Sean