Ncurses for Ruby
Ah what a generic title. I made this post because of all the problems I was having with ncurses, which turned out to be my own fault. Always remember, never name a file you’re working on the same name as a lib you’re trying to require. Bad mojo.
Anyway, gem install ncurses.
Here is Hello World in ruby ncurses (ripped off from Koders who ripped it from the library examples):
#!/usr/bin/env ruby
# Small Ncurses Demo
require 'ncurses'
Ncurses.initscr
Ncurses.mvaddstr(4, 19, "Hello, world!");
Ncurses.refresh
sleep(2.5)
Ncurses.endwin
Well, I learned my lesson.
Also, I found that killing the app would put my shell in a crappy mode where I couldn’t see what I was typing (I had to keep fixing with reset). I fixed this by adding these lines where they would get loaded:
trap("INT") do
Ncurses.endwin
exit
end
If you get something like Ncurses not found, make sure you’ve run Ncurses.initscr before the trap.


Yan
August 27, 2006 at 11:28 PM
(4.score + 7.years).ago
Hank
August 27, 2006 at 11:28 PM
I would but ActiveSupport doesn’t support the .score method. I’ll submit a patch though.