From: Josh Cheek Date: 2011-09-26T12:40:22+09:00 Subject: Re: [ANN] ffi-ncurses v0.4.0 released --20cf307d059c11311a04adcfebd5 Content-Type: text/plain; charset=ISO-8859-1 On Sun, Sep 25, 2011 at 5:25 PM, Sean O'Halpin 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 > > This is really cool :) 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 --20cf307d059c11311a04adcfebd5--